Skip to content

Commit

Permalink
Added a check to log a warning if some labels are used in metric defi…
Browse files Browse the repository at this point in the history
…nition
  • Loading branch information
OlivierCazade committed Apr 26, 2024
1 parent 216e3e6 commit 4c1722d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
21 changes: 21 additions & 0 deletions apis/flowmetrics/v1alpha1/flowmetric_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"

"github.com/netobserv/network-observability-operator/controllers/constants"
"github.com/netobserv/network-observability-operator/pkg/helper"

apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -61,6 +62,25 @@ func (r *FlowMetricWebhook) ValidateDelete(_ context.Context, _ runtime.Object)
return nil, nil
}

func labelIsHighCardinality(label string) bool {
for _, hLabel := range constants.MetricHighCardinalityLabels {
if label == hLabel {
return true
}
}
return false
}

func checkFlowMetricCartinality(fMetric *FlowMetric) {
for _, label := range fMetric.Spec.Labels {
if labelIsHighCardinality(label) {
//No warning level logging as info since it is not an error
flowmetriclog.Info("Warning: metric label has high cardinality, please limit it by using some filters", "labelName", label)
return
}
}
}

func validateFlowMetric(_ context.Context, fMetric *FlowMetric) error {
var str []string
var allErrs field.ErrorList
Expand Down Expand Up @@ -95,5 +115,6 @@ func validateFlowMetric(_ context.Context, fMetric *FlowMetric) error {
schema.GroupKind{Group: GroupVersion.Group, Kind: FlowMetric{}.Kind},
fMetric.Name, allErrs)
}
checkFlowMetricCartinality(fMetric)
return nil
}
1 change: 1 addition & 0 deletions controllers/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ var EnvNoHTTP2 = corev1.EnvVar{
Name: "GODEBUG",
Value: "http2server=0",
}
var MetricHighCardinalityLabels = []string{"DstAddr", "DstK8S_Name", "DstMac", "SrcAddr", "SrcK8S_Name", "SrcMac"}

0 comments on commit 4c1722d

Please sign in to comment.