Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jotak committed Feb 27, 2024
1 parent 67d785a commit 1ed73df
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 90 deletions.
18 changes: 3 additions & 15 deletions controllers/monitoring/monitoring_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,7 @@ func ControllerSpecs() {
return err
}
return d.Titles()
}, timeout, interval).Should(Equal([]string{
"Flows",
"Flows Overhead",
"Top flow rates per source and destination namespaces",
"Agents",
"Processor",
"Operator",
}))
}, timeout, interval).Should(Equal([]string{"", "Flowlogs-pipeline statistics", "eBPF agent statistics", "Operator statistics", "Resource usage"}))
})

It("Should update successfully", func() {
Expand All @@ -117,7 +110,7 @@ func ControllerSpecs() {
}, &v1.ConfigMap{})
}, timeout, interval).Should(MatchError(`configmaps "grafana-dashboard-netobserv-flow-metrics" not found`))

By("Expecting the health dashboards rows to be filtered")
By("Expecting the health dashboard to remain")
Eventually(func() interface{} {
cm := v1.ConfigMap{}
if err := k8sClient.Get(ctx, types.NamespacedName{
Expand All @@ -131,12 +124,7 @@ func ControllerSpecs() {
return err
}
return d.Titles()
}, timeout, interval).Should(Equal([]string{
"Flows",
"Agents",
"Processor",
"Operator",
}))
}, timeout, interval).Should(Equal([]string{"", "Flowlogs-pipeline statistics", "eBPF agent statistics", "Operator statistics", "Resource usage"}))
})
})

Expand Down
56 changes: 31 additions & 25 deletions pkg/dashboards/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ func init() {
scope.titlePart,
)
metric := fmt.Sprintf("%s_%s_%s_total", scope.metricPart, dir, valueType)
allRows = append(allRows, &Row{
Metric: metric,
Title: title,
Panels: topRatePanels(&scope, metric, scope.joinLabels(), scope.legendPart),
})
allRows = append(allRows, row(
metric,
title,
topRatePanels(&scope, metric, scope.joinLabels(), scope.legendPart),
))
}
// drops
title := fmt.Sprintf(
Expand All @@ -48,41 +48,47 @@ func init() {
scope.titlePart,
)
metric := fmt.Sprintf("%s_drop_%s_total", scope.metricPart, valueType)
allRows = append(allRows, &Row{
Metric: metric,
Title: title,
Panels: topRatePanels(&scope, metric, scope.joinLabels(), scope.legendPart),
})
allRows = append(allRows, row(
metric,
title,
topRatePanels(&scope, metric, scope.joinLabels(), scope.legendPart),
))
}
// RTT
title := fmt.Sprintf("Round-trip time %s (milliseconds - p99 and p50)", scope.titlePart)
metric := fmt.Sprintf("%s_rtt_seconds", scope.metricPart)
allRows = append(allRows, &Row{
Metric: metric,
Title: title,
Panels: histogramPanels(&scope, metric, scope.joinLabels(), scope.legendPart, "*1000"),
})
allRows = append(allRows, row(
metric,
title,
histogramPanels(&scope, metric, scope.joinLabels(), scope.legendPart, "*1000"),
))
// DNS latency
title = fmt.Sprintf("DNS latency %s (milliseconds - p99 and p50)", scope.titlePart)
metric = fmt.Sprintf("%s_dns_latency_seconds", scope.metricPart)
allRows = append(allRows, &Row{
Metric: metric,
Title: title,
Panels: histogramPanels(&scope, metric, scope.joinLabels(), scope.legendPart, "*1000"),
})
allRows = append(allRows, row(
metric,
title,
histogramPanels(&scope, metric, scope.joinLabels(), scope.legendPart, "*1000"),
))
// DNS errors
title = fmt.Sprintf("DNS request rate per code and %s", scope.titlePart)
metric = fmt.Sprintf("%s_dns_latency_seconds", scope.metricPart)
labels := scope.joinLabels() + ",DnsFlagsResponseCode"
legend := scope.legendPart + ", {{DnsFlagsResponseCode}}"
allRows = append(allRows, &Row{
Metric: metric,
Title: title,
Panels: topRatePanels(&scope, metric+"_count", labels, legend),
})
allRows = append(allRows, row(
metric,
title,
topRatePanels(&scope, metric+"_count", labels, legend),
))
}
}

