Skip to content

[confmap] Improve error messages on invalid YAML #12000

Open
@tsloughter

Description

@tsloughter

Describe the bug

A duplicate key in the configuration like this duplicate use of http:

receivers:
  otlp:
    protocols:
      grpc:
        endpoint: "0.0.0.0:4317"
      http:
        endpoint: "0.0.0.0:4318"
      http:
        cors:
          allowed_origins:
          - "http://localhost:8000"
        endpoint: "0.0.0.0:4318"

when run with main results in the error message:

$ bin/otelcorecol_linux_amd64 --config ../roll_dice_gleam/otel-collector-config.yaml
Error: failed to get config: cannot resolve the configuration: retrieved value (type=string) cannot be used as a Conf
2024/12/31 10:58:11 collector server run finished with error: failed to get config: cannot resolve the configuration: retrieved value (type=string) cannot be used as a Conf

This makes no mention of where the issue in the file was found or that it was a duplicate key.

Compare to what the error message was as of commit 334d95aebcffc88fa19ac4233dc166dd51aaa55f:

Error: failed to resolve config: cannot resolve the configuration: cannot retrieve the configuration: yaml: unmarshal errors:
  line 9: mapping key "http" already defined at line 7
2024/12/31 10:53:08 collector server run finished with error: failed to resolve config: cannot resolve the configuration: cannot retrieve the configuration: yaml: unmarshal errors:
  line 9: mapping key "http" already defined at line 7

The line number and the key http was given and that it was a duplicate issue.

Steps to reproduce

Run a recent collector with the configuration like the above.

What did you expect to see?

The previous error message as shown above.

What did you see instead?

An error message that does not give details on the actual issue.

What version did you use?

does't work: ffcef93
works: 334d95a

What config did you use?

receivers:
  otlp:
    protocols:
      grpc:
        endpoint: "0.0.0.0:4317"
      http:
        endpoint: "0.0.0.0:4318"
      http:
        cors:
          allowed_origins:
          - "http://localhost:8000"
        endpoint: "0.0.0.0:4318"

exporters:
  debug:
    verbosity: detailed
    sampling_initial: 1
    sampling_thereafter: 1

  pipelines:
    traces:
      receivers: [otlp]
      processors: [h]
      exporters: [debug]
    metrics:
      receivers: [otlp]
      processors: []
      exporters: [debug]
    logs:
      receivers: [otlp]
      processors: [batch]
      exporters: [debug]

Environment

Fedora 41
Go 1.22.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions