crowdsecurity/crowdsec · error
empty loki host
Error message
empty loki host
What it means
DSN validation in loki ConfigureByDSN: the loki:// DSN parsed successfully but u.Host is empty (e.g. 'loki:///' or 'loki:///query'). The host is the Loki server address, which is required to build the client URL; the scheme defaults to http if not overridden by query parameters.
Source
Thrown at pkg/acquisition/modules/loki/config.go:133
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 != "" {
l.Config.WaitForReady, err = time.ParseDuration(w)
if err != nil {
return err
}View on GitHub (pinned to 909b515798)
Solutions
- Include the Loki host in the DSN, e.g. loki://localhost:3100/
- Use loki://host:port?ssl=true for HTTPS endpoints
- Verify the variable holding the Loki address is not empty at DSN construction
Example fix
// before loki://?query=%7Bjob%3D%22x%22%7D // after loki://localhost:3100/?query=%7Bjob%3D%22x%22%7D
Defensive patterns
Strategy: validation
Validate before calling
u, err := url.Parse(dsn)
if err != nil || u.Scheme != "loki" || u.Host == "" {
return fmt.Errorf("invalid loki DSN: %s", dsn)
} Prevention
- Validate DSN format before handing it to crowdsec
- Include scheme://host:port always
- Test DSNs with cscli or a dry run first
When it happens
Trigger: A DSN like `loki://` or `loki://?query=...` (no host before the ? or path) passed to ConfigureByDSN.
Common situations: Generating DSNs from templates where the host variable is empty, truncating the URL, or forgetting the host when adding query params.
Understand the failure class
Background: "Invalid URL" / "URL cannot be empty": fix the malformed or missing URL behind request-construction failures — this error's family across 50 libraries.
Related errors
- failed to parse DSN %s: %w
- while parsing dsn '%s': %w
- invalid DSN %s for VictoriaLogs source, must start with vict
- query is mandatory (at least start_date and end_date or back
- cloudwatch path must contain group and stream : /my/group/na
AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06).
Data as JSON: /api/errors/ffb3db550367505b.
Report an issue: GitHub.