diff --git a/CHANGELOG.md b/CHANGELOG.md index d22f80e..a160e6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * Improved file_format documentation. [#137](https://github.com/open-telemetry/opentelemetry-configuration/pull/137) * Periodic exporter interval default value is inconsistent [#143](https://github.com/open-telemetry/opentelemetry-configuration/pull/143) +* Fix MetricReader invalid configurations [#148](https://github.com/open-telemetry/opentelemetry-configuration/pull/148) ## [v0.3.0] - 2024-05-08 diff --git a/README.md b/README.md index 647e17b..31d383e 100644 --- a/README.md +++ b/README.md @@ -121,6 +121,70 @@ If a property is _not_ required, it should include a [comment](./CONTRIBUTING.md If a property `type` includes `null`, it must include a [comment](./CONTRIBUTING.md#description-generation) describing the semantics when the value is `null`. It's common for properties with primitive types to allow `null`. `object` types allow `null` if no properties are required and the presence of the property key is meaningful. +### Polymorphic types + +JSON schema's [schema composition](https://json-schema.org/understanding-json-schema/reference/combining) keywords (`allOf`, `anyOf`, `oneOf`) offer a tempting mechanism for object-oriented style inheritance and polymorphic patterns. However, JSON schema code generation tools may struggle or not support these keywords. Therefore, these keywords should be used judiciously, and should not be used to extend `object` types. + +For example: + +```json +{ + "Shape": { + "title": "Shape", + "type": "object", + "properties": { + "sides": { "type": "integer"} + } + }, + "Square": { + "title": "Square", + "type": "object", + "allOf": [{"$ref": "#/$defs/Shape"}], + "properties": { + "side_length": {"type": "integer"} + } + } +} +``` + +`allOf` is used in the `Square` type to extend the parent `Shape` type, such that `Square` has properties `sides` and `side_length`. Avoid this type of use. + +Another example: + +```json +{ + "AttributeNameValue": { + "title": "AttributeNameValue", + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "value": { + "oneOf": [ + {"type": "string"}, + {"type": "number"}, + {"type": "boolean"}, + {"type": "null"}, + {"type": "array", "items": {"type": "string"}}, + {"type": "array", "items": {"type": "boolean"}}, + {"type": "array", "items": {"type": "number"}} + ] + }, + "type": { + "type": ["string", "null"], + "enum": [null, "string", "bool", "int", "double", "string_array", "bool_array", "int_array", "double_array"] + } + }, + "required": [ + "name", "value" + ] + } +} +``` + +`oneOf` is used to specify that the `value` property matches the [standard attribute](https://github.com/open-telemetry/opentelemetry-specification/tree/main/specification/common#standard-attribute) definition, and is either a primitive or array of primitives. This type of use is acceptable but should be used judiciously. + ## Contributing See [CONTRIBUTING.md](CONTRIBUTING.md) diff --git a/examples/kitchen-sink.yaml b/examples/kitchen-sink.yaml index 6a0c0e9..164290e 100644 --- a/examples/kitchen-sink.yaml +++ b/examples/kitchen-sink.yaml @@ -163,10 +163,9 @@ meter_provider: # If omitted, .included resource attributes are included. excluded: - "service.attr1" - # Configure metric producers. - producers: - - # Configure metric producer to be opencensus. - opencensus: + # Configure metric producers. + producers: + - opencensus: - # Configure a periodic metric reader. periodic: # Configure delay interval (in milliseconds) between start of two consecutive exports. diff --git a/schema/meter_provider.json b/schema/meter_provider.json index f63aa84..5dd33ad 100644 --- a/schema/meter_provider.json +++ b/schema/meter_provider.json @@ -44,6 +44,12 @@ }, "exporter": { "$ref": "#/$defs/PushMetricExporter" + }, + "producers": { + "type": "array", + "items": { + "$ref": "#/$defs/MetricProducer" + } } }, "required": [ @@ -57,6 +63,12 @@ "properties": { "exporter": { "$ref": "#/$defs/PullMetricExporter" + }, + "producers": { + "type": "array", + "items": { + "$ref": "#/$defs/MetricProducer" + } } }, "required": [ @@ -148,19 +160,13 @@ "type": "object", "additionalProperties": false, "minProperties": 1, - "maxProperties": 2, + "maxProperties": 1, "properties": { "periodic": { "$ref": "#/$defs/PeriodicMetricReader" }, "pull": { "$ref": "#/$defs/PullMetricReader" - }, - "producers": { - "type": "array", - "items": { - "$ref": "#/$defs/MetricProducer" - } } } }, diff --git a/schema/type_descriptions.yaml b/schema/type_descriptions.yaml index 9069b56..d37b247 100644 --- a/schema/type_descriptions.yaml +++ b/schema/type_descriptions.yaml @@ -330,13 +330,13 @@ property_descriptions: pull: Configure a pull based metric reader. periodic: Configure a periodic metric reader. - producers: Configure metric producers. path_patterns: - .meter_provider.readers[] - type: PullMetricReader property_descriptions: exporter: Configure exporter. + producers: Configure metric producers. path_patterns: - .meter_provider.readers[].pull @@ -351,6 +351,7 @@ If omitted or null, 30000 is used. exporter: Configure exporter. + producers: Configure metric producers. path_patterns: - .meter_provider.readers[].periodic @@ -359,7 +360,8 @@ opencensus: Configure metric producer to be opencensus. prometheus: Configure metric producer to be prometheus. path_patterns: - - .meter_provider.readers[].producers[] + - .meter_provider.readers[].producers[].pull + - .meter_provider.readers[].producers[].periodic - type: MetricExporter property_descriptions: