crowdsecurity/crowdsec · error

invalid DSN %s for loki source, must start with loki://

Error message

invalid DSN %s for loki source, must start with loki://

What it means

ConfigureByDSN of the loki source requires the URL scheme to be 'loki'; a DSN with a different scheme (e.g. http:// or https:// given directly) is not accepted and must be rewritten as loki:// or loki+https://.

Source

Thrown at pkg/acquisition/modules/loki/config.go:129

	l.Client.Logger = logger.WithFields(log.Fields{"component": "lokiclient", "source": l.Config.URL})

	return nil
}

func (l *Source) ConfigureByDSN(_ context.Context, dsn string, labels map[string]string, logger *log.Entry, uuid string) error {
	l.logger = logger
	l.Config = Configuration{}
	l.Config.Mode = configuration.CAT_MODE
	l.Config.Labels = labels
	l.Config.UniqueId = uuid

	u, err := url.Parse(dsn)
	if err != nil {
		return fmt.Errorf("while parsing dsn '%s': %w", dsn, err)
	}

	if u.Scheme != "loki" {
		return fmt.Errorf("invalid DSN %s for loki source, must start with loki://", dsn)
	}

	if u.Host == "" {
		return errors.New("empty loki host")
	}

	scheme := "http"

	params := u.Query()
	if q := params.Get("ssl"); q != "" {
		scheme = "https"
	}

	if q := params.Get("query"); q != "" {
		l.Config.Query = q
	}

	if w := params.Get("wait_for_ready"); w != "" {

View on GitHub (pinned to 909b515798)

Solutions

  1. Prefix the DSN with loki:// in the acquisition config
  2. Ensure the DSN is assigned to the loki source, not another source type
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pkg/acquisition/modules/loki/config.go:129 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06). Data as JSON: /api/errors/2ea0bbedd33c7f5a. Report an issue: GitHub.