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

MetricReader allows invalid configurations #138

Closed
marcalff opened this issue Nov 10, 2024 · 5 comments · Fixed by #148
Closed

MetricReader allows invalid configurations #138

marcalff opened this issue Nov 10, 2024 · 5 comments · Fixed by #148
Assignees

Comments

@marcalff
Copy link
Member

marcalff commented Nov 10, 2024

The following schema:

        "MetricReader": {
            "type": ["object", "null"],
            "additionalProperties": false,
            "minProperties": 1,
            "maxProperties": 2,
            "properties": {
                "periodic": {
                    "$ref": "#/$defs/PeriodicMetricReader"
                },
                "pull": {
                    "$ref": "#/$defs/PullMetricReader"
                },
                "producers": {
                    "type": "array",
                    "items": {
                        "$ref": "#/$defs/MetricProducer"
                    }
                }
            }
        },

is causing semantic issues.

Previously, it contained only "periodic" and "pull" properties, with max properties = 1, meaning a metric reader is either periodic or pull.

When producers was added, max properties was changed to 2.
This allows "periodic" + "producers", or "pull" + "producers", which is the intent (as I understand).

This however also allows to have both "periodic" and "pull", which are no longer mutually exclusive.

This opens the schema validation to unintended configurations, pushing this downstream to the SDK implementation.

If this combination is not allowed, this must be clarified explicitly:

  • for end users, to know what to expect
  • for SDK implementors, to test explicitly this case, so it can be handled correctly.

Found while implementing config.yaml for C++:

@marcalff
Copy link
Member Author

A possible fix is to move the "producers" property in each "periodic" and "pull" node.

@marcalff
Copy link
Member Author

According to the schema, a metric reader can also have only "producers", as this satisfies min properties = 1.

This is invalid, I think this part of the schema should be revisited.

@marcalff marcalff changed the title MetricReader needs more clarity for SDK implementors MetricReader allows invalid configurations Nov 10, 2024
@jack-berg
Copy link
Member

We could add documentation to type_descriptions.yaml that states that including both periodic and pull is invalid. We could also use oneOf or if / else to describe the that the properties are mutually exclusive. I have vague memory of jsonschema java tooling having bad / no support for anyof, oneof, but can't seem to find any old issues / PRs where its discussed. Even if jsonschema tooling struggles to enforce it, it could still be good to express in the schema.

@brettmc
Copy link
Contributor

brettmc commented Nov 13, 2024

+1 that this part of the schema is difficult to implement as-is. I am quite stuck when trying to devise a working implementation for PHP.

A possible fix is to move the "producers" property in each "periodic" and "pull" node.

I haven't tested it out, but I do feel that this would be a lot easier to implement...

marcalff added a commit to marcalff/opentelemetry-configuration that referenced this issue Dec 5, 2024
@marcalff marcalff self-assigned this Dec 5, 2024
jack-berg pushed a commit that referenced this issue Dec 9, 2024
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 a pull request may close this issue.

3 participants