{"record":{"id":"5db4157145614e1e","repo":"crowdsecurity/crowdsec","slug":"loki-query-is-mandatory","errorCode":null,"errorMessage":"loki query is mandatory","messagePattern":"loki query is mandatory","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/acquisition/modules/loki/config.go","lineNumber":49,"sourceCode":"\tLimit                             int               `yaml:\"limit\"`  // Limit of logs to read\n\tDelayFor                          time.Duration     `yaml:\"delay_for\"`\n\tSince                             time.Duration     `yaml:\"since\"`\n\tHeaders                           map[string]string `yaml:\"headers\"`        // HTTP headers for talking to Loki\n\tWaitForReady                      time.Duration     `yaml:\"wait_for_ready\"` // Retry interval, default is 10 seconds\n\tAuth                              AuthConfiguration `yaml:\"auth\"`\n\tMaxFailureDuration                time.Duration     `yaml:\"max_failure_duration\"` // Max duration of failure before stopping the source\n\tNoReadyCheck                      bool              `yaml:\"no_ready_check\"`       // Bypass /ready check before starting\n\tconfiguration.DataSourceCommonCfg                   `yaml:\",inline\"`\n}\n\nfunc (l *Source) UnmarshalConfig(yamlConfig []byte) error {\n\terr := yaml.UnmarshalWithOptions(yamlConfig, &l.Config, yaml.Strict())\n\tif err != nil {\n\t\treturn fmt.Errorf(\"cannot parse loki acquisition configuration: %s\", yaml.FormatError(err, false, false))\n\t}\n\n\tif l.Config.Query == \"\" {\n\t\treturn errors.New(\"loki query is mandatory\")\n\t}\n\n\tif l.Config.WaitForReady == 0 {\n\t\tl.Config.WaitForReady = 10 * time.Second\n\t}\n\n\tif l.Config.DelayFor < 0*time.Second || l.Config.DelayFor > 5*time.Second {\n\t\treturn errors.New(\"delay_for should be a value between 1s and 5s\")\n\t}\n\n\tif l.Config.Mode == \"\" {\n\t\tl.Config.Mode = configuration.TAIL_MODE\n\t}\n\n\tif l.Config.Prefix == \"\" {\n\t\tl.Config.Prefix = \"/\"\n\t}\n","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/acquisition/modules/loki/config.go#L31-L67","documentation":"Validation in the loki datasource's UnmarshalConfig: no logql query is configured. The Loki source reads logs by executing a query, so without one there is nothing to fetch and configuration fails. The query selects the log stream (selectors and filters) that crowdsec will ingest.","triggerScenarios":"A loki.yaml acquisition config (or loki:// DSN path) parsed via UnmarshalConfig with an empty or missing `query:` field.","commonSituations":"Copying an example config and deleting the query, forgetting to fill the template placeholder, or quoting issues leaving the field empty.","solutions":["Add a `query: '{job=\"myapp\"}'` LogQL selector to the loki acquisition config","Verify the query key is spelled correctly and non-empty under the source's config block","Check strict-YAML parse didn't drop your value due to bad indentation"],"exampleFix":"// before\nsource: loki\nloki_url: http://localhost:3100\n// after\nsource: loki\nloki_url: http://localhost:3100\nquery: '{job=\"myapp\"}'","handlingStrategy":"validation","validationCode":"if strings.TrimSpace(cfg.Query) == \"\" {\n    return errors.New(\"loki query is required\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always include a LogQL query in loki source configs","Lint acquisition configs before deployment","Use config templates with required-field checks"],"tags":["config","loki","validation","acquisition"],"backgroundTag":"missing-required-config-field","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}