{"record":{"id":"98baed996186452e","repo":"vitessio/vitess","slug":"err-error-getdetectionanalysis-failure","errorCode":null,"errorMessage":"err.Error() (GetDetectionAnalysis failure)","messagePattern":"err\\.Error\\(\\) \\(GetDetectionAnalysis failure\\)","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"go/vt/vtorc/server/api.go","lineNumber":326,"sourceCode":"\t}\n\tif b, err := json.Marshal(topoproto.TabletAliasString(lij.InstanceAlias)); err == nil {\n\t\tm[\"InstanceAlias\"] = b\n\t}\n\treturn json.Marshal(m)\n}\n\n// detectionAnalysisAPIHandler is the handler for the detectionAnalysisAPI endpoint\nfunc detectionAnalysisAPIHandler(response http.ResponseWriter, request *http.Request) {\n\t// This api also supports filtering by shard and keyspace provided.\n\tshard := request.URL.Query().Get(\"shard\")\n\tkeyspace := request.URL.Query().Get(\"keyspace\")\n\tif shard != \"\" && keyspace == \"\" {\n\t\thttp.Error(response, shardWithoutKeyspaceFilteringErrorStr, http.StatusBadRequest)\n\t\treturn\n\t}\n\tanalysis, err := inst.GetDetectionAnalysis(keyspace, shard, &inst.DetectionAnalysisHints{})\n\tif err != nil {\n\t\thttp.Error(response, err.Error(), http.StatusInternalServerError)\n\t\treturn\n\t}\n\tvar processed []*LegacyDetectionAnalysisJSON\n\tfor _, a := range analysis {\n\t\tprocessed = append(processed, NewLegacyDetectionAnalysisJSON(a))\n\t}\n\treturnAsJSON(response, http.StatusOK, processed)\n}\n\n// healthAPIHandler is the handler for the healthAPI endpoint\nfunc healthAPIHandler(response http.ResponseWriter, request *http.Request) {\n\thealth, discoveredOnce := process.HealthTest()\n\tcode := http.StatusOK\n\t// If the process isn't healthy, or if the first discovery cycle hasn't completed, we return an internal server error.\n\tif !health.Healthy || !discoveredOnce {\n\t\tcode = http.StatusInternalServerError\n\t}\n\treturnAsJSON(response, code, health)","sourceCodeStart":308,"sourceCodeEnd":344,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtorc/server/api.go#L308-L344","documentation":"The /detection-analysis handler returns HTTP 500 with the raw error text when inst.GetDetectionAnalysis(keyspace, shard, hints) fails. This means the analysis computation itself (reading detection data from vtorc's internals) errored, distinct from the 400 parameter-validation error above it.","triggerScenarios":"GET /detection-analysis with valid (or empty) keyspace/shard filters while GetDetectionAnalysis returns an error — e.g. internal state unavailable or invalid keyspace/shard lookup failing.","commonSituations":"Querying a keyspace that vtorc is not monitoring; vtorc internal store not yet populated after startup; passing malformed shard specs that the analysis code cannot resolve.","solutions":["Check vtorc logs for the underlying GetDetectionAnalysis error","Verify the keyspace/shard values exist in the keyspace vtorc monitors","Wait for vtorc to complete startup/rediscovery, then retry the request"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if keyspace != \"\" {\n    // confirm the keyspace is known to vtorc before querying\n}","typeGuard":null,"tryCatchPattern":"resp, err := http.Get(vtorcURL + \"/detection-analysis?keyspace=\" + url.QueryEscape(keyspace))\nif resp != nil && resp.StatusCode == http.StatusInternalServerError {\n    // log body, retry after backoff\n}","preventionTips":["Use keyspaces vtorc actually monitors","Allow vtorc to finish startup before querying analysis endpoints","Log the 500 body for the underlying cause"],"tags":["http-api","vtorc","internal-error"],"backgroundTag":"http-500-handler-error","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}