Skip to content

Commit

Permalink
[processor/filter] Add telemetry for dropped metrics, logs, and spans (
Browse files Browse the repository at this point in the history
…open-telemetry#29081)

**Description:**

Adds telemetry for metrics, logs, and spans that were intentionally
dropped via a `filterprocessor`. Specifically, the following metrics are
added:

`otelcol_processor_filter_datapoints_filtered`
`otelcol_processor_filter_logs_filtered`
`otelcol_processor_filter_spans_filtered`

Please let me know any feedback/thoughts on the naming or anything else!

**Link to tracking Issue:** open-telemetry#13169

**Testing:** I've used batchprocessor as an example for a couple of
tests, Filter*ProcessorTelemetryWithOC. I kept the wrapping code so that
OTEL versions can be easily added when that is ready in contrib. Overall
the tests are not super comprehensive and I could improve them if
needed, but as-is they were helpful for debugging.

<details>
<summary><i>Additionally, here's some stuff you can use for manually
testing.</i></summary>

There might be a better way to do this, but I just used hostmetrics,
filelog, and [this article from
honeycomb](https://www.honeycomb.io/blog/test-span-opentelemetry-collector)
with otlp/http.

Note, this should be run from the root of the contrib repo.

Add/overwrite `local/config.yaml`, `local/span.json`, and run:

```bash
mkdir -p local

cat >local/config.yaml <<EOL
receivers:
  hostmetrics:
    collection_interval: 30s
    initial_delay: 1s
    scrapers:
      load:
  filelog:
    include:
      ## echo '{"timestamp":"2023-12-18 12:00:00","msg":"foo"}' >> /tmp/otel-test.log
      ## echo '{"timestamp":"2023-12-18 12:00:00","msg":"bar"}' >> /tmp/otel-test.log
      ## echo '{"timestamp":"2023-12-18 12:00:00","msg":"baz"}' >> /tmp/otel-test.log
      - /tmp/otel-test.log
    operators:
      - type: json_parser
        timestamp:
          parse_from: attributes.timestamp
          layout: "%Y-%m-%d %H:%M:%S"
  otlp:
    protocols:
      ## curl -i http://localhost:4318/v1/traces -X POST -H "Content-Type: application/json" -d @local/span.json
      http:

processors:
  filter/test:
    metrics:
      metric:
        # Should drop 2 of the 3 metrics, 5m average remains
        - 'name=="system.cpu.load_average.1m"'
        - 'name=="system.cpu.load_average.15m"'
    logs:
      log_record:
        # Should filter out "bar" and "baz"
        - 'IsMatch(body, ".*ba.*")'
    traces:
      span:
        # Should drop 1 of the 2 spans
        - 'name == "foobar"'

exporters:
  debug:
    verbosity: detailed
    sampling_initial: 5
    sampling_thereafter: 200

service:
  extensions: []
  pipelines:
    metrics:
      receivers: [hostmetrics]
      processors: [filter/test]
      exporters: [debug]
    logs:
      receivers: [filelog]
      processors: [filter/test]
      exporters: [debug]
    traces:
      receivers: [otlp]
      processors: [filter/test]
      exporters: [debug]

  telemetry:
    logs:
      level: debug
    metrics:
      level: detailed
      address: 0.0.0.0:8888
EOL

cat >local/span.json <<EOL
{
  "resourceSpans": [
    {
      "resource": {
        "attributes": [
          {
            "key": "service.name",
            "value": {
              "stringValue": "test-with-curl"
            }
          }
        ]
      },
      "scopeSpans": [
        {
          "scope": {
            "name": "manual-test"
          },
          "spans": [
            {
              "traceId": "71699b6fe85982c7c8995ea3d9c95df2",
              "spanId": "3c191d03fa8be065",
              "name": "spanitron",
              "kind": 2,
              "droppedAttributesCount": 0,
              "events": [],
              "droppedEventsCount": 0,
              "status": {
                "code": 1
              }
            },
            {
              "traceId": "71699b6fe85982c7c8995ea3d9c95df2",
              "spanId": "2f357b34d32f77b4",
              "name": "foobar",
              "kind": 2,
              "droppedAttributesCount": 0,
              "events": [],
              "droppedEventsCount": 0,
              "status": {
                "code": 1
              }
            }
          ]
        }
      ]
    }
  ]
}
EOL

make run
```

Send some data to the receivers:

```bash
# Write some logs
echo '{"timestamp":"2023-12-18 12:00:00","msg":"foo"}' >> /tmp/otel-test.log
echo '{"timestamp":"2023-12-18 12:00:00","msg":"bar"}' >> /tmp/otel-test.log
echo '{"timestamp":"2023-12-18 12:00:00","msg":"baz"}' >> /tmp/otel-test.log

# Write some spans
curl -i http://localhost:4318/v1/traces -X POST -H "Content-Type: application/json" -d @local/span.json
```

Check the results:

```console
$ curl http://localhost:8888/metrics | grep filtered
# HELP otelcol_processor_filter_datapoints_filtered Number of metric data points dropped by the filter processor
# TYPE otelcol_processor_filter_datapoints_filtered counter
otelcol_processor_filter_datapoints_filtered{filter="filter/test",service_instance_id="a99d9078-548b-425f-8466-3e9e2e9bf3b1",service_name="otelcontribcol",service_version="0.91.0-dev"} 2
# HELP otelcol_processor_filter_logs_filtered Number of logs dropped by the filter processor
# TYPE otelcol_processor_filter_logs_filtered counter
otelcol_processor_filter_logs_filtered{filter="filter/test",service_instance_id="a99d9078-548b-425f-8466-3e9e2e9bf3b1",service_name="otelcontribcol",service_version="0.91.0-dev"} 2
# HELP otelcol_processor_filter_spans_filtered Number of spans dropped by the filter processor
# TYPE otelcol_processor_filter_spans_filtered counter
otelcol_processor_filter_spans_filtered{filter="filter/test",service_instance_id="a99d9078-548b-425f-8466-3e9e2e9bf3b1",service_name="otelcontribcol",service_version="0.91.0-dev"} 1
```

</details>

**Documentation:** I do not believe we document telemetry exposed by
components, but I could add this if needed.

---------

Co-authored-by: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com>
  • Loading branch information
2 people authored and nslaughter committed Dec 27, 2023
1 parent b607580 commit c4a053c
Show file tree
Hide file tree
Showing 12 changed files with 860 additions and 26 deletions.
27 changes: 27 additions & 0 deletions .chloggen/filterprocessor-telemetry.yaml
@@ -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: filterprocessor

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add telemetry for metrics, logs, and spans that were intentionally dropped via filterprocessor.

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

# (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 processor/filterprocessor/factory.go
Expand Up @@ -40,7 +40,7 @@ func createMetricsProcessor(
cfg component.Config,
nextConsumer consumer.Metrics,
) (processor.Metrics, error) {
fp, err := newFilterMetricProcessor(set.TelemetrySettings, cfg.(*Config))
fp, err := newFilterMetricProcessor(set, cfg.(*Config))
if err != nil {
return nil, err
}
Expand All @@ -59,7 +59,7 @@ func createLogsProcessor(
cfg component.Config,
nextConsumer consumer.Logs,
) (processor.Logs, error) {
fp, err := newFilterLogsProcessor(set.TelemetrySettings, cfg.(*Config))
fp, err := newFilterLogsProcessor(set, cfg.(*Config))
if err != nil {
return nil, err
}
Expand All @@ -78,7 +78,7 @@ func createTracesProcessor(
cfg component.Config,
nextConsumer consumer.Traces,
) (processor.Traces, error) {
fp, err := newFilterSpansProcessor(set.TelemetrySettings, cfg.(*Config))
fp, err := newFilterSpansProcessor(set, cfg.(*Config))
if err != nil {
return nil, err
}
Expand Down
20 changes: 18 additions & 2 deletions processor/filterprocessor/go.mod
Expand Up @@ -3,28 +3,41 @@ module github.com/open-telemetry/opentelemetry-collector-contrib/processor/filte
go 1.20

require (
contrib.go.opencensus.io/exporter/prometheus v0.4.2
github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.91.0
github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter v0.91.0
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl v0.91.0
github.com/prometheus/client_golang v1.17.0
github.com/prometheus/client_model v0.5.0
github.com/prometheus/common v0.45.0
github.com/stretchr/testify v1.8.4
go.opencensus.io v0.24.0
go.opentelemetry.io/collector/component v0.91.0
go.opentelemetry.io/collector/confmap v0.91.0
go.opentelemetry.io/collector/consumer v0.91.0
go.opentelemetry.io/collector/pdata v1.0.0
go.opentelemetry.io/collector/processor v0.91.0
go.opentelemetry.io/otel v1.21.0
go.opentelemetry.io/otel/metric v1.21.0
go.opentelemetry.io/otel/sdk/metric v1.21.0
go.opentelemetry.io/otel/trace v1.21.0
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.26.0
)

require (
github.com/alecthomas/participle/v2 v2.1.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/expr-lang/expr v1.15.7 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
Expand All @@ -34,26 +47,29 @@ require (
github.com/knadh/koanf/maps v0.1.1 // indirect
github.com/knadh/koanf/providers/confmap v0.1.0 // indirect
github.com/knadh/koanf/v2 v2.0.1 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/mapstructure v1.5.1-0.20220423185008-bf980b35cac4 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil v0.91.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
go.opencensus.io v0.24.0 // indirect
github.com/prometheus/procfs v0.11.1 // indirect
github.com/prometheus/statsd_exporter v0.22.7 // indirect
go.opentelemetry.io/collector v0.91.0 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.91.0 // indirect
go.opentelemetry.io/collector/featuregate v1.0.0 // indirect
go.opentelemetry.io/collector/semconv v0.91.0 // indirect
go.opentelemetry.io/otel v1.21.0 // indirect
go.opentelemetry.io/otel/sdk v1.21.0 // indirect
golang.org/x/exp v0.0.0-20231214170342-aacd6d4b4611 // indirect
golang.org/x/net v0.18.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

Expand Down

0 comments on commit c4a053c

Please sign in to comment.