{"record":{"id":"ffb3db550367505b","repo":"crowdsecurity/crowdsec","slug":"empty-loki-host","errorCode":null,"errorMessage":"empty loki host","messagePattern":"empty loki host","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/acquisition/modules/loki/config.go","lineNumber":133,"sourceCode":"\nfunc (l *Source) ConfigureByDSN(_ context.Context, dsn string, labels map[string]string, logger *log.Entry, uuid string) error {\n\tl.logger = logger\n\tl.Config = Configuration{}\n\tl.Config.Mode = configuration.CAT_MODE\n\tl.Config.Labels = labels\n\tl.Config.UniqueId = uuid\n\n\tu, err := url.Parse(dsn)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"while parsing dsn '%s': %w\", dsn, err)\n\t}\n\n\tif u.Scheme != \"loki\" {\n\t\treturn fmt.Errorf(\"invalid DSN %s for loki source, must start with loki://\", dsn)\n\t}\n\n\tif u.Host == \"\" {\n\t\treturn errors.New(\"empty loki host\")\n\t}\n\n\tscheme := \"http\"\n\n\tparams := u.Query()\n\tif q := params.Get(\"ssl\"); q != \"\" {\n\t\tscheme = \"https\"\n\t}\n\n\tif q := params.Get(\"query\"); q != \"\" {\n\t\tl.Config.Query = q\n\t}\n\n\tif w := params.Get(\"wait_for_ready\"); w != \"\" {\n\t\tl.Config.WaitForReady, err = time.ParseDuration(w)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/acquisition/modules/loki/config.go#L115-L151","documentation":"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.","triggerScenarios":"A DSN like `loki://` or `loki://?query=...` (no host before the ? or path) passed to ConfigureByDSN.","commonSituations":"Generating DSNs from templates where the host variable is empty, truncating the URL, or forgetting the host when adding query params.","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"],"exampleFix":"// before\nloki://?query=%7Bjob%3D%22x%22%7D\n// after\nloki://localhost:3100/?query=%7Bjob%3D%22x%22%7D","handlingStrategy":"validation","validationCode":"u, err := url.Parse(dsn)\nif err != nil || u.Scheme != \"loki\" || u.Host == \"\" {\n    return fmt.Errorf(\"invalid loki DSN: %s\", dsn)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate DSN format before handing it to crowdsec","Include scheme://host:port always","Test DSNs with cscli or a dry run first"],"tags":["dsn","loki","config","url"],"backgroundTag":"invalid-url","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}