{"record":{"id":"3493dad18538ed51","repo":"SigNoz/signoz","slug":"error-while-getting-ttl-ttl-type-should-be-metric","errorCode":null,"errorMessage":"error while getting ttl. ttl type should be metrics|traces, got %v","messagePattern":"error while getting ttl\\. ttl type should be metrics\\|traces, got (.+?)","errorType":"validation","errorClass":"model.ApiError","httpStatus":500,"severity":"warning","filePath":"pkg/query-service/app/clickhouseReader/reader.go","lineNumber":2207,"sourceCode":"\t\t}\n\t\tdbResp, apiErr := getLogsTTL()\n\t\tif apiErr != nil {\n\t\t\treturn nil, apiErr\n\t\t}\n\t\tttlQuery, apiErr := r.checkTTLStatusItem(ctx, orgID, tableNameArray[0])\n\t\tif apiErr != nil {\n\t\t\treturn nil, apiErr\n\t\t}\n\t\tttlQuery.TTL = ttlQuery.TTL / 3600 // convert to hours\n\t\tif ttlQuery.ColdStorageTTL != -1 {\n\t\t\tttlQuery.ColdStorageTTL = ttlQuery.ColdStorageTTL / 3600 // convert to hours\n\t\t}\n\n\t\tdelTTL, moveTTL := parseTTL(dbResp.EngineFull)\n\t\treturn &retentiontypes.GetTTLResponseItem{LogsTime: delTTL, LogsMoveTime: moveTTL, ExpectedLogsTime: ttlQuery.TTL, ExpectedLogsMoveTime: ttlQuery.ColdStorageTTL, Status: status}, nil\n\n\tdefault:\n\t\treturn nil, &model.ApiError{Typ: model.ErrorExec, Err: fmt.Errorf(\"error while getting ttl. ttl type should be metrics|traces, got %v\",\n\t\t\tttlParams.Type)}\n\t}\n\n}\n\nfunc (r *ClickHouseReader) ListErrors(ctx context.Context, queryParams *model.ListErrorsParams) (*[]model.Error, *model.ApiError) {\n\n\tctx = ctxtypes.NewContextWithCommentVals(ctx, map[string]string{\n\t\tinstrumentationtypes.TelemetrySignal:  telemetrytypes.SignalTraces.StringValue(),\n\t\tinstrumentationtypes.CodeNamespace:    \"clickhouse-reader\",\n\t\tinstrumentationtypes.CodeFunctionName: \"ListErrors\",\n\t})\n\tvar getErrorResponses []model.Error\n\n\tquery := \"SELECT any(exceptionMessage) as exceptionMessage, count() AS exceptionCount, min(timestamp) as firstSeen, max(timestamp) as lastSeen, groupID\"\n\tif len(queryParams.ServiceName) != 0 {\n\t\tquery = query + \", serviceName\"\n\t} else {","sourceCodeStart":2189,"sourceCodeEnd":2225,"githubUrl":"https://github.com/SigNoz/signoz/blob/5069bf80b08f1f00d7e014eccc09902f9871004f/pkg/query-service/app/clickhouseReader/reader.go#L2189-L2225","documentation":"Returned by GetTTL when ttlParams.Type is not one of the supported values (metrics, traces, logs handled in the switch). It is a request-validation error (model.ErrorExec) indicating an unrecognized ttl type reached the default branch.","triggerScenarios":"Calling the TTL endpoint with a type value outside the accepted set, e.g. type=logs on an older build that only handles metrics|traces, or a typo like type=metric.","commonSituations":"Version mismatch where the frontend/API caller sends 'logs' but the deployed query-service predates logs support; custom scripts passing arbitrary strings; parameter typos; case-sensitive value ('Metrics' vs 'metrics').","solutions":["Send a supported value: metrics or traces (and logs on versions that support it)","Upgrade SigNoz query-service if you need the logs TTL type and your build lacks it","Validate/normalize the type parameter before calling GetTTL (lowercase, whitelist)","If writing a wrapper API, reject unknown types early with a 400 instead of forwarding"],"exampleFix":"// before\nparams := retentiontypes.TTLQueryParams{Type: \"Metric\"} // -> error while getting ttl. ttl type should be metrics|traces, got Metric\n// after\nparams := retentiontypes.TTLQueryParams{Type: \"metrics\"} // ok","handlingStrategy":"validation","validationCode":"allowed := map[string]bool{\"metrics\": true, \"traces\": true, \"logs\": logsSupported}\nif !allowed[ttlParams.Type] { return fmt.Errorf(\"unsupported ttl type %q; use metrics|traces\", ttlParams.Type) }","typeGuard":"func isValidTTLType(t string, logsSupported bool) bool { if t==\"metrics\"||t==\"traces\" {return true}; return logsSupported && t==\"logs\" }","tryCatchPattern":"if apiErr, ok := err.(*model.ApiError); ok && strings.Contains(apiErr.Err.Error(), \"ttl type should be\") { return 400, apiErr.Err }","preventionTips":["Normalize type to lowercase before sending","Whitelist allowed values at the API gateway","Upgrade query-service when you need logs TTL support"],"tags":["validation","signoz","ttl","bad-request"],"backgroundTag":"invalid-enum-parameter","analyzedSha":"5069bf80b08f1f00d7e014eccc09902f9871004f","analyzedAt":"2026-08-28T06:22:12.824Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}