Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance config validation by Instantiating service during dryrun. #12488

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

sudiptob2
Copy link
Contributor

@sudiptob2 sudiptob2 commented Feb 25, 2025

Description

As mentioned in #8721 (comment), we can surface configuration errors by instantiating the service during a dry run.

Expanding on this idea, this PR enhances configuration validation. The validate command will now capture all validation errors that would prevent the collector from starting.

Link to the tracking issue

Fixes #8721

Testing

Added unit tests. Also, a few scenarios and example output are given below. I will add more unit tests if necessary.

1. Improper Connector Use

invalid_config.yaml
receivers:
  otlp:
    protocols:
      grpc:
exporters:
  debug:
connectors:
  forward:
service:
  pipelines:
    logs/in:
      receivers: [otlp]
      processors: []
      exporters: [forward]
    logs/in2:
      receivers: [ otlp ]
      processors: [ ]
      exporters: [ forward ]
    logs/out:
      receivers: [otlp]
      processors: []
      exporters: [debug]
    traces:
      receivers: [ otlp ]
      processors: [ ]
      exporters: [ forward ]
    metrics:
      receivers: [ forward ]
      processors: [ ]
      exporters: [ debug ]

Before: No error detected

Proposed Change:

Error: failed to build pipelines: connector "forward" used as exporter in [logs/in2 logs/in] pipeline but not used in any supported receiver pipeline
2025/02/25 16:58:09 collector server run finished with error: failed to build pipelines: connector "forward" used as exporter in [logs/in2 logs/in] pipeline but not used in any supported receiver pipeline

2. Unused Connector

invalid_config.yaml
receivers:
  otlp:
    protocols:
      grpc:
      http:
exporters:
  debug:
connectors:
  forward:
service:
  pipelines:
    logs/out:
      receivers: [forward]
      processors: []
      exporters: [debug]

Before: No error detected

Proposed Change:

Error: failed to build pipelines: connector "forward" used as receiver in [logs/out] pipeline but not used in any supported exporter pipeline
2025/02/26 10:40:53 collector server run finished with error: failed to build pipelines: connector "forward" used as receiver in [logs/out] pipeline but not used in any supported exporter pipeline

2. Cycle in the Pipeline

invalid_config.yaml
receivers:
  otlp:
    protocols:
      grpc:

exporters:
  debug:

connectors:
  forward:

service:
  pipelines:
    traces/in:
      receivers: [forward]
      processors: [ ]
      exporters: [forward]
    traces/out:
      receivers: [forward]
      processors: [ ]
      exporters: [forward]

Before: No error detected

Proposed Change:

Error: failed to build pipelines: cycle detected: connector "forward" (traces to traces) -> connector "forward" (traces to traces)
2025/02/26 11:12:53 collector server run finished with error: failed to build pipelines: cycle detected: connector "forward" (traces to traces) -> connector "forward" (traces to traces)

Note

I removed the following log as it seemed redundant to me and it is also surfaced during validation. Let me know if we absolutely need to keep it

logger.Info("Setting up own telemetry...")

Copy link

codecov bot commented Feb 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.03%. Comparing base (0faea29) to head (bce7fac).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #12488      +/-   ##
==========================================
+ Coverage   92.00%   92.03%   +0.03%     
==========================================
  Files         469      469              
  Lines       25355    25358       +3     
==========================================
+ Hits        23327    23339      +12     
+ Misses       1619     1613       -6     
+ Partials      409      406       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sudiptob2 sudiptob2 force-pushed the fix/8721/config-validation branch 4 times, most recently from 89f448f to 754e9a7 Compare February 26, 2025 03:56
@sudiptob2 sudiptob2 marked this pull request as ready for review February 26, 2025 04:18
@sudiptob2 sudiptob2 requested a review from a team as a code owner February 26, 2025 04:18
@sudiptob2 sudiptob2 requested a review from mx-psi February 26, 2025 04:18
@sudiptob2
Copy link
Contributor Author

sudiptob2 commented Feb 26, 2025

Some tests are failing, which are not related to this PR. Any guidance would be helpful.

Copy link
Member

@mx-psi mx-psi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the errors that were not reported before that are reported after this change? Can we instead statically validate those?

@mx-psi
Copy link
Member

mx-psi commented Feb 26, 2025

Feel free to ignore the errors, they are not related to this PR

@sudiptob2
Copy link
Contributor Author

sudiptob2 commented Feb 26, 2025

@mx-psi Thanks for the quick response!

What are the errors that were not reported before that are reported after this change? Can we instead statically validate those?

This approach should catch all errors in the pipeline configuration. I am not aware of it all, but here are a couple of examples.

Especially for $\textcolor{red}{\textsf{cycle detection,}}$ we need to initialize the graph. Statically verifying that might not be feasible.

1. Improper Connector Use

invalid_config.yaml
receivers:
  otlp:
    protocols:
      grpc:
exporters:
  debug:
connectors:
  forward:
service:
  pipelines:
    logs/in:
      receivers: [otlp]
      processors: []
      exporters: [forward]
    logs/in2:
      receivers: [ otlp ]
      processors: [ ]
      exporters: [ forward ]
    logs/out:
      receivers: [otlp]
      processors: []
      exporters: [debug]
    traces:
      receivers: [ otlp ]
      processors: [ ]
      exporters: [ forward ]
    metrics:
      receivers: [ forward ]
      processors: [ ]
      exporters: [ debug ]

