-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NETOBSERV-1284 implement metrics white-listing (#447)
- Introduce CRD field processor.metrics.includeList - Deprecate CRD field processor.metrics.ignoreTags - Convert ignoreTags to includeList approach when includeList isn't set - If includeList isn't set and ignoreTags == default tags in 1.4, default includeList will be used. This should allow a smooth transitioning if more metrics are added in 1.5 - Some code refactoring to move away from embedded metrics defs - this will help to prepare exposing the metrics creation API, and avoid having to define every metric permutation one by one (egress/ingress, bytes/packets, node/ns/workload) - Fixing an issue with the Health dashboard not showing some metrics (previously tagged as "flows") despite they are always present disambiguate package name Fix include inner direction in metrics Rebased / adapt to v1beta2 - In Conversion webhooks, use the per-field dedicated functions to integrate conversion logic - Add tests on conversion webhooks - Automate generation of hack CRD - Modify Health dashboard tagging: just a single tag "dynamic" is sufficient to tell whether we need to check for metric included
- Loading branch information
Showing
45 changed files
with
780 additions
and
752 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
package v1beta1 | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/netobserv/network-observability-operator/api/v1beta2" | ||
"github.com/stretchr/testify/assert" | ||
"k8s.io/utils/ptr" | ||
) | ||
|
||
func TestBeta1ConversionRoundtrip_Loki(t *testing.T) { | ||
// Testing beta1 -> beta2 -> beta1 | ||
assert := assert.New(t) | ||
|
||
initial := FlowCollector{ | ||
Spec: FlowCollectorSpec{ | ||
Loki: FlowCollectorLoki{ | ||
Enable: ptr.To(true), | ||
URL: "http://loki", | ||
StatusURL: "http://loki/status", | ||
QuerierURL: "http://loki/querier", | ||
TenantID: "tenant", | ||
AuthToken: LokiAuthForwardUserToken, | ||
TLS: ClientTLS{ | ||
Enable: true, | ||
InsecureSkipVerify: true, | ||
}, | ||
StatusTLS: ClientTLS{ | ||
Enable: true, | ||
InsecureSkipVerify: true, | ||
}, | ||
BatchSize: 1000, | ||
}, | ||
}, | ||
} | ||
|
||
var converted v1beta2.FlowCollector | ||
err := initial.ConvertTo(&converted) | ||
assert.NoError(err) | ||
|
||
assert.Equal(v1beta2.LokiModeManual, converted.Spec.Loki.Mode) | ||
assert.True(*converted.Spec.Loki.Enable) | ||
assert.Equal("http://loki", converted.Spec.Loki.Manual.IngesterURL) | ||
assert.Equal("http://loki/status", converted.Spec.Loki.Manual.StatusURL) | ||
assert.Equal("http://loki/querier", converted.Spec.Loki.Manual.QuerierURL) | ||
assert.Equal("tenant", converted.Spec.Loki.Manual.TenantID) | ||
assert.Equal(LokiAuthForwardUserToken, converted.Spec.Loki.Manual.AuthToken) | ||
assert.True(converted.Spec.Loki.Manual.TLS.Enable) | ||
assert.True(converted.Spec.Loki.Manual.TLS.InsecureSkipVerify) | ||
assert.True(converted.Spec.Loki.Manual.StatusTLS.Enable) | ||
assert.True(converted.Spec.Loki.Manual.StatusTLS.InsecureSkipVerify) | ||
|
||
// Other way | ||
var back FlowCollector | ||
err = back.ConvertFrom(&converted) | ||
assert.NoError(err) | ||
assert.Equal(initial.Spec.Loki, back.Spec.Loki) | ||
} | ||
|
||
func TestBeta2ConversionRoundtrip_Loki(t *testing.T) { | ||
// Testing beta2 -> beta1 -> beta2 | ||
assert := assert.New(t) | ||
|
||
initial := v1beta2.FlowCollector{ | ||
Spec: v1beta2.FlowCollectorSpec{ | ||
Loki: v1beta2.FlowCollectorLoki{ | ||
Enable: ptr.To(true), | ||
Mode: v1beta2.LokiModeLokiStack, | ||
LokiStack: v1beta2.LokiStackRef{ | ||
Name: "lokiii", | ||
Namespace: "lokins", | ||
}, | ||
BatchSize: 1000, | ||
}, | ||
}, | ||
} | ||
|
||
var converted FlowCollector | ||
err := converted.ConvertFrom(&initial) | ||
assert.NoError(err) | ||
|
||
assert.True(*converted.Spec.Loki.Enable) | ||
assert.Equal("https://lokiii-gateway-http.lokins.svc:8080/api/logs/v1/network/", converted.Spec.Loki.URL) | ||
assert.Equal("https://lokiii-query-frontend-http.lokins.svc:3100/", converted.Spec.Loki.StatusURL) | ||
assert.Equal("https://lokiii-gateway-http.lokins.svc:8080/api/logs/v1/network/", converted.Spec.Loki.QuerierURL) | ||
assert.Equal("network", converted.Spec.Loki.TenantID) | ||
assert.Equal(LokiAuthForwardUserToken, converted.Spec.Loki.AuthToken) | ||
assert.True(converted.Spec.Loki.TLS.Enable) | ||
assert.False(converted.Spec.Loki.TLS.InsecureSkipVerify) | ||
assert.True(converted.Spec.Loki.StatusTLS.Enable) | ||
assert.False(converted.Spec.Loki.StatusTLS.InsecureSkipVerify) | ||
|
||
// Other way | ||
var back v1beta2.FlowCollector | ||
err = converted.ConvertTo(&back) | ||
assert.NoError(err) | ||
assert.Equal(initial.Spec.Loki, back.Spec.Loki) | ||
} | ||
|
||
func TestBeta1ConversionRoundtrip_Metrics(t *testing.T) { | ||
// Testing beta1 -> beta2 -> beta1 | ||
assert := assert.New(t) | ||
|
||
initial := FlowCollector{ | ||
Spec: FlowCollectorSpec{ | ||
Processor: FlowCollectorFLP{ | ||
Metrics: FLPMetrics{ | ||
DisableAlerts: []FLPAlert{AlertLokiError}, | ||
IgnoreTags: []string{"nodes", "workloads", "bytes", "ingress"}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
var converted v1beta2.FlowCollector | ||
err := initial.ConvertTo(&converted) | ||
assert.NoError(err) | ||
|
||
assert.Equal([]v1beta2.FLPAlert{v1beta2.AlertLokiError}, converted.Spec.Processor.Metrics.DisableAlerts) | ||
assert.NotNil(converted.Spec.Processor.Metrics.IncludeList) | ||
assert.Equal([]string{"namespace_egress_packets_total", "namespace_flows_total"}, *converted.Spec.Processor.Metrics.IncludeList) | ||
|
||
// Other way | ||
var back FlowCollector | ||
err = back.ConvertFrom(&converted) | ||
assert.NoError(err) | ||
// Here, includeList is preserved; it takes precedence over ignoreTags | ||
assert.Equal([]string{"namespace_egress_packets_total", "namespace_flows_total"}, *back.Spec.Processor.Metrics.IncludeList) | ||
assert.Equal(initial.Spec.Processor.Metrics.DisableAlerts, back.Spec.Processor.Metrics.DisableAlerts) | ||
assert.Equal(initial.Spec.Processor.Metrics.Server, back.Spec.Processor.Metrics.Server) | ||
} | ||
|
||
func TestBeta2ConversionRoundtrip_Metrics(t *testing.T) { | ||
// Testing beta2 -> beta1 -> beta2 | ||
assert := assert.New(t) | ||
|
||
initial := v1beta2.FlowCollector{ | ||
Spec: v1beta2.FlowCollectorSpec{ | ||
Processor: v1beta2.FlowCollectorFLP{ | ||
Metrics: v1beta2.FLPMetrics{ | ||
DisableAlerts: []v1beta2.FLPAlert{v1beta2.AlertLokiError}, | ||
IncludeList: &[]string{"namespace_egress_packets_total", "namespace_flows_total"}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
var converted FlowCollector | ||
err := converted.ConvertFrom(&initial) | ||
assert.NoError(err) | ||
|
||
assert.Equal([]FLPAlert{AlertLokiError}, converted.Spec.Processor.Metrics.DisableAlerts) | ||
assert.NotNil(converted.Spec.Processor.Metrics.IncludeList) | ||
assert.Equal([]string{"namespace_egress_packets_total", "namespace_flows_total"}, *converted.Spec.Processor.Metrics.IncludeList) | ||
|
||
var back v1beta2.FlowCollector | ||
err = converted.ConvertTo(&back) | ||
assert.NoError(err) | ||
assert.Equal(initial.Spec.Processor.Metrics, back.Spec.Processor.Metrics) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.