func row(metrics string, title string, panels []Panel) *Row {
r := NewRow(title, false, "250px", panels)
r.Metric = metrics
return r
}

func topRatePanels(scope *metricScope, metric, labels, legend string) []Panel {
if scope.splitAppInfra {
return []Panel{
Expand Down
41 changes: 4 additions & 37 deletions pkg/dashboards/dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,45 +150,12 @@ func TestCreateHealthDashboard_Default(t *testing.T) {
assert.NoError(err)

assert.Equal("NetObserv / Health", d.Title)
assert.Equal([]string{
"Flows",
"Flows Overhead",
"Top flow rates per source and destination namespaces",
"Agents",
"Processor",
"Operator",
}, d.Titles())
assert.Equal([]string{"", "Flowlogs-pipeline statistics", "eBPF agent statistics", "Operator statistics", "Resource usage"}, d.Titles())

// First row
row := 0
assert.Len(d.Rows[row].Panels, 1)
assert.Equal("Rates", d.Rows[row].Panels[0].Title)
assert.Len(d.Rows[row].Panels[0].Targets, 3)
assert.Contains(d.Rows[row].Panels[0].Targets[0].Expr, "netobserv_ingest_flows_processed")

// 3rd row
row = 2
assert.Len(d.Rows[row].Panels, 2)
assert.Equal("Applications", d.Rows[row].Panels[0].Title)
assert.Equal("Infrastructure", d.Rows[row].Panels[1].Title)
assert.Len(d.Rows[row].Panels, 4)
assert.Equal("Flows per second", d.Rows[row].Panels[0].Title)
assert.Len(d.Rows[row].Panels[0].Targets, 1)
assert.Contains(d.Rows[row].Panels[0].Targets[0].Expr, "netobserv_namespace_flows_total")
}

func TestCreateHealthDashboard_NoFlowMetric(t *testing.T) {
assert := assert.New(t)

js, err := CreateHealthDashboard("netobserv", []string{})
assert.NoError(err)

d, err := FromBytes([]byte(js))
assert.NoError(err)

assert.Equal("NetObserv / Health", d.Title)
assert.Equal([]string{
"Flows",
"Agents",
"Processor",
"Operator",
}, d.Titles())
assert.Contains(d.Rows[row].Panels[0].Targets[0].Expr, "netobserv_agent_evicted_flows_total")
}
16 changes: 7 additions & 9 deletions pkg/dashboards/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ func CreateHealthDashboard(netobsNs string, _ []string) (string, error) {
d := Dashboard{Title: "NetObserv / Health"}

// Global stats
d.Rows = append(d.Rows, NewRow("", false, 100, []Panel{
d.Rows = append(d.Rows, NewRow("", false, "100px", []Panel{
NewSingleStatPanel("Flows per second", PanelUnitShort, 3, NewTarget(
"sum(rate(netobserv_agent_evicted_flows_total[1m]))", "")),
NewSingleStatPanel("Total traffic captured", PanelUnitShort, 3, NewTarget(
"sum(rate(netobserv_agent_evicted_flows_total[1m]))", "")),
NewSingleStatPanel("Sampling", PanelUnitShort, 3, NewTarget(
"avg(netobserv_agent_sampling_rate)", "")),
NewSingleStatPanel("Errors last minute", PanelUnitShort, 3, NewTarget(
Expand All @@ -24,7 +22,7 @@ func CreateHealthDashboard(netobsNs string, _ []string) (string, error) {

// FLP stats
// TODO: FLP error
flpStats := NewRow("Flowlogs-pipeline statistics", false, 250, []Panel{
flpStats := NewRow("Flowlogs-pipeline statistics", false, "250px", []Panel{
NewGraphPanel("Flows per second", PanelUnitShort, 6, false, []Target{
NewTarget("sum(rate(netobserv_ingest_flows_processed[1m]))", "Flows ingested"),
NewTarget("sum(rate(netobserv_loki_sent_entries_total[1m]))", "Flows sent to Loki"),
Expand Down Expand Up @@ -54,7 +52,7 @@ func CreateHealthDashboard(netobsNs string, _ []string) (string, error) {
d.Rows = append(d.Rows, flpStats)

// Agent stats
d.Rows = append(d.Rows, NewRow("eBPF agent statistics", false, 250, []Panel{
d.Rows = append(d.Rows, NewRow("eBPF agent statistics", false, "250px", []Panel{
NewGraphPanel("Eviction rate", PanelUnitShort, 6, true, []Target{
NewTarget("sum(rate(netobserv_agent_evictions_total[1m])) by (source, reason)", "{{source}} {{reason}}"),
}),
Expand All @@ -70,7 +68,7 @@ func CreateHealthDashboard(netobsNs string, _ []string) (string, error) {
}))

// Operator stats
d.Rows = append(d.Rows, NewRow("Operator statistics", true, 250, []Panel{
d.Rows = append(d.Rows, NewRow("Operator statistics", true, "250px", []Panel{
NewGraphPanel("Reconcile events per minute", PanelUnitShort, 6, true, []Target{
NewTarget(`sum(increase(controller_runtime_reconcile_total{job="netobserv-metrics-service"}[1m])) by (controller,result)`, "{{controller}}: {{result}}"),
}),
Expand All @@ -81,16 +79,16 @@ func CreateHealthDashboard(netobsNs string, _ []string) (string, error) {
}))

// CPU and memory
d.Rows = append(d.Rows, NewRow("Resource usage", true, 250, []Panel{
d.Rows = append(d.Rows, NewRow("Resource usage", true, "250px", []Panel{
NewGraphPanel("Overall CPU", PanelUnitShort, 6, true, []Target{
NewTarget(`sum(node_namespace_pod_container:container_cpu_usage_seconds_total:sum_irate{container="netobserv-ebpf-agent"})`, "eBPF agent"),
NewTarget(`sum(node_namespace_pod_container:container_cpu_usage_seconds_total:sum_irate{container="flowlogs-pipeline"})`, "flowlogs-pipeline"),
NewTarget(`sum(node_namespace_pod_container:container_cpu_usage_seconds_total:sum_irate{container!="",pod=~"netobserv-controller-manager.*"})`, "operator"),
}),
NewGraphPanel("Overall memory", PanelUnitShort, 6, true, []Target{
NewTarget(`sum(container_memory_rss{container="netobserv-ebpf-agent"})`, "eBPF agent"),
NewTarget(`sum(container_memory_rss{container="flowlogs-pipeline"})`, "Flowlogs-pipeline"),
NewTarget(`sum(container_memory_rss{container!="",pod=~"netobserv-controller-manager.*"})`, "Operator"),
NewTarget(`sum(container_memory_rss{container="flowlogs-pipeline"})`, "flowlogs-pipeline"),
NewTarget(`sum(container_memory_rss{container!="",pod=~"netobserv-controller-manager.*"})`, "operator"),
}),
NewGraphPanel("eBPF agent CPU - top 10 pods", PanelUnitShort, 6, true, []Target{
NewTarget(`topk(10, node_namespace_pod_container:container_cpu_usage_seconds_total:sum_irate{container="netobserv-ebpf-agent"})`, "{{pod}}"),
Expand Down
8 changes: 4 additions & 4 deletions pkg/dashboards/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ type Dashboard struct {
type Row struct {
Title string
Collapse bool
Height int
Height string
Metric string // TODO: remove
Panels []Panel
}

func NewRow(title string, collaspe bool, height int, panels []Panel) *Row {
func NewRow(title string, collapse bool, height string, panels []Panel) *Row {
return &Row{
Title: title,
Collapse: collaspe,
Collapse: collapse,
Height: height,
Panels: panels,
}
Expand Down Expand Up @@ -194,7 +194,7 @@ func (r *Row) ToGrafanaJSON(netobsNs string) string {
{
"collapse": %t,
"editable": true,
"height": "%dpx",
"height": "%s",
"panels": [%s],
"showTitle": %t,
"title": "%s"
Expand Down

0 comments on commit 1ed73df

Please sign in to comment.