Before: No error detected

Proposed Change:

Error: failed to build pipelines: connector "forward" used as exporter in [logs/in2 logs/in] pipeline but not used in any supported receiver pipeline
2025/02/25 16:58:09 collector server run finished with error: failed to build pipelines: connector "forward" used as exporter in [logs/in2 logs/in] pipeline but not used in any supported receiver pipeline

2. Unused Connector

invalid_config.yaml
receivers:
  otlp:
    protocols:
      grpc:
      http:
exporters:
  debug:
connectors:
  forward:
service:
  pipelines:
    logs/out:
      receivers: [forward]
      processors: []
      exporters: [debug]

Before: No error detected

Proposed Change:

Error: failed to build pipelines: connector "forward" used as receiver in [logs/out] pipeline but not used in any supported exporter pipeline
2025/02/26 10:40:53 collector server run finished with error: failed to build pipelines: connector "forward" used as receiver in [logs/out] pipeline but not used in any supported exporter pipeline

2. Cycle in the Pipeline

invalid_config.yaml
receivers:
  otlp:
    protocols:
      grpc:

exporters:
  debug:

connectors:
  forward:

service:
  pipelines:
    traces/in:
      receivers: [forward]
      processors: [ ]
      exporters: [forward]
    traces/out:
      receivers: [forward]
      processors: [ ]
      exporters: [forward]

Before: No error detected

Proposed Change:

Error: failed to build pipelines: cycle detected: connector "forward" (traces to traces) -> connector "forward" (traces to traces)
2025/02/26 11:12:53 collector server run finished with error: failed to build pipelines: cycle detected: connector "forward" (traces to traces) -> connector "forward" (traces to traces)

@sudiptob2 sudiptob2 force-pushed the fix/8721/config-validation branch from 754e9a7 to b863577 Compare February 26, 2025 17:55
@sudiptob2 sudiptob2 force-pushed the fix/8721/config-validation branch from 16f3e68 to bce7fac Compare February 27, 2025 20:10
@sudiptob2 sudiptob2 requested a review from mx-psi February 28, 2025 01:40
Comment on lines +283 to +284
_, err = col.createService(ctx, cfg, factories)
return err
Copy link
Member

@bogdandrutu bogdandrutu Feb 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this? Why do we need to start things to make sure we are ok?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it does not start a service. As mentioned in this #8721 (comment) we can surface configuration errors by instantiating the service during a dry run. This will initialize the graph, and detect cycles and other errors which might prevent the service to start.

Copy link
Member

@bogdandrutu bogdandrutu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer the DryRun to not have to start the collector, what do we miss that we need to do this?

@sudiptob2
Copy link
Contributor Author

I would prefer the DryRun to not have to start the collector, what do we miss that we need to do this?

These are the error that current validate command can not detect

1. Improper Connector Use

invalid_config.yaml
receivers:
  otlp:
    protocols:
      grpc:
exporters:
  debug:
connectors:
  forward:
service:
  pipelines:
    logs/in:
      receivers: [otlp]
      processors: []
      exporters: [forward]
    logs/in2:
      receivers: [ otlp ]
      processors: [ ]
      exporters: [ forward ]
    logs/out:
      receivers: [otlp]
      processors: []
      exporters: [debug]
    traces:
      receivers: [ otlp ]
      processors: [ ]
      exporters: [ forward ]
    metrics:
      receivers: [ forward ]
      processors: [ ]
      exporters: [ debug ]

Before: No error detected

Proposed Change:

Error: failed to build pipelines: connector "forward" used as exporter in [logs/in2 logs/in] pipeline but not used in any supported receiver pipeline
2025/02/25 16:58:09 collector server run finished with error: failed to build pipelines: connector "forward" used as exporter in [logs/in2 logs/in] pipeline but not used in any supported receiver pipeline

2. Unused Connector

invalid_config.yaml
receivers:
  otlp:
    protocols:
      grpc:
      http:
exporters:
  debug:
connectors:
  forward:
service:
  pipelines:
    logs/out:
      receivers: [forward]
      processors: []
      exporters: [debug]

Before: No error detected

Proposed Change:

Error: failed to build pipelines: connector "forward" used as receiver in [logs/out] pipeline but not used in any supported exporter pipeline
2025/02/26 10:40:53 collector server run finished with error: failed to build pipelines: connector "forward" used as receiver in [logs/out] pipeline but not used in any supported exporter pipeline

2. Cycle in the Pipeline

invalid_config.yaml
receivers:
  otlp:
    protocols:
      grpc:

exporters:
  debug:

connectors:
  forward:

service:
  pipelines:
    traces/in:
      receivers: [forward]
      processors: [ ]
      exporters: [forward]
    traces/out:
      receivers: [forward]
      processors: [ ]
      exporters: [forward]

Before: No error detected

Proposed Change:

Error: failed to build pipelines: cycle detected: connector "forward" (traces to traces) -> connector "forward" (traces to traces)
2025/02/26 11:12:53 collector server run finished with error: failed to build pipelines: cycle detected: connector "forward" (traces to traces) -> connector "forward" (traces to traces)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Validate Connector Usage
3 participants