Skip to content

Commit

Permalink
chore(metrics): route based on job attributes
Browse files Browse the repository at this point in the history
We can do this after having consolidated our remote writes.
  • Loading branch information
swiatekm committed Sep 22, 2023
1 parent b65f03e commit f4679bd
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 182 deletions.
1 change: 0 additions & 1 deletion deploy/helm/sumologic/conf/metrics/otelcol/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ receivers:
write_timeout = "30s"
service_address = ":9888"
data_format = "prometheusremotewrite"
path_tag = true
paths = [
{{ include "metric.endpoints" . | indent 10 }}
]
Expand Down
3 changes: 0 additions & 3 deletions deploy/helm/sumologic/conf/metrics/otelcol/pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ processors:
{{- end }}
- batch
{{- if eq .Values.sumologic.metrics.sourceType "http" }}
- transform/prepare_routing
- routing
{{- else }}
- transform/drop_routing_attribute
{{- end }}
receivers:
- telegraf
Expand Down
56 changes: 9 additions & 47 deletions deploy/helm/sumologic/conf/metrics/otelcol/processors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -132,57 +132,42 @@ resource/remove_k8s_pod_pod_name:
key: k8s.pod.pod_name

{{- if eq .Values.sumologic.metrics.sourceType "http" }}
## NOTE: below listed rules could be simplified if routingprocessor
## supports regex matching. At this point we could group route entries
## going to the same set of exporters.
routing:
attribute_source: resource
default_exporters:
- sumologic/default
drop_resource_routing_attribute: true
from_attribute: http_listener_v2_path
error_mode: ignore
table:
## apiserver metrics
- exporters:
- sumologic/apiserver
value: /prometheus.metrics.apiserver
statement: route() where resource.attributes["job"] == "apiserver"
## control-plane metrics
- exporters:
- sumologic/control_plane
value: /prometheus.metrics.control-plane.coredns
statement: route() where resource.attributes["job"] == "coredns"
- exporters:
- sumologic/control_plane
value: /prometheus.metrics.control-plane.kube-etcd
statement: route() where resource.attributes["job"] == "kube-etcd"
## controller metrics
- exporters:
- sumologic/controller
value: /prometheus.metrics.controller-manager
statement: route() where resource.attributes["job"] == "kube-controller-manager"
## kubelet metrics
- exporters:
- sumologic/kubelet
value: /prometheus.metrics.kubelet
statement: route() where resource.attributes["job"] == "kubelet"
## node metrics
- exporters:
- sumologic/node
value: /prometheus.metrics.node
statement: route() where resource.attributes["job"] == "node-exporter"
## scheduler metrics
- exporters:
- sumologic/scheduler
value: /prometheus.metrics.scheduler
statement: route() where resource.attributes["job"] == "kube-scheduler"
## state metrics
- exporters:
- sumologic/state
value: /prometheus.metrics.state
## custom metrics
## These entries are necessary due to a bug in routing processor that prevents the routing key from being deleted
## if the default exporter is chosen
## See: https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/24644
- exporters:
- sumologic/default
value: /prometheus.metrics.applications.custom
- exporters:
- sumologic/default
value: /prometheus.metrics
statement: route() where resource.attributes["job"] == "kube-state-metrics"
{{- end }}

## Configuration for Source Processor
Expand All @@ -197,29 +182,6 @@ source:
sumologic_schema:
add_cloud_namespace: false

{{- if eq .Values.sumologic.metrics.sourceType "http" }}
transform/prepare_routing:
error_mode: ignore
metric_statements:
- context: metric
statements:
- set(resource.attributes["http_listener_v2_path"], "/prometheus.metrics.apiserver") where resource.attributes["job"] == "apiserver"
- set(resource.attributes["http_listener_v2_path"], "/prometheus.metrics.control-plane.coredns") where resource.attributes["job"] == "coredns"
- set(resource.attributes["http_listener_v2_path"], "/prometheus.metrics.control-plane.kube-etcd") where resource.attributes["job"] == "kube-etcd"
- set(resource.attributes["http_listener_v2_path"], "/prometheus.metrics.controller-manager") where resource.attributes["job"] == "kubelet" and IsMatch(name, "^cloudprovider_.*")
- set(resource.attributes["http_listener_v2_path"], "/prometheus.metrics.kubelet") where resource.attributes["job"] == "kubelet" and not IsMatch(name, "^cloudprovider_.*")
- set(resource.attributes["http_listener_v2_path"], "/prometheus.metrics.node") where resource.attributes["job"] == "node-exporter"
- set(resource.attributes["http_listener_v2_path"], "/prometheus.metrics.scheduler") where resource.attributes["job"] == "kube-scheduler"
- set(resource.attributes["http_listener_v2_path"], "/prometheus.metrics.state") where resource.attributes["job"] == "kube-state-metrics"
{{ else }}
transform/drop_routing_attribute:
error_mode: ignore
metric_statements:
- context: resource
statements:
- delete_key(attributes, "http_listener_v2_path")
{{- end }}

