Skip to content

Commit

Permalink
feat(observability-lib): variable add current + includeAll options (#808
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Atrax1 authored Sep 30, 2024
1 parent 5179326 commit d5bb400
Show file tree
Hide file tree
Showing 13 changed files with 195 additions and 344 deletions.
3 changes: 0 additions & 3 deletions observability-lib/cmd/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,18 @@ func BuildDashboardWithType(options *BuildOptions) (*grafana.Dashboard, error) {
case TypeDashboardDONOCR:
return atlasdon.NewDashboard(&atlasdon.Props{
Name: options.Name,
Platform: options.Platform,
MetricsDataSource: options.MetricsDataSource,
OCRVersion: string(OCRVersionOCR),
})
case TypeDashboardDONOCR2:
return atlasdon.NewDashboard(&atlasdon.Props{
Name: options.Name,
Platform: options.Platform,
MetricsDataSource: options.MetricsDataSource,
OCRVersion: string(OCRVersionOCR2),
})
case TypeDashboardDONOCR3:
return atlasdon.NewDashboard(&atlasdon.Props{
Name: options.Name,
Platform: options.Platform,
MetricsDataSource: options.MetricsDataSource,
OCRVersion: string(OCRVersionOCR3),
})
Expand Down
89 changes: 49 additions & 40 deletions observability-lib/dashboards/atlas-don/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ func NewDashboard(props *Props) (*grafana.Dashboard, error) {
return nil, fmt.Errorf("OCRVersion is required")
}

if props.Platform == "" {
return nil, fmt.Errorf("Platform is required")
}

props.PlatformOpts = PlatformPanelOpts(props.Platform, props.OCRVersion)
props.PlatformOpts = PlatformPanelOpts(props.OCRVersion)

builder := grafana.NewBuilder(&grafana.BuilderOptions{
Name: props.Name,
Expand Down Expand Up @@ -55,33 +51,13 @@ func NewDashboard(props *Props) (*grafana.Dashboard, error) {
func vars(p *Props) []cog.Builder[dashboard.VariableModel] {
var variables []cog.Builder[dashboard.VariableModel]

variables = append(variables, grafana.NewQueryVariable(&grafana.QueryVariableOptions{
VariableOption: &grafana.VariableOption{
Label: "Namespace",
Name: "namespace",
},
Datasource: p.MetricsDataSource.Name,
Query: `label_values(namespace)`,
Regex: "otpe[1-3]?$",
}))

variables = append(variables, grafana.NewQueryVariable(&grafana.QueryVariableOptions{
VariableOption: &grafana.VariableOption{
Label: "Job",
Name: "job",
},
Datasource: p.MetricsDataSource.Name,
Query: `label_values(up{namespace="$namespace"}, job)`,
}))

variables = append(variables, grafana.NewQueryVariable(&grafana.QueryVariableOptions{
VariableOption: &grafana.VariableOption{
Label: "Pod",
Name: "pod",
},
Datasource: p.MetricsDataSource.Name,
Query: `label_values(up{namespace="$namespace", job="$job"}, pod)`,
Multi: true,
Query: `label_values(up{namespace` + p.PlatformOpts.LabelFilters["namespace"] + `}, job)`,
}))

variableFeedID := "feed_id"
Expand Down Expand Up @@ -159,7 +135,7 @@ func summary(p *Props) []*grafana.Panel {
Query: []grafana.Query{
{
Expr: `bool:` + p.OCRVersion + `_oracle_telemetry_down_except_telemetry_down{job=~"${job}", oracle!="csa_unknown"} == 1`,
Legend: "{{oracle}} | {{report_type}}",
Legend: "{{oracle}}",
},
},
Threshold: &grafana.ThresholdOptions{
Expand All @@ -170,6 +146,13 @@ func summary(p *Props) []*grafana.Panel {
{Value: grafana.Pointer[float64](0.99), Color: "red"},
},
},
Transform: &grafana.TransformOptions{
ID: "renameByRegex",
Options: map[string]string{
"regex": "/^(.*[\\\\\\/])/",
"renamePattern": "",
},
},
},
TextMode: common.BigValueTextModeName,
Orientation: common.VizOrientationHorizontal,
Expand Down Expand Up @@ -237,7 +220,7 @@ func summary(p *Props) []*grafana.Panel {
Query: []grafana.Query{
{
Expr: `bool:` + p.OCRVersion + `_oracle_blind_except_telemetry_down{job=~"${job}"} == 1`,
Legend: "{{oracle}} | {{report_type}}",
Legend: "{{oracle}}",
},
},
Threshold: &grafana.ThresholdOptions{
Expand All @@ -248,6 +231,13 @@ func summary(p *Props) []*grafana.Panel {
{Value: grafana.Pointer[float64](0.99), Color: "red"},
},
},
Transform: &grafana.TransformOptions{
ID: "renameByRegex",
Options: map[string]string{
"regex": "/^(.*[\\\\\\/])/",
"renamePattern": "",
},
},
},
TextMode: common.BigValueTextModeName,
Orientation: common.VizOrientationHorizontal,
Expand All @@ -263,7 +253,7 @@ func summary(p *Props) []*grafana.Panel {
Query: []grafana.Query{
{
Expr: `bool:` + p.OCRVersion + `_oracle_feed_no_observations_except_oracle_blind_except_feed_reporting_failure_except_feed_telemetry_down{job=~"${job}"} == 1`,
Legend: "{{oracle}} | {{report_type}}",
Legend: "{{oracle}}",
},
},
Threshold: &grafana.ThresholdOptions{
Expand All @@ -274,6 +264,13 @@ func summary(p *Props) []*grafana.Panel {
{Value: grafana.Pointer[float64](0.99), Color: "red"},
},
},
Transform: &grafana.TransformOptions{
ID: "renameByRegex",
Options: map[string]string{
"regex": "/^(.*[\\\\\\/])/",
"renamePattern": "",
},
},
},
TextMode: common.BigValueTextModeName,
Orientation: common.VizOrientationHorizontal,
Expand All @@ -296,7 +293,7 @@ func ocrContractConfigOracle(p *Props) []*grafana.Panel {
Query: []grafana.Query{
{
Expr: `sum(` + p.OCRVersion + `_contract_oracle_active{` + p.PlatformOpts.LabelQuery + `}) by (contract, oracle)`,
Legend: "{{contract}} - {{oracle}}",
Legend: "{{oracle}}",
},
},
Threshold: &grafana.ThresholdOptions{
Expand All @@ -307,6 +304,13 @@ func ocrContractConfigOracle(p *Props) []*grafana.Panel {
{Value: grafana.Pointer[float64](0.99), Color: "green"},
},
},
Transform: &grafana.TransformOptions{
ID: "renameByRegex",
Options: map[string]string{
"regex": "/^(.*[\\\\\\/])/",
"renamePattern": "",
},
},
},
TextMode: common.BigValueTextModeName,
Orientation: common.VizOrientationHorizontal,
Expand Down Expand Up @@ -553,22 +557,27 @@ func priceReporting(p *Props) []*grafana.Panel {
func roundEpochProgression(p *Props) []*grafana.Panel {
var panels []*grafana.Panel

variableFeedID := "feed_id"
if p.OCRVersion == "ocr3" {
var variableFeedID string
switch p.OCRVersion {
case "ocr":
variableFeedID = "contract"
case "ocr2":
variableFeedID = "feed_id"
case "ocr3":
variableFeedID = "feed_id_name"
}

panels = append(panels, grafana.NewTimeSeriesPanel(&grafana.TimeSeriesPanelOptions{
PanelOptions: &grafana.PanelOptions{
Datasource: p.MetricsDataSource.Name,
Title: "Agreed Epoch Progression",
Span: 8,
Span: 12,
Height: 6,
Decimals: 1,
Unit: "short",
Query: []grafana.Query{
{
Expr: `` + p.OCRVersion + `_telemetry_feed_agreed_epoch{` + variableFeedID + `=~"${` + variableFeedID + `}"}`,
Expr: `` + p.OCRVersion + `_telemetry_feed_agreed_epoch{` + p.PlatformOpts.LabelQuery + `}`,
Legend: `{{` + variableFeedID + `}}`,
},
},
Expand All @@ -579,13 +588,13 @@ func roundEpochProgression(p *Props) []*grafana.Panel {
PanelOptions: &grafana.PanelOptions{
Datasource: p.MetricsDataSource.Name,
Title: "Round Epoch Progression",
Span: 8,
Span: 12,
Height: 6,
Decimals: 1,
Unit: "short",
Query: []grafana.Query{
{
Expr: `` + p.OCRVersion + `_telemetry_epoch_round{` + variableFeedID + `=~"${` + variableFeedID + `}"}`,
Expr: `` + p.OCRVersion + `_telemetry_epoch_round{` + p.PlatformOpts.LabelQuery + `}`,
Legend: `{{oracle}}`,
},
},
Expand All @@ -597,13 +606,13 @@ func roundEpochProgression(p *Props) []*grafana.Panel {
Datasource: p.MetricsDataSource.Name,
Title: "Rounds Started",
Description: `Tracks individual nodes firing "new round" message via telemetry (not part of P2P messages)`,
Span: 8,
Span: 12,
Height: 6,
Decimals: 1,
Unit: "short",
Query: []grafana.Query{
{
Expr: `rate(` + p.OCRVersion + `_telemetry_round_started_total{` + variableFeedID + `=~"${` + variableFeedID + `}"}[1m])`,
Expr: `rate(` + p.OCRVersion + `_telemetry_round_started_total{` + p.PlatformOpts.LabelQuery + `}[1m])`,
Legend: `{{oracle}}`,
},
},
Expand All @@ -614,13 +623,13 @@ func roundEpochProgression(p *Props) []*grafana.Panel {
PanelOptions: &grafana.PanelOptions{
Datasource: p.MetricsDataSource.Name,
Title: "Telemetry Ingested",
Span: 8,
Span: 12,
Height: 6,
Decimals: 1,
Unit: "short",
Query: []grafana.Query{
{
Expr: `rate(` + p.OCRVersion + `_telemetry_ingested_total{` + variableFeedID + `=~"${` + variableFeedID + `}"}[1m])`,
Expr: `rate(` + p.OCRVersion + `_telemetry_ingested_total{` + p.PlatformOpts.LabelQuery + `}[1m])`,
Legend: `{{oracle}}`,
},
},
Expand Down
1 change: 0 additions & 1 deletion observability-lib/dashboards/atlas-don/component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ func TestNewDashboard(t *testing.T) {
t.Run("NewDashboard creates a dashboard", func(t *testing.T) {
testDashboard, err := atlasdon.NewDashboard(&atlasdon.Props{
Name: "DON OCR Dashboard",
Platform: grafana.TypePlatformDocker,
MetricsDataSource: grafana.NewDataSource("Prometheus", ""),
OCRVersion: "ocr2",
})
Expand Down
31 changes: 12 additions & 19 deletions observability-lib/dashboards/atlas-don/platform.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package atlasdon

import (
"fmt"

"github.com/smartcontractkit/chainlink-common/observability-lib/grafana"
)

type PlatformOpts struct {
Platform grafana.TypePlatform
LabelFilters map[string]string
LabelFilter string
LegendString string
Expand All @@ -16,19 +13,17 @@ type PlatformOpts struct {

type Props struct {
Name string
Platform grafana.TypePlatform
MetricsDataSource *grafana.DataSource
PlatformOpts PlatformOpts
OCRVersion string
}

// PlatformPanelOpts generate different queries depending on params
func PlatformPanelOpts(platform grafana.TypePlatform, ocrVersion string) PlatformOpts {
func PlatformPanelOpts(ocrVersion string) PlatformOpts {
po := PlatformOpts{
LabelFilters: map[string]string{
"contract": `=~"${contract}"`,
},
Platform: platform,
}

variableFeedID := "feed_id"
Expand All @@ -42,20 +37,18 @@ func PlatformPanelOpts(platform grafana.TypePlatform, ocrVersion string) Platfor
case "ocr3":
po.LabelFilters[variableFeedID] = `=~"${` + variableFeedID + `}"`
}
switch platform {
case grafana.TypePlatformKubernetes:
po.LabelFilters["namespace"] = `=~"${namespace}"`
po.LabelFilters["job"] = `=~"${job}"`
po.LabelFilters["pod"] = `=~"${pod}"`
po.LabelFilter = "job"
po.LegendString = "pod"
case grafana.TypePlatformDocker:
po.LabelFilters["instance"] = `=~"${instance}"`
po.LabelFilter = "instance"
po.LegendString = "instance"
default:
panic(fmt.Sprintf("failed to generate Platform dependent queries, unknown platform: %s", platform))
namespace := "otpe"
if ocrVersion == "ocr2" {
namespace = "otpe2"
} else if ocrVersion == "ocr3" {
namespace = "otpe3"
}

po.LabelFilters["namespace"] = `="` + namespace + `"`
po.LabelFilters["job"] = `=~"${job}"`
po.LabelFilter = "job"
po.LegendString = "job"

for key, value := range po.LabelFilters {
po.LabelQuery += key + value + ", "
}
Expand Down
Loading

0 comments on commit d5bb400

Please sign in to comment.