Skip to content

Commit

Permalink
[exporter/influxdb] configurable LogRecord dimensions
Browse files Browse the repository at this point in the history
Adds new config value `LogRecordDimensions` to influxdbexporter, similar to open-telemetry#23230. This allows the user to specify which otel attributes translate to InfluxDB tags, and which should be written to the `attributes` InfluxDB field.

Incidentally, this change also updates the main dependency of influxdbreceiver, but no important changes were made to that module.
  • Loading branch information
jacobmarble committed Aug 31, 2023
1 parent f6f1a24 commit 93c5219
Show file tree
Hide file tree
Showing 16 changed files with 120 additions and 59 deletions.
27 changes: 27 additions & 0 deletions .chloggen/jgm-log-record-dimensions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: influxdbexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add user-configurable LogRecord dimensions (otel attributes -> InfluxDB tags)

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [26342]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
6 changes: 3 additions & 3 deletions cmd/configschema/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,9 @@ require (
github.com/imdario/mergo v0.3.15 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/influxdata/go-syslog/v3 v3.0.1-0.20210608084020-ac565dc76ba6 // indirect
github.com/influxdata/influxdb-observability/common v0.5.5 // indirect
github.com/influxdata/influxdb-observability/influx2otel v0.5.5 // indirect
github.com/influxdata/influxdb-observability/otel2influx v0.5.5 // indirect
github.com/influxdata/influxdb-observability/common v0.5.6 // indirect
github.com/influxdata/influxdb-observability/influx2otel v0.5.6 // indirect
github.com/influxdata/influxdb-observability/otel2influx v0.5.6 // indirect
github.com/influxdata/line-protocol/v2 v2.2.1 // indirect
github.com/ionos-cloud/sdk-go/v6 v6.1.6 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
Expand Down
12 changes: 6 additions & 6 deletions cmd/configschema/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions cmd/otelcontribcol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,9 @@ require (
github.com/imdario/mergo v0.3.15 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/influxdata/go-syslog/v3 v3.0.1-0.20210608084020-ac565dc76ba6 // indirect
github.com/influxdata/influxdb-observability/common v0.5.5 // indirect
github.com/influxdata/influxdb-observability/influx2otel v0.5.5 // indirect
github.com/influxdata/influxdb-observability/otel2influx v0.5.5 // indirect
github.com/influxdata/influxdb-observability/common v0.5.6 // indirect
github.com/influxdata/influxdb-observability/influx2otel v0.5.6 // indirect
github.com/influxdata/influxdb-observability/otel2influx v0.5.6 // indirect
github.com/influxdata/line-protocol/v2 v2.2.1 // indirect
github.com/ionos-cloud/sdk-go/v6 v6.1.6 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
Expand Down
12 changes: 6 additions & 6 deletions cmd/otelcontribcol/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions exporter/influxdbexporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ The following configuration options are supported:
* `username` (optional) Basic auth username for authenticating with InfluxDB v1.x
* `password` (optional) Basic auth password for authenticating with InfluxDB v1.x
* `span_dimensions` (default = service.name, span.name) Span attributes to use as dimensions (InfluxDB tags)
* `log_record_dimensions` (default = service.name) Log Record attributes to use as dimensions (InfluxDB tags)
* `payload_max_lines` (default = 10_000) Maximum number of lines allowed per HTTP POST request
* `payload_max_bytes` (default = 10_000_000) Maximum number of bytes allowed per HTTP POST request
* `metrics_schema` (default = telegraf-prometheus-v1) The chosen metrics schema to write; must be one of:
Expand Down Expand Up @@ -63,6 +64,8 @@ exporters:
span_dimensions:
- service.name
- span.name
log_record_dimensions:
- service.name
metrics_schema: telegraf-prometheus-v1

sending_queue:
Expand Down
42 changes: 34 additions & 8 deletions exporter/influxdbexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ type Config struct {
// - https://github.com/open-telemetry/opentelemetry-collector/tree/main/semconv
SpanDimensions []string `mapstructure:"span_dimensions"`

// LogRecordDimensions are log record attributes to be used as line protocol tags.
// These are always included as tags, if available:
// - trace ID
// - span ID
// The default values:
// - service.name
// Other common attributes can be found here:
// - https://github.com/open-telemetry/opentelemetry-collector/tree/main/semconv
// When using InfluxDB for both logs and traces, be certain that log_record_dimensions
// matches the tracing span_dimensions value.
LogRecordDimensions []string `mapstructure:"log_record_dimensions"`

// MetricsSchema indicates the metrics schema to emit to line protocol.
// Options:
// - telegraf-prometheus-v1
Expand All @@ -64,19 +76,33 @@ type Config struct {
}

func (cfg *Config) Validate() error {
uniqueDimensions := make(map[string]struct{}, len(cfg.SpanDimensions))
duplicateDimensions := make(map[string]struct{})
spanDimensions := make(map[string]struct{}, len(cfg.SpanDimensions))
duplicateSpanDimensions := make(map[string]struct{})
for _, k := range cfg.SpanDimensions {
if _, found := uniqueDimensions[k]; found {
duplicateDimensions[k] = struct{}{}
if _, found := spanDimensions[k]; found {
duplicateSpanDimensions[k] = struct{}{}
} else {
uniqueDimensions[k] = struct{}{}
spanDimensions[k] = struct{}{}
}
}

if len(duplicateDimensions) > 0 {
if len(duplicateSpanDimensions) > 0 {
return fmt.Errorf("duplicate span dimension(s) configured: %s",
strings.Join(maps.Keys(duplicateDimensions), ","))
strings.Join(maps.Keys(duplicateSpanDimensions), ","))
}

logRecordDimensions := make(map[string]struct{}, len(cfg.LogRecordDimensions))
duplicateLogRecordDimensions := make(map[string]struct{})
for _, k := range cfg.LogRecordDimensions {
if _, found := logRecordDimensions[k]; found {
duplicateLogRecordDimensions[k] = struct{}{}
} else {
logRecordDimensions[k] = struct{}{}
}
}
if len(duplicateLogRecordDimensions) > 0 {
return fmt.Errorf("duplicate log record dimension(s) configured: %s",
strings.Join(maps.Keys(duplicateLogRecordDimensions), ","))
}

return nil
}
15 changes: 8 additions & 7 deletions exporter/influxdbexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,14 @@ func TestLoadConfig(t *testing.T) {
RandomizationFactor: backoff.DefaultRandomizationFactor,
Multiplier: backoff.DefaultMultiplier,
},
Org: "my-org",
Bucket: "my-bucket",
Token: "my-token",
SpanDimensions: []string{"service.name", "span.name"},
MetricsSchema: "telegraf-prometheus-v1",
PayloadMaxLines: 72,
PayloadMaxBytes: 27,
Org: "my-org",
Bucket: "my-bucket",
Token: "my-token",
SpanDimensions: []string{"service.name", "span.name"},
LogRecordDimensions: []string{"service.name"},
MetricsSchema: "telegraf-prometheus-v1",
PayloadMaxLines: 72,
PayloadMaxBytes: 27,
},
},
}
Expand Down
10 changes: 6 additions & 4 deletions exporter/influxdbexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ func createDefaultConfig() component.Config {
"User-Agent": "OpenTelemetry -> Influx",
},
},
QueueSettings: exporterhelper.NewDefaultQueueSettings(),
RetrySettings: exporterhelper.NewDefaultRetrySettings(),
MetricsSchema: common.MetricsSchemaTelegrafPrometheusV1.String(),
SpanDimensions: otel2influx.DefaultOtelTracesToLineProtocolConfig().SpanDimensions,
QueueSettings: exporterhelper.NewDefaultQueueSettings(),
RetrySettings: exporterhelper.NewDefaultRetrySettings(),
MetricsSchema: common.MetricsSchemaTelegrafPrometheusV1.String(),
SpanDimensions: otel2influx.DefaultOtelTracesToLineProtocolConfig().SpanDimensions,
LogRecordDimensions: otel2influx.DefaultOtelLogsToLineProtocolConfig().LogRecordDimensions,
// defaults per suggested:
// https://docs.influxdata.com/influxdb/cloud-serverless/write-data/best-practices/optimize-writes/#batch-writes
PayloadMaxLines: 10_000,
Expand Down Expand Up @@ -133,6 +134,7 @@ func createLogsExporter(ctx context.Context, set exporter.CreateSettings, config
expConfig := otel2influx.DefaultOtelLogsToLineProtocolConfig()
expConfig.Logger = logger
expConfig.Writer = writer
expConfig.LogRecordDimensions = cfg.LogRecordDimensions
exp, err := otel2influx.NewOtelLogsToLineProtocol(expConfig)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions exporter/influxdbexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ go 1.20

require (
github.com/cenkalti/backoff/v4 v4.2.1
github.com/influxdata/influxdb-observability/common v0.5.5
github.com/influxdata/influxdb-observability/otel2influx v0.5.5
github.com/influxdata/influxdb-observability/common v0.5.6
github.com/influxdata/influxdb-observability/otel2influx v0.5.6
github.com/influxdata/line-protocol/v2 v2.2.1
github.com/stretchr/testify v1.8.4
go.opentelemetry.io/collector/component v0.84.0
Expand Down
8 changes: 4 additions & 4 deletions exporter/influxdbexporter/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions exporter/influxdbexporter/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ influxdb/override-config:
span_dimensions:
- service.name
- span.name
log_record_dimensions:
- service.name
payload_max_lines: 72
payload_max_bytes: 27
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,9 @@ require (
github.com/imdario/mergo v0.3.15 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/influxdata/go-syslog/v3 v3.0.1-0.20210608084020-ac565dc76ba6 // indirect
github.com/influxdata/influxdb-observability/common v0.5.5 // indirect
github.com/influxdata/influxdb-observability/influx2otel v0.5.5 // indirect
github.com/influxdata/influxdb-observability/otel2influx v0.5.5 // indirect
github.com/influxdata/influxdb-observability/common v0.5.6 // indirect
github.com/influxdata/influxdb-observability/influx2otel v0.5.6 // indirect
github.com/influxdata/influxdb-observability/otel2influx v0.5.6 // indirect
github.com/influxdata/line-protocol/v2 v2.2.1 // indirect
github.com/ionos-cloud/sdk-go/v6 v6.1.6 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions receiver/influxdbreceiver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ go 1.20

require (
github.com/influxdata/influxdb-client-go/v2 v2.12.3
github.com/influxdata/influxdb-observability/common v0.5.5
github.com/influxdata/influxdb-observability/influx2otel v0.5.5
github.com/influxdata/influxdb-observability/common v0.5.6
github.com/influxdata/influxdb-observability/influx2otel v0.5.6
github.com/influxdata/influxdb1-client v0.0.0-20220302092344-a9ab5670611c
github.com/influxdata/line-protocol/v2 v2.2.1
github.com/open-telemetry/opentelemetry-collector-contrib/internal/common v0.84.0
Expand Down
Loading

0 comments on commit 93c5219

Please sign in to comment.