{"record":{"id":"816e22808baf6ce4","repo":"hibiken/asynq","slug":"failed-to-get-queue-names-w","errorCode":null,"errorMessage":"failed to get queue names: %w","messagePattern":"failed to get queue names: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"x/metrics/metrics.go","lineNumber":28,"sourceCode":")\n\n// Namespace used in fully-qualified metrics names.\nconst namespace = \"asynq\"\n\n// QueueMetricsCollector gathers queue metrics.\n// It implements prometheus.Collector interface.\n//\n// All metrics exported from this collector have prefix \"asynq\".\ntype QueueMetricsCollector struct {\n\tinspector *asynq.Inspector\n}\n\n// collectQueueInfo gathers QueueInfo of all queues.\n// Since this operation is expensive, it must be called once per collection.\nfunc (qmc *QueueMetricsCollector) collectQueueInfo() ([]*asynq.QueueInfo, error) {\n\tqnames, err := qmc.inspector.Queues()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get queue names: %w\", err)\n\t}\n\tinfos := make([]*asynq.QueueInfo, len(qnames))\n\tfor i, qname := range qnames {\n\t\tqinfo, err := qmc.inspector.GetQueueInfo(qname)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to get queue info: %w\", err)\n\t\t}\n\t\tinfos[i] = qinfo\n\t}\n\treturn infos, nil\n}\n\n// Descriptors used by QueueMetricsCollector\nvar (\n\ttasksQueuedDesc = prometheus.NewDesc(\n\t\tprometheus.BuildFQName(namespace, \"\", \"tasks_enqueued_total\"),\n\t\t\"Number of tasks enqueued; broken down by queue and state.\",\n\t\t[]string{\"queue\", \"state\"}, nil,","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/hibiken/asynq/blob/d135f1439bee74e989b7f9b41ecd542cc87f024a/x/metrics/metrics.go#L10-L46","documentation":"QueueMetricsCollector.collectQueueInfo calls Inspector.Queues() to list all queue names and wraps any underlying Redis/transport error with this message. Collect propagates it, failing the whole Prometheus scrape for this collector since queue info cannot be gathered.","triggerScenarios":"Prometheus scrape invokes Collect → collectQueueInfo; Inspector.Ques()/Queues() fails due to Redis connection failure, auth failure, closed connection, or the underlying client not initialized.","commonSituations":"Redis down or restarted when Prometheus scrapes; wrong REDIS address/password in the metrics exporter config; network partition between exporter and Redis; using an Inspector built with invalid RedisConnOpt.","solutions":["Check Redis connectivity from the exporter (redis-cli ping) and fix REDIS address/credentials.","Unwrap the %w-wrapped cause to identify the underlying error (connection refused, auth, timeout).","Make the Inspector's RedisConnOpt point to the correct, reachable Redis instance.","Add retry/backoff in the collector or handle per-scrape errors in Prometheus instrumentation."],"exampleFix":"// before\ninspector := asynq.NewInspector(asynq.RedisClientOpt{Addr: \"\"})\n// after\ninspector := asynq.NewInspector(asynq.RedisClientOpt{Addr: \"localhost:6379\", Password: os.Getenv(\"REDIS_PASSWORD\")})\nif _, err := inspector.Queues(); err != nil {\n    log.Fatalf(\"redis unreachable: %v\", err)\n}","handlingStrategy":"try-catch","validationCode":"insp := asynq.NewInspector(redisOpt)\nif _, err := insp.Queues(); err != nil {\n    log.Fatalf(\"redis unreachable for metrics: %v\", err)\n}","typeGuard":null,"tryCatchPattern":"if infos, err := qmc.collectQueueInfo(); err != nil {\n    log.Printf(\"metrics collection failed: %v\", err) // keep scrape alive\n    return prometheus.NoopCollector\n}","preventionTips":["Health-check Redis connectivity before registering the metrics collector.","Use connection retry/timeouts in RedisClientOpt.","Alert on Redis reachability separately so scrapes failing is a symptom, not the first signal.","Verify exporter REDIS address/password match the asynq server's."],"tags":["go","asynq","redis","metrics","prometheus"],"backgroundTag":"database-query-failed","analyzedSha":"d135f1439bee74e989b7f9b41ecd542cc87f024a","analyzedAt":"2026-09-07T19:02:34.660Z","contentChangedAt":"2026-09-07T19:02:34.660Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}