-
Notifications
You must be signed in to change notification settings - Fork 488
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
otelcolconvert: support converting filterprocessor (#6479)
Signed-off-by: Paschalis Tsilias <[email protected]>
- Loading branch information
1 parent
c00b19c
commit c5bfe59
Showing
5 changed files
with
174 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
converter/internal/otelcolconvert/converter_filterprocessor.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package otelcolconvert | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/grafana/agent/component/otelcol" | ||
"github.com/grafana/agent/component/otelcol/processor/filter" | ||
"github.com/grafana/agent/converter/diag" | ||
"github.com/grafana/agent/converter/internal/common" | ||
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/filterprocessor" | ||
"go.opentelemetry.io/collector/component" | ||
) | ||
|
||
func init() { | ||
converters = append(converters, filterProcessorConverter{}) | ||
} | ||
|
||
type filterProcessorConverter struct{} | ||
|
||
func (filterProcessorConverter) Factory() component.Factory { | ||
return filterprocessor.NewFactory() | ||
} | ||
|
||
func (filterProcessorConverter) InputComponentName() string { | ||
return "otelcol.processor.filter" | ||
} | ||
|
||
func (filterProcessorConverter) ConvertAndAppend(state *state, id component.InstanceID, cfg component.Config) diag.Diagnostics { | ||
var diags diag.Diagnostics | ||
|
||
label := state.FlowComponentLabel() | ||
|
||
args := toFilterProcessor(state, id, cfg.(*filterprocessor.Config)) | ||
block := common.NewBlockWithOverride([]string{"otelcol", "processor", "filter"}, label, args) | ||
|
||
diags.Add( | ||
diag.SeverityLevelInfo, | ||
fmt.Sprintf("Converted %s into %s", stringifyInstanceID(id), stringifyBlock(block)), | ||
) | ||
|
||
state.Body().AppendBlock(block) | ||
return diags | ||
} | ||
|
||
func toFilterProcessor(state *state, id component.InstanceID, cfg *filterprocessor.Config) *filter.Arguments { | ||
var ( | ||
nextMetrics = state.Next(id, component.DataTypeMetrics) | ||
nextLogs = state.Next(id, component.DataTypeLogs) | ||
nextTraces = state.Next(id, component.DataTypeTraces) | ||
) | ||
|
||
return &filter.Arguments{ | ||
ErrorMode: cfg.ErrorMode, | ||
Traces: filter.TraceConfig{ | ||
Span: cfg.Traces.SpanConditions, | ||
SpanEvent: cfg.Traces.SpanEventConditions, | ||
}, | ||
Metrics: filter.MetricConfig{ | ||
Metric: cfg.Metrics.MetricConditions, | ||
Datapoint: cfg.Metrics.DataPointConditions, | ||
}, | ||
Logs: filter.LogConfig{ | ||
LogRecord: cfg.Logs.LogConditions, | ||
}, | ||
Output: &otelcol.ConsumerArguments{ | ||
Metrics: toTokenizedConsumers(nextMetrics), | ||
Logs: toTokenizedConsumers(nextLogs), | ||
Traces: toTokenizedConsumers(nextTraces), | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
otelcol.receiver.otlp "default" { | ||
grpc { } | ||
|
||
http { } | ||
|
||
output { | ||
metrics = [otelcol.processor.filter.default_ottl.input] | ||
logs = [otelcol.processor.filter.default_ottl.input] | ||
traces = [otelcol.processor.filter.default_ottl.input] | ||
} | ||
} | ||
|
||
otelcol.processor.filter "default_ottl" { | ||
error_mode = "ignore" | ||
|
||
traces { | ||
span = ["attributes[\"container.name\"] == \"app_container_1\"", "resource.attributes[\"host.name\"] == \"localhost\"", "name == \"app_3\""] | ||
spanevent = ["attributes[\"grpc\"] == true", "IsMatch(name, \".*grpc.*\")"] | ||
} | ||
|
||
metrics { | ||
metric = ["name == \"my.metric\" and resource.attributes[\"my_label\"] == \"abc123\"", "type == METRIC_DATA_TYPE_HISTOGRAM"] | ||
datapoint = ["metric.type == METRIC_DATA_TYPE_SUMMARY", "resource.attributes[\"service.name\"] == \"my_service_name\""] | ||
} | ||
|
||
logs { | ||
log_record = ["IsMatch(body, \".*password.*\")", "severity_number < SEVERITY_NUMBER_WARN"] | ||
} | ||
|
||
output { | ||
metrics = [otelcol.exporter.otlp.default.input] | ||
logs = [otelcol.exporter.otlp.default.input] | ||
traces = [otelcol.exporter.otlp.default.input] | ||
} | ||
} | ||
|
||
otelcol.exporter.otlp "default" { | ||
client { | ||
endpoint = "database:4317" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
receivers: | ||
otlp: | ||
protocols: | ||
grpc: | ||
http: | ||
|
||
exporters: | ||
otlp: | ||
# Our defaults have drifted from upstream, so we explicitly set our | ||
# defaults below (balancer_name and queue_size). | ||
endpoint: database:4317 | ||
balancer_name: pick_first | ||
sending_queue: | ||
queue_size: 5000 | ||
|
||
processors: | ||
filter/ottl: | ||
error_mode: ignore | ||
metrics: | ||
metric: | ||
- 'name == "my.metric" and resource.attributes["my_label"] == "abc123"' | ||
- 'type == METRIC_DATA_TYPE_HISTOGRAM' | ||
datapoint: | ||
- 'metric.type == METRIC_DATA_TYPE_SUMMARY' | ||
- 'resource.attributes["service.name"] == "my_service_name"' | ||
logs: | ||
log_record: | ||
- 'IsMatch(body, ".*password.*")' | ||
- 'severity_number < SEVERITY_NUMBER_WARN' | ||
traces: | ||
span: | ||
- 'attributes["container.name"] == "app_container_1"' | ||
- 'resource.attributes["host.name"] == "localhost"' | ||
- 'name == "app_3"' | ||
spanevent: | ||
- 'attributes["grpc"] == true' | ||
- 'IsMatch(name, ".*grpc.*")' | ||
|
||
service: | ||
pipelines: | ||
metrics: | ||
receivers: [otlp] | ||
processors: [filter/ottl] | ||
exporters: [otlp] | ||
logs: | ||
receivers: [otlp] | ||
processors: [filter/ottl] | ||
exporters: [otlp] | ||
traces: | ||
receivers: [otlp] | ||
processors: [filter/ottl] | ||
exporters: [otlp] | ||
|