Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

chore: remove inline enum and implement jsonschema.Enum for metric types (#10238)

Srikanth Chekurib420ca494efd
diff --git a/docs/api/openapi.yml b/docs/api/openapi.yml
index cffafdf812..d80994a990 100644
--- a/docs/api/openapi.yml
+++ b/docs/api/openapi.yml
@@ -3928,19 +3928,9 @@ components:
isMonotonic:
type: boolean
temporality:
- enum:
- - delta
- - cumulative
- - unspecified
- type: string
+ $ref: '#/components/schemas/MetrictypesTemporality'
type:
- enum:
- - gauge
- - sum
- - histogram
- - summary
- - exponentialhistogram
- type: string
+ $ref: '#/components/schemas/MetrictypesType'
unit:
type: string
required:
@@ -3963,13 +3953,7 @@ components:
minimum: 0
type: integer
type:
- enum:
- - gauge
- - sum
- - histogram
- - summary
- - exponentialhistogram
- type: string
+ $ref: '#/components/schemas/MetrictypesType'
unit:
type: string
required:
@@ -4030,6 +4014,11 @@ components:
- percentage
- totalValue
type: object
+ MetricsexplorertypesTreemapMode:
+ enum:
+ - timeseries
+ - samples
+ type: string
MetricsexplorertypesTreemapRequest:
properties:
end:
@@ -4040,10 +4029,7 @@ components:
limit:
type: integer
mode:
- enum:
- - timeseries
- - samples
- type: string
+ $ref: '#/components/schemas/MetricsexplorertypesTreemapMode'
start:
format: int64
type: integer
@@ -4078,19 +4064,9 @@ components:
metricName:
type: string
temporality:
- enum:
- - delta
- - cumulative
- - unspecified
- type: string
+ $ref: '#/components/schemas/MetrictypesTemporality'
type:
- enum:
- - gauge
- - sum
- - histogram
- - summary
- - exponentialhistogram
- type: string
+ $ref: '#/components/schemas/MetrictypesType'
unit:
type: string
required:
@@ -4101,6 +4077,20 @@ components:
- temporality
- isMonotonic
type: object
+ MetrictypesTemporality:
+ enum:
+ - delta
+ - cumulative
+ - unspecified
+ type: string
+ MetrictypesType:
+ enum:
+ - gauge
+ - sum
+ - histogram
+ - summary
+ - exponentialhistogram
+ type: string
PreferencetypesPreference:
properties:
allowedScopes:
diff --git a/frontend/src/api/generated/services/sigNoz.schemas.ts b/frontend/src/api/generated/services/sigNoz.schemas.ts
index fdccdf156d..d5796b34f5 100644
--- a/frontend/src/api/generated/services/sigNoz.schemas.ts
+++ b/frontend/src/api/generated/services/sigNoz.schemas.ts
@@ -762,18 +762,6 @@ export interface MetricsexplorertypesMetricHighlightsResponseDTO {
totalTimeSeries: number;
}
-export enum MetricsexplorertypesMetricMetadataDTOTemporality {
- delta = 'delta',
- cumulative = 'cumulative',
- unspecified = 'unspecified',
-}
-export enum MetricsexplorertypesMetricMetadataDTOType {
- gauge = 'gauge',
- sum = 'sum',
- histogram = 'histogram',
- summary = 'summary',
- exponentialhistogram = 'exponentialhistogram',
-}
export interface MetricsexplorertypesMetricMetadataDTO {
/**
* @type string
@@ -783,29 +771,14 @@ export interface MetricsexplorertypesMetricMetadataDTO {
* @type boolean
*/
isMonotonic: boolean;
- /**
- * @enum delta,cumulative,unspecified
- * @type string
- */
- temporality: MetricsexplorertypesMetricMetadataDTOTemporality;
- /**
- * @enum gauge,sum,histogram,summary,exponentialhistogram
- * @type string
- */
- type: MetricsexplorertypesMetricMetadataDTOType;
+ temporality: MetrictypesTemporalityDTO;
+ type: MetrictypesTypeDTO;
/**
* @type string
*/
unit: string;
}
-export enum MetricsexplorertypesStatDTOType {
- gauge = 'gauge',
- sum = 'sum',
- histogram = 'histogram',
- summary = 'summary',
- exponentialhistogram = 'exponentialhistogram',
-}
export interface MetricsexplorertypesStatDTO {
/**
* @type string
@@ -825,11 +798,7 @@ export interface MetricsexplorertypesStatDTO {
* @minimum 0
*/
timeseries: number;
- /**
- * @enum gauge,sum,histogram,summary,exponentialhistogram
- * @type string
- */
- type: MetricsexplorertypesStatDTOType;
+ type: MetrictypesTypeDTO;
/**
* @type string
*/
@@ -889,7 +858,7 @@ export interface MetricsexplorertypesTreemapEntryDTO {
totalValue: number;
}
-export enum MetricsexplorertypesTreemapRequestDTOMode {
+export enum MetricsexplorertypesTreemapModeDTO {
timeseries = 'timeseries',
samples = 'samples',
}
@@ -904,11 +873,7 @@ export interface MetricsexplorertypesTreemapRequestDTO {
* @type integer
*/
limit: number;
- /**
- * @enum timeseries,samples
- * @type string
- */
- mode: MetricsexplorertypesTreemapRequestDTOMode;
+ mode: MetricsexplorertypesTreemapModeDTO;
/**
* @type integer
* @format int64
@@ -929,18 +894,6 @@ export interface MetricsexplorertypesTreemapResponseDTO {
timeseries: MetricsexplorertypesTreemapEntryDTO[] | null;
}
-export enum MetricsexplorertypesUpdateMetricMetadataRequestDTOTemporality {
- delta = 'delta',
- cumulative = 'cumulative',
- unspecified = 'unspecified',
-}
-export enum MetricsexplorertypesUpdateMetricMetadataRequestDTOType {
- gauge = 'gauge',
- sum = 'sum',
- histogram = 'histogram',
- summary = 'summary',
- exponentialhistogram = 'exponentialhistogram',
-}
export interface MetricsexplorertypesUpdateMetricMetadataRequestDTO {
/**
* @type string
@@ -954,22 +907,26 @@ export interface MetricsexplorertypesUpdateMetricMetadataRequestDTO {
* @type string
*/
metricName: string;
- /**
- * @enum delta,cumulative,unspecified
- * @type string
- */
- temporality: MetricsexplorertypesUpdateMetricMetadataRequestDTOTemporality;
- /**
- * @enum gauge,sum,histogram,summary,exponentialhistogram
- * @type string
- */
- type: MetricsexplorertypesUpdateMetricMetadataRequestDTOType;
+ temporality: MetrictypesTemporalityDTO;
+ type: MetrictypesTypeDTO;
/**
* @type string
*/
unit: string;
}
+export enum MetrictypesTemporalityDTO {
+ delta = 'delta',
+ cumulative = 'cumulative',
+ unspecified = 'unspecified',
+}
+export enum MetrictypesTypeDTO {
+ gauge = 'gauge',
+ sum = 'sum',
+ histogram = 'histogram',
+ summary = 'summary',
+ exponentialhistogram = 'exponentialhistogram',
+}
export interface PreferencetypesPreferenceDTO {
/**
* @type array
@@ -1388,7 +1345,7 @@ export interface TypesPostableForgotPasswordDTO {
/**
* @type string
*/
- email?: string;
+ email: string;
/**
* @type string
*/
@@ -1396,7 +1353,7 @@ export interface TypesPostableForgotPasswordDTO {
/**
* @type string
*/
- orgId?: string;
+ orgId: string;
}
export interface TypesPostableInviteDTO {
diff --git a/pkg/types/metricsexplorertypes/metricsexplorer.go b/pkg/types/metricsexplorertypes/metricsexplorer.go
index 85519cb3af..1439cae054 100644
--- a/pkg/types/metricsexplorertypes/metricsexplorer.go
+++ b/pkg/types/metricsexplorertypes/metricsexplorer.go
@@ -31,6 +31,13 @@ var (
TreemapModeSamples = TreemapMode{valuer.NewString("samples")}
)
+func (TreemapMode) Enum() []any {
+ return []any{
+ TreemapModeTimeSeries,
+ TreemapModeSamples,
+ }
+}
+
// StatsRequest represents the payload accepted by the metrics stats endpoint.
type StatsRequest struct {
Filter *qbtypes.Filter `json:"filter,omitempty"`
@@ -98,7 +105,7 @@ func (req *StatsRequest) UnmarshalJSON(data []byte) error {
type Stat struct {
MetricName string `json:"metricName" required:"true"`
Description string `json:"description" required:"true"`
- MetricType metrictypes.Type `json:"type" required:"true" enum:"gauge,sum,histogram,summary,exponentialhistogram"`
+ MetricType metrictypes.Type `json:"type" required:"true"`
MetricUnit string `json:"unit" required:"true"`
TimeSeries uint64 `json:"timeseries" required:"true"`
Samples uint64 `json:"samples" required:"true"`
@@ -112,9 +119,9 @@ type StatsResponse struct {
type MetricMetadata struct {
Description string `json:"description" required:"true"`
- MetricType metrictypes.Type `json:"type" required:"true" enum:"gauge,sum,histogram,summary,exponentialhistogram"`
+ MetricType metrictypes.Type `json:"type" required:"true"`
MetricUnit string `json:"unit" required:"true"`
- Temporality metrictypes.Temporality `json:"temporality" required:"true" enum:"delta,cumulative,unspecified"`
+ Temporality metrictypes.Temporality `json:"temporality" required:"true"`
IsMonotonic bool `json:"isMonotonic" required:"true"`
}
@@ -131,10 +138,10 @@ func (m *MetricMetadata) UnmarshalBinary(data []byte) error {
// UpdateMetricMetadataRequest represents the payload for updating metric metadata.
type UpdateMetricMetadataRequest struct {
MetricName string `json:"metricName" required:"true"`
- Type metrictypes.Type `json:"type" required:"true" enum:"gauge,sum,histogram,summary,exponentialhistogram"`
+ Type metrictypes.Type `json:"type" required:"true"`
Description string `json:"description" required:"true"`
Unit string `json:"unit" required:"true"`
- Temporality metrictypes.Temporality `json:"temporality" required:"true" enum:"delta,cumulative,unspecified"`
+ Temporality metrictypes.Temporality `json:"temporality" required:"true"`
IsMonotonic bool `json:"isMonotonic" required:"true"`
}
@@ -144,7 +151,7 @@ type TreemapRequest struct {
Start int64 `json:"start" required:"true"`
End int64 `json:"end" required:"true"`
Limit int `json:"limit" required:"true"`
- Mode TreemapMode `json:"mode" required:"true" enum:"timeseries,samples"`
+ Mode TreemapMode `json:"mode" required:"true"`
}
// Validate enforces basic constraints on TreemapRequest.
diff --git a/pkg/types/metrictypes/metrictypes.go b/pkg/types/metrictypes/metrictypes.go
index 9a65031b86..5bc3927875 100644
--- a/pkg/types/metrictypes/metrictypes.go
+++ b/pkg/types/metrictypes/metrictypes.go
@@ -36,7 +36,7 @@ func (t Temporality) Value() (driver.Value, error) {
}
}
-func (t *Temporality) Scan(src interface{}) error {
+func (t *Temporality) Scan(src any) error {
if src == nil {
*t = Unknown
return nil
@@ -66,6 +66,14 @@ func (t *Temporality) Scan(src interface{}) error {
return nil
}
+func (Temporality) Enum() []any {
+ return []any{
+ Delta,
+ Cumulative,
+ Unspecified,
+ }
+}
+
// Type is the type of the metric in OTLP data model
// Read more here https://opentelemetry.io/docs/specs/otel/metrics/data-model/#metric-points
type Type struct {
@@ -134,6 +142,16 @@ var (
UnspecifiedType = Type{valuer.NewString("")}
)
+func (Type) Enum() []any {
+ return []any{
+ GaugeType,
+ SumType,
+ HistogramType,
+ SummaryType,
+ ExpHistogramType,
+ }
+}
+
type TimeAggregation struct {
valuer.String
}
@@ -151,6 +169,21 @@ var (
TimeAggregationIncrease = TimeAggregation{valuer.NewString("increase")}
)
+func (TimeAggregation) Enum() []any {
+ return []any{
+ TimeAggregationUnspecified,
+ TimeAggregationLatest,
+ TimeAggregationSum,
+ TimeAggregationAvg,
+ TimeAggregationMin,
+ TimeAggregationMax,
+ TimeAggregationCount,
+ TimeAggregationCountDistinct,
+ TimeAggregationRate,
+ TimeAggregationIncrease,
+ }
+}
+
type SpaceAggregation struct {
valuer.String
}
@@ -169,6 +202,22 @@ var (
SpaceAggregationPercentile99 = SpaceAggregation{valuer.NewString("p99")}
)
+func (SpaceAggregation) Enum() []any {
+ return []any{
+ SpaceAggregationUnspecified,
+ SpaceAggregationSum,
+ SpaceAggregationAvg,
+ SpaceAggregationMin,
+ SpaceAggregationMax,
+ SpaceAggregationCount,
+ SpaceAggregationPercentile50,
+ SpaceAggregationPercentile75,
+ SpaceAggregationPercentile90,
+ SpaceAggregationPercentile95,
+ SpaceAggregationPercentile99,
+ }
+}
+
func (s SpaceAggregation) IsPercentile() bool {
return s == SpaceAggregationPercentile50 ||
s == SpaceAggregationPercentile75 ||