{"record":{"id":"ba4fc90d9588d1c4","repo":"thanos-io/thanos","slug":"groupname-q-is-repeated-in-the-same-file","errorCode":null,"errorMessage":"groupname: %q is repeated in the same file","messagePattern":"groupname: %q is repeated in the same file","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/rules/manager.go","lineNumber":259,"sourceCode":"func (g configRuleAdapter) MarshalYAML() (any, error) {\n\treturn struct {\n\t\tRuleGroup map[string]any `yaml:\",inline\"`\n\t}{\n\t\tRuleGroup: g.nativeRuleGroup,\n\t}, nil\n}\n\n// TODO(bwplotka): Replace this with upstream implementation after https://github.com/prometheus/prometheus/issues/7128 is fixed.\nfunc (g configRuleAdapter) validate() (errs []error) {\n\tset := map[string]struct{}{}\n\tif g.group.Name == \"\" {\n\t\terrs = append(errs, errors.New(\"Groupname should not be empty\"))\n\t}\n\n\tif _, ok := set[g.group.Name]; ok {\n\t\terrs = append(\n\t\t\terrs,\n\t\t\tfmt.Errorf(\"groupname: %q is repeated in the same file\", g.group.Name),\n\t\t)\n\t}\n\n\tset[g.group.Name] = struct{}{}\n\n\tfor i, r := range g.group.Rules {\n\t\tfor _, node := range r.Validate(rulefmt.RuleNode{}, model.UTF8Validation) {\n\t\t\tvar ruleName string\n\t\t\tif r.Alert != \"\" {\n\t\t\t\truleName = r.Alert\n\t\t\t} else {\n\t\t\t\truleName = r.Record\n\t\t\t}\n\t\t\terrs = append(errs, &rulefmt.Error{\n\t\t\t\tGroup:    g.group.Name,\n\t\t\t\tRule:     i,\n\t\t\t\tRuleName: ruleName,\n\t\t\t\tErr:      node,","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/rules/manager.go#L241-L277","documentation":"validate also enforces that group names are not repeated within the same rule file. Because groups are addressed by name, duplicates would make rule references ambiguous, so the second occurrence produces this error.","triggerScenarios":"A single rules YAML file declares two groups with the identical name value; validate walks groups and detects the name already seen in its set.","commonSituations":"Merging rule files by concatenation without renaming groups; copy-pasting a group block and editing only its rules; templated generation reusing the same group name.","solutions":["Rename one of the duplicated groups so names are unique per file","Split duplicated groups into separate files if identical config is needed per tenant","Run promtool check rules to detect duplicates before deployment","Audit generated rule output for templating that collapses distinct names"],"exampleFix":"// before\ngroups:\n  - name: app-rules\n    rules: [...]\n  - name: app-rules\n    rules: [...]\n// after\ngroups:\n  - name: app-rules-alerts\n    rules: [...]\n  - name: app-rules-recording\n    rules: [...]","handlingStrategy":"validation","validationCode":"seen := map[string]int{}\nfor _, g := range cfg.Groups {\n    if prev, dup := seen[g.Name]; dup {\n        return fmt.Errorf(\"group %q duplicated at groups[%d] and groups[%d]\", g.Name, prev, idx)\n    }\n    seen[g.Name] = idx\n}","typeGuard":null,"tryCatchPattern":"if errs := group.validate(); len(errs) > 0 {\n    for _, e := range errs {\n        var dupErr *fmt.Errorf\n        if strings.Contains(e.Error(), \"is repeated\") {\n            // fail fast with file/line context\n        }\n    }\n}","preventionTips":["Enforce unique group names when concatenating rule files in CI","Give generated groups tenant/namespace-scoped names","Run promtool check rules as a pre-commit or pipeline gate"],"tags":["validation","duplicate","rules"],"backgroundTag":"duplicate-group-name","analyzedSha":"35b8b991177def87ed52dcf10f9b6d87f07282c8","analyzedAt":"2026-09-07T01:49:59.689Z","contentChangedAt":"2026-09-07T01:49:59.689Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}