transform/remove_name:
error_mode: ignore
metric_statements:
Expand Down
3 changes: 0 additions & 3 deletions tests/helm/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ func TestMetadataMetricsOtelConfigExtraProcessors(t *testing.T) {
"transform/remove_name",
"filter/drop_unnecessary_metrics",
"batch",
"transform/prepare_routing",
"routing",
}

Expand Down Expand Up @@ -182,10 +181,8 @@ sumologic:
assert.Len(t, otelConfig.Exporters.Rest, 0)
assert.NotContains(t, otelConfig.Processors, "routing")
assert.NotContains(t, otelConfig.Processors, "transform/prepare_routing")
assert.Contains(t, otelConfig.Processors, "transform/drop_routing_attribute")
assert.NotContains(t, otelConfig.Service.Pipelines.Metrics.Processors, "routing")
assert.NotContains(t, otelConfig.Service.Pipelines.Metrics.Processors, "transform/prepare_routing")
assert.Contains(t, otelConfig.Service.Pipelines.Metrics.Processors, "transform/drop_routing_attribute")
assert.Equal(t, otelConfig.Service.Pipelines.Metrics.Exporters, []string{"sumologic/default"})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,69 +202,40 @@ data:
- action: delete
key: k8s.pod.pod_name
routing:
attribute_source: resource
default_exporters:
- sumologic/default
drop_resource_routing_attribute: true
from_attribute: http_listener_v2_path
error_mode: ignore
table:
- exporters:
- sumologic/apiserver
value: /prometheus.metrics.apiserver
statement: route() where resource.attributes["job"] == "apiserver"
- exporters:
- sumologic/control_plane
value: /prometheus.metrics.control-plane.coredns
statement: route() where resource.attributes["job"] == "coredns"
- exporters:
- sumologic/control_plane
value: /prometheus.metrics.control-plane.kube-etcd
statement: route() where resource.attributes["job"] == "kube-etcd"
- exporters:
- sumologic/controller
value: /prometheus.metrics.controller-manager
statement: route() where resource.attributes["job"] == "kube-controller-manager"
- exporters:
- sumologic/kubelet
value: /prometheus.metrics.kubelet
statement: route() where resource.attributes["job"] == "kubelet"
- exporters:
- sumologic/node
value: /prometheus.metrics.node
statement: route() where resource.attributes["job"] == "node-exporter"
- exporters:
- sumologic/scheduler
value: /prometheus.metrics.scheduler
statement: route() where resource.attributes["job"] == "kube-scheduler"
- exporters:
- sumologic/state
value: /prometheus.metrics.state
- exporters:
- sumologic/default
value: /prometheus.metrics.applications.custom
- exporters:
- sumologic/default
value: /prometheus.metrics
statement: route() where resource.attributes["job"] == "kube-state-metrics"
source:
collector: kubernetes
exclude:
k8s.namespace.name: ""
sumologic_schema:
add_cloud_namespace: false
transform/prepare_routing:
error_mode: ignore
metric_statements:
- context: metric
statements:
- set(resource.attributes["http_listener_v2_path"], "/prometheus.metrics.apiserver")
where resource.attributes["job"] == "apiserver"
- set(resource.attributes["http_listener_v2_path"], "/prometheus.metrics.control-plane.coredns")
where resource.attributes["job"] == "coredns"
- set(resource.attributes["http_listener_v2_path"], "/prometheus.metrics.control-plane.kube-etcd")
where resource.attributes["job"] == "kube-etcd"
- set(resource.attributes["http_listener_v2_path"], "/prometheus.metrics.controller-manager")
where resource.attributes["job"] == "kubelet" and IsMatch(name, "^cloudprovider_.*")
- set(resource.attributes["http_listener_v2_path"], "/prometheus.metrics.kubelet")
where resource.attributes["job"] == "kubelet" and not IsMatch(name, "^cloudprovider_.*")
- set(resource.attributes["http_listener_v2_path"], "/prometheus.metrics.node")
where resource.attributes["job"] == "node-exporter"
- set(resource.attributes["http_listener_v2_path"], "/prometheus.metrics.scheduler")
where resource.attributes["job"] == "kube-scheduler"
- set(resource.attributes["http_listener_v2_path"], "/prometheus.metrics.state")
where resource.attributes["job"] == "kube-state-metrics"
transform/remove_name:
error_mode: ignore
metric_statements:
Expand Down Expand Up @@ -294,7 +265,6 @@ data:
write_timeout = "30s"
service_address = ":9888"
data_format = "prometheusremotewrite"
path_tag = true
paths = [
"/prometheus.metrics",
"/prometheus.metrics.custom",
Expand Down Expand Up @@ -331,7 +301,6 @@ data:
- transform/remove_name
- filter/drop_unnecessary_metrics
- batch
- transform/prepare_routing
- routing
receivers:
- telegraf
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,69 +202,40 @@ data:
- action: delete
key: k8s.pod.pod_name
routing:
attribute_source: resource
default_exporters:
- sumologic/default
drop_resource_routing_attribute: true
from_attribute: http_listener_v2_path
error_mode: ignore
table:
- exporters:
- sumologic/apiserver
value: /prometheus.metrics.apiserver
statement: route() where resource.attributes["job"] == "apiserver"
- exporters:
- sumologic/control_plane
value: /prometheus.metrics.control-plane.coredns
statement: route() where resource.attributes["job"] == "coredns"
- exporters:
- sumologic/control_plane
value: /prometheus.metrics.control-plane.kube-etcd
statement: route() where resource.attributes["job"] == "kube-etcd"
- exporters:
- sumologic/controller
value: /prometheus.metrics.controller-manager
statement: route() where resource.attributes["job"] == "kube-controller-manager"
- exporters:
- sumologic/kubelet
value: /prometheus.metrics.kubelet
statement: route() where resource.attributes["job"] == "kubelet"
- exporters:
- sumologic/node
value: /prometheus.metrics.node
statement: route() where resource.attributes["job"] == "node-exporter"
- exporters:
- sumologic/scheduler
value: /prometheus.metrics.scheduler
statement: route() where resource.attributes["job"] == "kube-scheduler"
- exporters:
- sumologic/state
value: /prometheus.metrics.state
- exporters:
- sumologic/default
value: /prometheus.metrics.applications.custom
- exporters:
- sumologic/default
value: /prometheus.metrics
statement: route() where resource.attributes["job"] == "kube-state-metrics"
source:
collector: kubernetes
exclude:
k8s.namespace.name: ""
sumologic_schema:
add_cloud_namespace: false
transform/prepare_routing:
error_mode: ignore
metric_statements:
- context: metric
statements:
- set(resource.attributes["http_listener_v2_path"], "/prometheus.metrics.apiserver")
where resource.attributes["job"] == "apiserver"
- set(resource.attributes["http_listener_v2_path"], "/prometheus.metrics.control-plane.coredns")
where resource.attributes["job"] == "coredns"
- set(resource.attributes["http_listener_v2_path"], "/prometheus.metrics.control-plane.kube-etcd")
where resource.attributes["job"] == "kube-etcd"
- set(resource.attributes["http_listener_v2_path"], "/prometheus.metrics.controller-manager")
where resource.attributes["job"] == "kubelet" and IsMatch(name, "^cloudprovider_.*")
- set(resource.attributes["http_listener_v2_path"], "/prometheus.metrics.kubelet")
where resource.attributes["job"] == "kubelet" and not IsMatch(name, "^cloudprovider_.*")
- set(resource.attributes["http_listener_v2_path"], "/prometheus.metrics.node")
where resource.attributes["job"] == "node-exporter"
- set(resource.attributes["http_listener_v2_path"], "/prometheus.metrics.scheduler")
where resource.attributes["job"] == "kube-scheduler"
- set(resource.attributes["http_listener_v2_path"], "/prometheus.metrics.state")
where resource.attributes["job"] == "kube-state-metrics"
transform/remove_name:
error_mode: ignore
metric_statements:
Expand Down Expand Up @@ -294,7 +265,6 @@ data:
write_timeout = "30s"
service_address = ":9888"
data_format = "prometheusremotewrite"
path_tag = true
paths = [
"/prometheus.metrics"
]
Expand Down Expand Up @@ -329,7 +299,6 @@ data:
- transform/remove_name
- filter/drop_unnecessary_metrics
- batch
- transform/prepare_routing
- routing
receivers:
- telegraf
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,6 @@ data:
k8s.namespace.name: ""
sumologic_schema:
add_cloud_namespace: false
transform/drop_routing_attribute:
error_mode: ignore
metric_statements:
- context: resource
statements:
- delete_key(attributes, "http_listener_v2_path")
transform/remove_name:
error_mode: ignore
metric_statements:
Expand Down Expand Up @@ -172,7 +166,6 @@ data:
write_timeout = "30s"
service_address = ":9888"
data_format = "prometheusremotewrite"
path_tag = true
paths = [
"/prometheus.metrics"
]
Expand Down Expand Up @@ -200,7 +193,6 @@ data:
- transform/remove_name
- filter/drop_unnecessary_metrics
- batch
- transform/drop_routing_attribute
receivers:
- telegraf
- otlp
Expand Down
Loading

0 comments on commit f4679bd

Please sign in to comment.