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.
TypeScript apmapplication-monitoringdistributed-tracinggogood-first-issuejaegerloglogsmetricsmonitoringnextjsobservabilityopen-sourceopentelemetryprometheusreactreactjsself-hostedtracingtypescript
chore(metric-metadata): do not delete rows, keep inserting, pick latest
Nikhil Mantri42943f72b73d
diff --git a/pkg/query-service/app/clickhouseReader/reader.go b/pkg/query-service/app/clickhouseReader/reader.goindex 90efeb718f..d122f239f0 100644--- a/pkg/query-service/app/clickhouseReader/reader.go+++ b/pkg/query-service/app/clickhouseReader/reader.go@@ -6252,17 +6252,6 @@ LIMIT 40`, // added rand to get diff value every time we run this queryreturn fingerprints, nil}-func (r *ClickHouseReader) DeleteMetricsMetadata(ctx context.Context, orgID valuer.UUID, metricName string) *model.ApiError {- delQuery := fmt.Sprintf(`ALTER TABLE %s.%s DELETE WHERE metric_name = ?;`, signozMetricDBName, signozUpdatedMetricsMetadataLocalTable)- valueCtx := context.WithValue(ctx, "clickhouse_max_threads", constants.MetricsExplorerClickhouseThreads)- err := r.db.Exec(valueCtx, delQuery, metricName)- if err != nil {- return &model.ApiError{Typ: "ClickHouseError", Err: err}- }- r.cache.Delete(ctx, orgID, constants.UpdatedMetricsMetadataCachePrefix+metricName)- return nil-}-func (r *ClickHouseReader) UpdateMetricsMetadata(ctx context.Context, orgID valuer.UUID, req *model.UpdateMetricsMetadata) *model.ApiError {if req.MetricType == v3.MetricTypeHistogram {labels := []string{"le"}@@ -6292,10 +6281,7 @@ func (r *ClickHouseReader) UpdateMetricsMetadata(ctx context.Context, orgID valu}}- apiErr := r.DeleteMetricsMetadata(ctx, orgID, req.MetricName)- if apiErr != nil {- return apiErr- }+ // Insert new metadata (keeping history of all updates)insertQuery := fmt.Sprintf(`INSERT INTO %s.%s (metric_name, temporality, is_monotonic, type, description, unit, created_at)VALUES ( ?, ?, ?, ?, ?, ?, ?);`, signozMetricDBName, signozUpdatedMetricsMetadataTable)valueCtx := context.WithValue(ctx, "clickhouse_max_threads", constants.MetricsExplorerClickhouseThreads)@@ -6364,9 +6350,19 @@ func (r *ClickHouseReader) GetUpdatedMetricsMetadata(ctx context.Context, orgIDvar stillMissing []stringif len(missingMetrics) > 0 {metricList := "'" + strings.Join(missingMetrics, "', '") + "'"- query := fmt.Sprintf(`SELECT metric_name, type, description, temporality, is_monotonic, unit- FROM %s.%s- WHERE metric_name IN (%s);`, signozMetricDBName, signozUpdatedMetricsMetadataTable, metricList)+ query := fmt.Sprintf(`SELECT+ metric_name,+ argMax(type, created_at) AS type,+ argMax(description, created_at) AS description,+ argMax(temporality, created_at) AS temporality,+ argMax(is_monotonic, created_at) AS is_monotonic,+ argMax(unit, created_at) AS unit+ FROM %s.%s+ WHERE metric_name IN (%s)+ GROUP BY metric_name;`,+ signozMetricDBName,+ signozUpdatedMetricsMetadataTable,+ metricList)valueCtx := context.WithValue(ctx, "clickhouse_max_threads", constants.MetricsExplorerClickhouseThreads)rows, err := r.db.Query(valueCtx, query)diff --git a/pkg/query-service/interfaces/interface.go b/pkg/query-service/interfaces/interface.goindex 43d6624a98..749c24828b 100644--- a/pkg/query-service/interfaces/interface.go+++ b/pkg/query-service/interfaces/interface.go@@ -127,7 +127,6 @@ type Reader interface {GetInspectMetricsFingerprints(ctx context.Context, attributes []string, req *metrics_explorer.InspectMetricsRequest) ([]string, *model.ApiError)GetInspectMetrics(ctx context.Context, req *metrics_explorer.InspectMetricsRequest, fingerprints []string) (*metrics_explorer.InspectMetricsResponse, *model.ApiError)- DeleteMetricsMetadata(ctx context.Context, orgID valuer.UUID, metricName string) *model.ApiErrorUpdateMetricsMetadata(ctx context.Context, orgID valuer.UUID, req *model.UpdateMetricsMetadata) *model.ApiErrorGetUpdatedMetricsMetadata(ctx context.Context, orgID valuer.UUID, metricNames ...string) (map[string]*model.UpdateMetricsMetadata, *model.ApiError)