{"record":{"id":"cad2f9a9873e8b25","repo":"apache/skywalking","slug":"layer-has-already-set-rule","errorCode":null,"errorMessage":"Layer {} has already set {} rule.","messagePattern":"Layer (.+?) has already set (.+?) rule\\.","errorType":"exception","errorClass":"ModuleStartException","httpStatus":null,"severity":"critical","filePath":"oap-server/analyzer/log-analyzer/src/main/java/org/apache/skywalking/oap/log/analyzer/v2/provider/log/listener/LogFilterListener.java","lineNumber":258,"sourceCode":"         */\n        public void loadStaticRules() throws Exception {\n            final Map<Layer, Map<String, DSL>> initDsls = new HashMap<>();\n            final Map<String, DSL> initAutoDsls = new HashMap<>();\n            final List<LALConfig> configList = LALConfigs.load(analyzerConfig.getLalPath(), analyzerConfig.lalFiles())\n                                                         .stream()\n                                                         .flatMap(it -> it.getRules().stream())\n                                                         .collect(Collectors.toList());\n            for (final LALConfig c : configList) {\n                final CompiledLAL compiled = compile(c);\n                if (compiled.layer == null) {\n                    if (initAutoDsls.put(c.getName(), compiled.dsl) != null) {\n                        throw new ModuleStartException(\n                            \"Auto-layer rules have duplicate name: \" + c.getName());\n                    }\n                } else {\n                    final Map<String, DSL> layerDsls = initDsls.computeIfAbsent(compiled.layer, k -> new HashMap<>());\n                    if (layerDsls.put(c.getName(), compiled.dsl) != null) {\n                        throw new ModuleStartException(\n                            \"Layer \" + compiled.layer.name() + \" has already set \" + c.getName() + \" rule.\");\n                    }\n                }\n                // Publish per-rule debug holder into the dsl-debugging registry. sourceName, not\n                // sourcePath: both routes derive it through LALConfigs.stampSource, so a\n                // runtime-rule replace puts over the static binding without orphaning it.\n                LalStaticBindingHook.publish(c.getSourceName(), c.getName(), compiled.dsl.getExpression());\n            }\n            // Publish: readers from now on see the startup-complete registry.\n            this.dsls = initDsls;\n            this.autoDsls = initAutoDsls;\n        }\n\n        /**\n         * Compile a single LALConfig into a runnable {@link DSL}. Used by both the startup\n         * constructor and the runtime-rule hot-update path (LalFileApplier).\n         */\n        public CompiledLAL compile(final LALConfig c) throws ModuleStartException {","sourceCodeStart":240,"sourceCodeEnd":276,"githubUrl":"https://github.com/apache/skywalking/blob/102af09b4a56064e22050dded10e2c52e490d040/oap-server/analyzer/log-analyzer/src/main/java/org/apache/skywalking/oap/log/analyzer/v2/provider/log/listener/LogFilterListener.java#L240-L276","documentation":"Thrown during static rule load when two rules targeting the SAME Layer share the same name: per-layer DSL maps (initDsls keyed by Layer) reject the second registration of an identical name. This is the layer-scoped twin of the auto-layer duplicate-name error — the same name in two different layers is fine, but not twice within one layer.","triggerScenarios":"Two rules both declaring layer: MESH (or resolved to the same layer) with identical ruleName; copy-pasting an envoy-als style rule and keeping the name; a layerDefinitions inline entry plus an explicit layer: that resolve to the same Layer object.","commonSituations":"Extending a shipped per-layer rule file (envoy-als.yaml etc.) by duplicating an entry and editing only the body; merging contributed rule files for the same layer.","solutions":["Rename the duplicate rule within that layer","If the rules genuinely target different layers, verify both layer: declarations resolve to distinct Layer values","Delete the stale copy if the file was duplicated wholesale"],"exampleFix":"# before: two entries with layer: MESH named 'envoy-als'\n# after: rename the second\nruleName: envoy-als-custom","handlingStrategy":"validation","validationCode":"# Detect duplicate names within a layer:\n#   awk '/^layer:/{L=$2} /^ruleName:/{print L, $2}' lal/*.yaml | sort | uniq -d","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Namespacing convention: prefix rule names with the layer or source","When copying a shipped per-layer rule, rename immediately","Review duplicates per layer, not just globally"],"tags":["lal","log-analyzer","rules","duplicate","layer","startup"],"backgroundTag":null,"analyzedSha":"102af09b4a56064e22050dded10e2c52e490d040","analyzedAt":"2026-08-14T10:47:52.647Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}