Skip to content

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...")

@codecov
Copy link

codecov bot commented Feb 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.60%. Comparing base (ee0f0ae) to head (e53a1f7).
Report is 72 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #12488      +/-   ##
==========================================
+ Coverage   91.57%   91.60%   +0.03%     
==========================================
  Files         483      483              
  Lines       26383    26386       +3     
==========================================
+ Hits        24160    24172      +12     
+ Misses       1762     1756       -6     
+ Partials      461      458       -3     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@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 2 times, most recently from 16f3e68 to bce7fac Compare February 27, 2025 20:10
@sudiptob2 sudiptob2 requested a review from mx-psi February 28, 2025 01:40
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)

@github-actions
Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@sudiptob2
Copy link
Contributor Author

@bogdandrutu PR #12681, implements validation without instantiating the service, please take a look.

@sudiptob2 sudiptob2 requested a review from bogdandrutu March 22, 2025 13:54
@github-actions
Copy link
Contributor

github-actions bot commented Apr 8, 2025

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Apr 8, 2025
github-merge-queue bot pushed a commit that referenced this pull request Apr 9, 2025
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description
As described in
[#8721](#8721),
the current `validate` command cannot capture improper connector usage
errors during a dry run.

One proposed solution _(as mentioned in [this
comment](#8721 (comment)
is to surface configuration errors by instantiating the service during
the dry run. However, reviewers preferred statically verifying the
errors over instantiating the service (see the [PR #12488
comments](#12488)).

The validation logic for connectors is located in the
[`service/internal/graph`](https://github.com/open-telemetry/opentelemetry-collector/blob/1daa315455d02bac90185027878d858ba08a0f07/service/internal/graph)
package. In the discussion of [PR
#12681](#12681),
it was concluded that instantiating the graph is the better approach
(see [this
comment](#12681 (comment))).

Finally, this PR uses the `graph.Build()` method to surface
configuration errors during the dry run.

<!-- Issue number if applicable -->
#### Link to tracking issue
Fixes #8721 #12535

<!--Describe what testing was performed and which tests were added.-->
#### Testing

<!--Describe the documentation added.-->
#### Documentation

<!--Please delete paragraphs that you did not use before submitting.-->

---------

Signed-off-by: sudipto baral <[email protected]>
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.

Please rebase

mockMap: map[string]string{
"number": "123",
},
expectErr: true,
Copy link
Member

Choose a reason for hiding this comment

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

Please add a version without error.

if err = conf.Marshal(cfg); err != nil {
return fmt.Errorf("could not marshal configuration: %w", err)
}
_ = conf.Marshal(cfg)
Copy link
Member

Choose a reason for hiding this comment

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

why skip the error?

@sudiptob2
Copy link
Contributor Author

sudiptob2 commented Apr 10, 2025

We can close this one as #12712 was the final PR which is now merged. @bogdandrutu

@sudiptob2 sudiptob2 closed this Apr 10, 2025
@bogdandrutu bogdandrutu reopened this Apr 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Validate Connector Usage

3 participants