grafana/k6 · error

failed to get secret

Error message

failed to get secret: %w

What it means

Inside the retry loop of urlSecrets.Get, the HTTP request to the configured URL template (with {key} substituted) failed at the network level — DNS, connection, TLS, timeout. It is marked retryable, so this error is only returned to the caller if all retry attempts fail.

Solutions

  1. Verify the secret service URL is reachable from the k6 host
  2. Check TLS/proxy settings and network connectivity
  3. Tune maxRetries and retryBackoff if the service is flaky
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at internal/secretsource/url/url.go:189 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18). Data as JSON: /api/errors/027f8c7b7676bc34. Report an issue: GitHub.

Appendix: source

Thrown at internal/secretsource/url/url.go:189

	err := retry(ctx, maxAttempts, backoff, us.logger, func() (error, bool) {
		// Replace {key} placeholder in URL template
		url := strings.ReplaceAll(us.config.URLTemplate, "{key}", key)

		req, err := http.NewRequestWithContext(ctx, us.config.Method.String, url, nil)
		if err != nil {
			return fmt.Errorf("failed to create request: %w", err), true
		}

		// Add headers
		for k, v := range us.config.Headers {
			req.Header.Set(k, v)
		}

		response, err := us.httpClient.Do(req) //nolint:gosec
		if err != nil {
			// Network errors are retryable
			return fmt.Errorf("failed to get secret: %w", err), true
		}
		defer func() { _ = response.Body.Close() }()

		if response.StatusCode != http.StatusOK {
			statusErr := fmt.Errorf("status code %d: %w", response.StatusCode, errFailedToGetSecret)

			// Retry on server errors (5xx) and rate limiting (429)
			// Don't retry on client errors (4xx except 429)
			retryable := response.StatusCode >= 500 || response.StatusCode == http.StatusTooManyRequests
			return statusErr, retryable
		}

		// Extract secret value from response
		extractedSecret, err := extractSecretFromResponse(response.Body, us.config.ResponsePath.String)
		if err != nil {
			// Extraction errors are not retryable (indicates config issue)
			return fmt.Errorf("failed to extract secret: %w", err), false
		}

View on GitHub (pinned to 01ffac6f24)