{"record":{"id":"dd873892bc22b61b","repo":"grafana/k6","slug":"failed-to-derive-the-metrics-push-url-w","errorCode":null,"errorMessage":"failed to derive the metrics push URL: %w","messagePattern":"failed to derive the metrics push URL: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"output/cloud/expv2/output.go","lineNumber":136,"sourceCode":"\to.collector, err = newCollector(\n\t\to.config.AggregationPeriod.TimeDuration(),\n\t\to.config.AggregationWaitPeriod.TimeDuration())\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to initialize the samples collector: %w\", err)\n\t}\n\n\t// The metrics client always pushes to an explicit URL. In provisioning\n\t// mode both the HTTP client and URL are injected via the setters;\n\t// otherwise we derive the legacy /v2/metrics/<testRunID> URL from the\n\t// cloud client. The two must be set together — one without the other is\n\t// a misconfiguration rather than a silent fallback.\n\tswitch {\n\tcase o.metricsHTTPClient != nil && o.metricsURL != \"\":\n\t\t// Both injected (provisioning mode); use as-is.\n\tcase o.metricsHTTPClient == nil && o.metricsURL == \"\":\n\t\to.metricsURL, err = deriveMetricsURL(o.cloudClient.BaseURL(), o.testRunID)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to derive the metrics push URL: %w\", err)\n\t\t}\n\t\to.metricsHTTPClient = o.cloudClient\n\tdefault:\n\t\treturn errors.New(\"metrics push client misconfigured: \" +\n\t\t\t\"metricsHTTPClient and metricsURL must be set together\")\n\t}\n\n\tmc, err := newMetricsClientWithURL(o.metricsHTTPClient, o.metricsURL)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to initialize the http metrics flush client: %w\", err)\n\t}\n\to.flushing = &metricsFlusher{\n\t\ttestRunID:                  o.testRunID,\n\t\tbq:                         &o.collector.bq,\n\t\tclient:                     mc,\n\t\tlogger:                     o.logger,\n\t\tdiscardedLabels:            make(map[string]struct{}),\n\t\taggregationPeriodInSeconds: uint32(o.config.AggregationPeriod.TimeDuration().Seconds()),","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/output/cloud/expv2/output.go#L118-L154","documentation":"During Output.Start, deriveMetricsURL could not build the metrics push URL from the cloud client's base URL and the test run ID. This happens while wiring up the legacy /v2/metrics/<testRunID> endpoint when no explicit metrics client/URL was injected; the wrapped error explains the malformed base URL or run ID.","triggerScenarios":"Thrown at output/cloud/expv2/output.go:136 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify K6_CLOUD_HOST / cloud API base URL is a valid, complete URL","Ensure the cloud test run was created successfully and a test run ID exists","Check for typos in cloud-related environment variables"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}