Skip to content

Commit

Permalink
feat(metrics): add ability to use OTLP source
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikołaj Świątek authored and swiatekm committed Sep 6, 2023
1 parent 8964ea5 commit fae8c2e
Show file tree
Hide file tree
Showing 31 changed files with 495 additions and 50 deletions.
1 change: 1 addition & 0 deletions .changelog/2949.added.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
feat(metrics): add ability to use OTLP source
1 change: 1 addition & 0 deletions deploy/helm/sumologic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ The following table lists the configurable parameters of the Sumo Logic chart an
| `sumologic.metrics.collector.otelcol.annotatedPods.enabled` | Enable collection of metrics from Pods annotated with prometheus.io/\* keys. See [docs/collecting-application-metrics.md](/docs/collecting-application-metrics.md#application-metrics-are-exposed-one-endpoint-scenario) for more information. | `true` |
| `sumologic.metrics.collector.otelcol.allocationStrategy` | Allocation strategy for the scrape target allocator. Valid values are: least-weighted and consistent-hashing. See: https://github.com/open-telemetry/opentelemetry-operator/blob/main/docs/api.md#opentelemetrycollectorspectargetallocator | `least-weighted` |
| `sumologic.metrics.dropHistogramBuckets` | Drop buckets from select high-cardinality histogram metrics, leaving only the sum and count components. | `true` |
| `sumologic.metrics.sourceType` | The type of the Sumo Logic source being used for metrics ingestion. Can be `http` or `otlp`. | `http` |
| `sumologic.traces.enabled` | Set the enabled flag to true to enable tracing ingestion. _Tracing must be enabled for the account first. Please contact your Sumo representative for activation details_ | `true` |
| `sumologic.traces.spans_per_request` | Maximum number of spans sent in single batch | `100` |
| `sumologic.traces.sourceType` | The type of the Sumo Logic source being used for traces ingestion. Can be `http` for [HTTP Source](https://help.sumologic.com/docs/send-data/hosted-collectors/http-source/traces/) or `otlp` for [OTLP/HTTP Source](https://help.sumologic.com/docs/send-data/hosted-collectors/http-source/otlp/). | `http` |
Expand Down
84 changes: 45 additions & 39 deletions deploy/helm/sumologic/conf/metrics/otelcol/exporters.yaml
Original file line number Diff line number Diff line change
@@ -1,106 +1,112 @@
sumologic/apiserver:
endpoint: ${SUMO_ENDPOINT_APISERVER_METRICS_SOURCE}
max_request_body_size: 16_777_216 # 16 MB before compression
metric_format: prometheus
## Configuration for Sumo Logic Exporter
## ref: https://github.com/SumoLogic/sumologic-otel-collector/blob/main/pkg/exporter/sumologicexporter
sumologic/default:
metric_format: {{ include "metrics.otelcol.exporter.format" . }}
endpoint: {{ include "metrics.otelcol.exporter.endpoint" . }}
## Configuration for sending queue
## ref: https://github.com/open-telemetry/opentelemetry-collector/tree/release/v0.37.x/exporter/exporterhelper#configuration
sending_queue:
enabled: true
num_consumers: 10
queue_size: 10_000
{{- if .Values.metadata.persistence.enabled }}
storage: file_storage
{{- end }}
num_consumers: 10
## setting queue_size a high number, so we always use maximum space of the storage
## minimal alert non-triggering queue size (if only one exporter is being used): 10GB/16MB = 640
queue_size: 10_000
max_request_body_size: 16_777_216 # 16 MB before compression
## set timeout to 30s due to big requests
timeout: 30s
sumologic/control_plane:
endpoint: ${SUMO_ENDPOINT_CONTROL_PLANE_METRICS_SOURCE}
max_request_body_size: 16_777_216 # 16 MB before compression
{{- if eq .Values.sumologic.metrics.sourceType "http" }}
sumologic/apiserver:
metric_format: prometheus
endpoint: ${SUMO_ENDPOINT_APISERVER_METRICS_SOURCE}
sending_queue:
enabled: true
num_consumers: 10
queue_size: 10_000
{{- if .Values.metadata.persistence.enabled }}
storage: file_storage
{{- end }}
num_consumers: 10
queue_size: 10_000
max_request_body_size: 16_777_216 # 16 MB before compression
## set timeout to 30s due to big requests
timeout: 30s
sumologic/controller:
endpoint: ${SUMO_ENDPOINT_CONTROLLER_METRICS_SOURCE}
max_request_body_size: 16_777_216 # 16 MB before compression
sumologic/control_plane:
metric_format: prometheus
endpoint: ${SUMO_ENDPOINT_CONTROL_PLANE_METRICS_SOURCE}
sending_queue:
enabled: true
num_consumers: 10
queue_size: 10_000
{{- if .Values.metadata.persistence.enabled }}
storage: file_storage
{{- end }}
num_consumers: 10
queue_size: 10_000
max_request_body_size: 16_777_216 # 16 MB before compression
## set timeout to 30s due to big requests
timeout: 30s
sumologic/default:
endpoint: ${SUMO_ENDPOINT_DEFAULT_METRICS_SOURCE}
max_request_body_size: 16_777_216 # 16 MB before compression
sumologic/controller:
metric_format: prometheus
endpoint: ${SUMO_ENDPOINT_CONTROLLER_METRICS_SOURCE}
sending_queue:
enabled: true
num_consumers: 10
## setting queue_size a high number, so we always use maximum space of the storage
## minimal alert non-triggering queue size (if only one exporter is being used): 10GB/16MB = 640
queue_size: 10_000
{{- if .Values.metadata.persistence.enabled }}
storage: file_storage
{{- end }}
num_consumers: 10
queue_size: 10_000
max_request_body_size: 16_777_216 # 16 MB before compression
## set timeout to 30s due to big requests
timeout: 30s
sumologic/kubelet:
endpoint: ${SUMO_ENDPOINT_KUBELET_METRICS_SOURCE}
max_request_body_size: 16_777_216 # 16 MB before compression
metric_format: prometheus
endpoint: ${SUMO_ENDPOINT_KUBELET_METRICS_SOURCE}
sending_queue:
enabled: true
num_consumers: 10
queue_size: 10_000
{{- if .Values.metadata.persistence.enabled }}
storage: file_storage
{{- end }}
num_consumers: 10
queue_size: 10_000
max_request_body_size: 16_777_216 # 16 MB before compression
## set timeout to 30s due to big requests
timeout: 30s
sumologic/node:
endpoint: ${SUMO_ENDPOINT_NODE_METRICS_SOURCE}
max_request_body_size: 16_777_216 # 16 MB before compression
metric_format: prometheus
endpoint: ${SUMO_ENDPOINT_NODE_METRICS_SOURCE}
sending_queue:
enabled: true
num_consumers: 10
queue_size: 10_000
{{- if .Values.metadata.persistence.enabled }}
storage: file_storage
{{- end }}
num_consumers: 10
queue_size: 10_000
max_request_body_size: 16_777_216 # 16 MB before compression
## set timeout to 30s due to big requests
timeout: 30s
sumologic/scheduler:
endpoint: ${SUMO_ENDPOINT_SCHEDULER_METRICS_SOURCE}
max_request_body_size: 16_777_216 # 16 MB before compression
metric_format: prometheus
endpoint: ${SUMO_ENDPOINT_SCHEDULER_METRICS_SOURCE}
sending_queue:
enabled: true
num_consumers: 10
queue_size: 10_000
{{- if .Values.metadata.persistence.enabled }}
storage: file_storage
{{- end }}
num_consumers: 10
queue_size: 10_000
max_request_body_size: 16_777_216 # 16 MB before compression
## set timeout to 30s due to big requests
timeout: 30s
sumologic/state:
endpoint: ${SUMO_ENDPOINT_STATE_METRICS_SOURCE}
max_request_body_size: 16_777_216 # 16 MB before compression
metric_format: prometheus
endpoint: ${SUMO_ENDPOINT_STATE_METRICS_SOURCE}
sending_queue:
enabled: true
num_consumers: 10
queue_size: 10_000
{{- if .Values.metadata.persistence.enabled }}
storage: file_storage
{{- end }}
num_consumers: 10
queue_size: 10_000
max_request_body_size: 16_777_216 # 16 MB before compression
## set timeout to 30s due to big requests
timeout: 30s
{{- end }}
6 changes: 6 additions & 0 deletions deploy/helm/sumologic/conf/metrics/otelcol/pipeline.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
exporters:
- sumologic/default
{{- if eq .Values.sumologic.metrics.sourceType "http" }}
- sumologic/apiserver
- sumologic/control_plane
- sumologic/controller
- sumologic/kubelet
- sumologic/node
- sumologic/scheduler
- sumologic/state
{{- end }}
processors:
- memory_limiter
- metricstransform
Expand All @@ -26,8 +28,12 @@ processors:
- groupbyattrs/group_by_name
- transform/remove_name
- batch
{{- if eq .Values.sumologic.metrics.sourceType "http" }}
- transform/prepare_routing
- routing
{{- else }}
- transform/drop_routing_attribute
{{- end }}
receivers:
- telegraf
- otlp
11 changes: 11 additions & 0 deletions deploy/helm/sumologic/conf/metrics/otelcol/processors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ resource/remove_k8s_pod_pod_name:
- action: delete
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.
Expand Down Expand Up @@ -163,6 +164,7 @@ routing:
- exporters:
- sumologic/default
value: /prometheus.metrics.applications.custom
{{- end }}

## Configuration for Source Processor
## Source processor adds Sumo Logic related metadata
Expand All @@ -176,6 +178,7 @@ source:
sumologic_schema:
add_cloud_namespace: false

{{- if eq .Values.sumologic.metrics.sourceType "http" }}
transform/prepare_routing:
error_mode: ignore
metric_statements:
Expand All @@ -189,6 +192,14 @@ transform/prepare_routing:
- 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
Expand Down
27 changes: 27 additions & 0 deletions deploy/helm/sumologic/templates/_helpers/_metrics.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,33 @@ sumologic.com/app: otelcol
{{ template "sumologic.metadata.name.metrics.targetallocator.name" . }}
{{- end -}}

{{/*
Return the metrics format for the default Sumologic exporter for metrics.
'{{ include "metrics.otelcol.exporter.format" . }}'
*/}}
{{- define "metrics.otelcol.exporter.format" -}}
{{- if eq .Values.sumologic.metrics.sourceType "http" -}}
{{- "prometheus" -}}
{{- else if eq .Values.sumologic.metrics.sourceType "otlp" -}}
{{- "otlp" -}}
{{- else -}}
{{- fail "`sumologic.metrics.sourceType` can only be `http` or `otlp`" -}}
{{- end -}}
{{- end -}}

{{/*
Return the endpoint for the default Sumologic exporter for metrics.
'{{ include "metrics.otelcol.exporter.endpoint" . }}'
*/}}
{{- define "metrics.otelcol.exporter.endpoint" -}}
{{- if eq .Values.sumologic.metrics.sourceType "http" -}}
{{- "${SUMO_ENDPOINT_DEFAULT_METRICS_SOURCE}" -}}
{{- else if eq .Values.sumologic.metrics.sourceType "otlp" -}}
{{- "${SUMO_ENDPOINT_DEFAULT_OTLP_METRICS_SOURCE}" -}}
{{- else -}}
{{- fail "`sumologic.metrics.sourceType` can only be `http` or `otlp`" -}}
{{- end -}}
{{- end -}}

{{/*
Generate metrics match configuration
Expand Down
9 changes: 9 additions & 0 deletions deploy/helm/sumologic/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ sumologic:
default:
name: (default-metrics)
config-name: endpoint-metrics
default-otlp:
name: metrics-otlp
config-name: endpoint-metrics-otlp
properties:
content_type: Otlp
apiserver:
name: apiserver-metrics
config-name: endpoint-metrics-apiserver
Expand Down Expand Up @@ -722,6 +727,10 @@ sumologic:
matchLabels:
app: kube-prometheus-stack-prometheus

## The type of source we send to in Sumo. The possible values are http and otlp.
## Consult the documentation for more information.
sourceType: http

### Traces configuration
## Set the enabled flag to false to disable traces ingestion.
traces:
Expand Down
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Documentation links:
- [Comparison of Fluentd and Opentelemetry Collector functionality](/docs/fluent/fluentd-otc-comparison.md)
- [Comparison of Fluent Bit and Opentelemetry Collector functionality](/docs/fluentbit-otc-comparison.md)
- [Traces - auto-instrumentation in Kubernetes](https://help.sumologic.com/docs/apm/traces/get-started-transaction-tracing/opentelemetry-instrumentation/kubernetes)
- [OTLP source](/docs/otlp-source.md)
- Fluentd and Fluent-Bit
- [Adding Additional Fluentd Plugins](/docs/fluent/additional-fluentd-plugins.md)
- [Container log parsing with Fluent-Bit (Docker, CRI-O, containerd)](/docs/fluent/container-logs.md)
Expand Down
12 changes: 10 additions & 2 deletions docs/otlp-source.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ The data needed to be converted to the formats the generic HTTP source supports
Recently, we've added support for directly sending data using the OTLP protocol to Sumo Logic. This is achieved using the [OTLP
source][otlp_source]. This document explains how to use this new source with the Helm Chart.

**Note:** This Chart currently only supports OTLP Source for the following signal types: logs, events

## Enabling the OTLP source

### For logs
Expand All @@ -21,6 +19,16 @@ sumologic:
sourceType: otlp
```
### For metrics
Add the following to your configuration:
```yaml
sumologic:
metricss:
sourceType: otlp
```
### For traces
Add the following to your configuration:
Expand Down
46 changes: 46 additions & 0 deletions tests/helm/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"path"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v3"
)
Expand Down Expand Up @@ -141,3 +142,48 @@ func TestMetadataMetricsOtelConfigExtraProcessors(t *testing.T) {

require.Equal(t, expectedPipelineValue, otelConfig.Service.Pipelines.Metrics.Processors)
}

func TestMetadataSourceTypeOTLP(t *testing.T) {
t.Parallel()
templatePath := "templates/metrics/otelcol/configmap.yaml"

type OtelConfig struct {
Exporters struct {
Default struct {
MetricFormat string `yaml:"metric_format"`
Endpoint string
} `yaml:"sumologic/default"`
Rest map[string]interface{} `yaml:",inline"`
}
Processors map[string]interface{}
Service struct {
Pipelines struct {
Metrics struct {
Processors []string `yaml:"processors"`
Exporters []string `yaml:"exporters"`
}
}
}
}

var otelConfig OtelConfig
valuesYaml := `
sumologic:
metrics:
sourceType: otlp
`
otelConfigYaml := GetOtelConfigYaml(t, valuesYaml, templatePath)
err := yaml.Unmarshal([]byte(otelConfigYaml), &otelConfig)
require.NoError(t, err)

assert.Equal(t, otelConfig.Exporters.Default.MetricFormat, "otlp")
assert.Equal(t, otelConfig.Exporters.Default.Endpoint, "${SUMO_ENDPOINT_DEFAULT_OTLP_METRICS_SOURCE}")
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"})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sumologic:
metrics:
sourceType: otlp
Loading

0 comments on commit fae8c2e

Please sign in to comment.