Skip to content

Commit

Permalink
drop node metrics if node input is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
shorim committed Sep 17, 2024
1 parent bc68a9d commit f79985f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 13 deletions.
1 change: 1 addition & 0 deletions internal/otelcollector/config/metric/gateway/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ type Processors struct {
DropIfInputSourceOtlp *FilterProcessor `yaml:"filter/drop-if-input-source-otlp,omitempty"`
DropRuntimePodMetrics *FilterProcessor `yaml:"filter/drop-runtime-pod-metrics,omitempty"`
DropRuntimeContainerMetrics *FilterProcessor `yaml:"filter/drop-runtime-container-metrics,omitempty"`
DropRuntimeNodeMetrics *FilterProcessor `yaml:"filter/drop-runtime-node-metrics,omitempty"`
DropK8sClusterMetrics *FilterProcessor `yaml:"filter/drop-k8s-cluster-metrics,omitempty"`
ResolveServiceName *metric.TransformProcessor `yaml:"transform/resolve-service-name,omitempty"`
SetInstrumentationScopeKyma *metric.TransformProcessor `yaml:"transform/set-instrumentation-scope-kyma,omitempty"`
Expand Down
12 changes: 12 additions & 0 deletions internal/otelcollector/config/metric/gateway/config_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ func declareRuntimeResourcesFilters(pipeline *telemetryv1alpha1.MetricPipeline,
if isRuntimeInputEnabled(input) && !isRuntimeContainerMetricsEnabled(input) {
cfg.Processors.DropRuntimeContainerMetrics = makeDropRuntimeContainerMetricsConfig()
}
if isRuntimeInputEnabled(input) && !isRuntimeNodeMetricsEnabled(input) {
cfg.Processors.DropRuntimeNodeMetrics = makeDropRuntimeNodeMetricsConfig()
}

if isRuntimeInputEnabled(input) {
cfg.Processors.DropK8sClusterMetrics = makeK8sClusterDropMetrics()
Expand Down Expand Up @@ -272,6 +275,15 @@ func isRuntimeContainerMetricsEnabled(input telemetryv1alpha1.MetricPipelineInpu
return !isRuntimeContainerMetricsDisabled
}

func isRuntimeNodeMetricsEnabled(input telemetryv1alpha1.MetricPipelineInput) bool {
// Runtime node metrics are disabled by default
// If any of the fields (Resources, Node or Enabled) is nil, the node metrics will be disabled
return input.Runtime.Resources != nil &&
input.Runtime.Resources.Node != nil &&
input.Runtime.Resources.Node.Enabled != nil &&
*input.Runtime.Resources.Node.Enabled
}

func isKymaInputEnabled(annotations map[string]string, kymaInputAllowed bool) bool {
return kymaInputAllowed && annotations[KymaInputAnnotation] == "true"
}
36 changes: 23 additions & 13 deletions internal/otelcollector/config/metric/gateway/processors.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,30 +98,40 @@ func makeDropIfInputSourceOtlpConfig() *FilterProcessor {
}

func makeDropRuntimePodMetricsConfig() *FilterProcessor {
dropMetricRules := []string{
ottlexpr.JoinWithAnd(
inputSourceEquals(metric.InputSourceRuntime),
ottlexpr.IsMatch("name", "^k8s.pod.*"),
),
}
return &FilterProcessor{
Metrics: FilterProcessorMetrics{
Metric: dropMetricRules,
Metric: []string{
ottlexpr.JoinWithAnd(
inputSourceEquals(metric.InputSourceRuntime),
ottlexpr.IsMatch("name", "^k8s.pod.*"),
),
},
},
}
}

func makeDropRuntimeContainerMetricsConfig() *FilterProcessor {
dropMetricRules := []string{
ottlexpr.JoinWithAnd(
inputSourceEquals(metric.InputSourceRuntime),
ottlexpr.IsMatch("name", "(^k8s.container.*)|(^container.*)"),
),
return &FilterProcessor{
Metrics: FilterProcessorMetrics{
Metric: []string{
ottlexpr.JoinWithAnd(
inputSourceEquals(metric.InputSourceRuntime),
ottlexpr.IsMatch("name", "(^k8s.container.*)|(^container.*)"),
),
},
},
}
}

func makeDropRuntimeNodeMetricsConfig() *FilterProcessor {
return &FilterProcessor{
Metrics: FilterProcessorMetrics{
Metric: dropMetricRules,
Metric: []string{
ottlexpr.JoinWithAnd(
inputSourceEquals(metric.InputSourceRuntime),
ottlexpr.IsMatch("name", "^k8s.node.*"),
),
},
},
}
}
Expand Down
3 changes: 3 additions & 0 deletions internal/otelcollector/config/metric/gateway/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ func makeRuntimeResourcesFiltersIDs(input telemetryv1alpha1.MetricPipelineInput)
if isRuntimeInputEnabled(input) && !isRuntimeContainerMetricsEnabled(input) {
processors = append(processors, "filter/drop-runtime-container-metrics")
}
if isRuntimeInputEnabled(input) && !isRuntimeNodeMetricsEnabled(input) {
processors = append(processors, "filter/drop-runtime-node-metrics")
}
if isRuntimeInputEnabled(input) {
processors = append(processors, "filter/drop-k8s-cluster-metrics")
}
Expand Down

0 comments on commit f79985f

Please sign in to comment.