Files
signoz/pkg/types/metrictypes
Pandey 8c40d8c2ca fix(querybuildertypesv5): allow empty source, temporality and timeAggregation in the metric query spec (#12164)
* fix(querybuildertypesv5): omit unset metric enum fields on the wire

A metric builder query serialized empty strings for its enum fields
because omitempty has no effect on struct-backed valuer types:

  "source":"", "aggregations":[{"temporality":"","timeAggregation":"","spaceAggregation":""}]

Those "" values are not members of the corresponding OpenAPI enums
(source=[meter], temporality=[delta,cumulative,unspecified], etc.), so a
typed client reading a rule back rejected it (create -> GET round-trip
drift; terraform-provider-signoz generate-config failed schema validation).

Tag Source/Temporality/TimeAggregation/SpaceAggregation with ,omitzero so
an unset value is dropped instead of emitted as an invalid "", matching the
existing convention (dashboardtypes Sort, telemetrytypes field keys). Valid
values still serialize. The OpenAPI spec regenerates byte-identical, which
confirms the enums were already correct.

* test(querybuildertypesv5): cover client-sent empty enum values

A client (e.g. terraform) may send explicit source:"" / temporality:"" for
an unset enum. Assert unmarshaling accepts them, normalizes to the zero
value, and re-marshaling drops them so the round-trip never echoes an
invalid "" back.

* fix(querybuildertypesv5): allow empty metric enum values in the spec

The server accepts and echoes back an unset source, temporality, and
timeAggregation for a metric query (a create -> GET returns "" for them), but
their OpenAPI enums omitted "". A typed client (terraform-provider-signoz
generate-config) therefore rejected the config generated for an imported rule.

Add "" as a valid member of the Source, Temporality, and TimeAggregation enums
so the spec matches what the server actually accepts and returns. spaceAggregation
is left unchanged: an empty value is rejected with 400 at creation (IsValid), so
it is never stored or echoed and "" must stay out of its enum.

Drop the earlier ,omitzero tags: these fields already always-serialize, so an
accepted "" round-trips faithfully instead of being silently dropped (silent
mutation is itself drift). source loses its no-op omitempty for the same reason.

Regenerate the OpenAPI spec and frontend client (both git-diff gated).

* test(querybuildertypesv5): assert accepted empty enums round-trip

Empty source/temporality/timeAggregation are echoed back (not dropped) and are
stable across marshal -> unmarshal -> marshal; spaceAggregation carries a valid
value since an empty one is 400'd at creation.

* test(querybuildertypesv5): merge and rename metric enum round-trip test

Fold the unmarshal-echo case into the table-driven marshal round-trip test
(its marshal -> unmarshal -> marshal check already covers the client-sends-""
path) and rename to TestQueryBuilderQuery_MetricAggregation_MarshalJSONEnumRoundTrip.

* style(metrictypes): drop explanatory comments on enum changes

Remove the comments added to Temporality/TimeAggregation Enum() and the metric
enum round-trip test case.

* style(telemetrytypes): drop explanatory comment on Source enum change

Remove the comment added to Source.Enum(), keeping the pre-existing doc/TODO.
2026-07-19 19:52:51 +00:00
..