You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2022/11/01 07:11:16 UTC

[skywalking] branch master updated: Change the way of loading MAL rules (#9822)

This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking.git


The following commit(s) were added to refs/heads/master by this push:
     new e497efd245 Change the way of loading MAL rules (#9822)
e497efd245 is described below

commit e497efd2450930c8a572d19d9ead4bbd9e08902a
Author: yswdqz <74...@users.noreply.github.com>
AuthorDate: Tue Nov 1 15:11:04 2022 +0800

    Change the way of loading MAL rules (#9822)
---
 apm-dist/src/main/assembly/binary.xml              |   2 +-
 docs/en/changes/changes.md                         |   2 +
 docs/en/concepts-and-designs/lal.md                |   2 +-
 docs/en/setup/backend/opentelemetry-receiver.md    |  22 ++---
 .../analyzer/provider/LogAnalyzerModuleConfig.java |   8 +-
 .../oap/meter/analyzer/prometheus/rule/Rules.java  | 101 +++++++++++++++------
 .../analyzer/dsl/rule/RuleLoaderFailTest.java      |  58 ++++++++++++
 .../meter/analyzer/dsl/rule/RuleLoaderTest.java    |  76 ++++++++++++++++
 .../analyzer/dsl/rule/RuleLoaderYAMLFailTest.java  |  54 +++++++++++
 .../resources/otel-rules/illegal-yaml/test.yml}    |  24 +++--
 .../resources/otel-rules/single-file-case.yaml     |  40 ++++++++
 .../resources/otel-rules/test-folder/case1.yaml    |  40 ++++++++
 .../resources/otel-rules/test-folder/case2.yml     |  40 ++++++++
 .../resources/otel-rules/test-folder/case3.yaml    |  40 ++++++++
 .../test-folder/deeperFolder/caseUnReach.yaml      |  40 ++++++++
 .../resources/otel-rules/test-folder/empty.yaml}   |  23 +++--
 .../oap/server/library/util/ResourceUtils.java     |   5 +
 .../receiver/envoy/EnvoyMetricReceiverConfig.java  |   8 +-
 .../server/receiver/otel/oc/OCMetricHandler.java   |  10 +-
 .../otel/otlp/OpenTelemetryMetricHandler.java      |   9 +-
 .../src/main/resources/application.yml             |   2 +-
 .../otel-rules/{ => k8s}/k8s-cluster.yaml          |   0
 .../otel-rules/{ => k8s}/k8s-instance.yaml         |   0
 .../resources/otel-rules/{ => k8s}/k8s-node.yaml   |   0
 .../otel-rules/{ => k8s}/k8s-service.yaml          |   0
 .../cases/mysql/mysql-slowsql/docker-compose.yaml  |   2 -
 26 files changed, 544 insertions(+), 64 deletions(-)

diff --git a/apm-dist/src/main/assembly/binary.xml b/apm-dist/src/main/assembly/binary.xml
index 9f4cef1715..cef37bf39f 100644
--- a/apm-dist/src/main/assembly/binary.xml
+++ b/apm-dist/src/main/assembly/binary.xml
@@ -65,7 +65,7 @@
                 <include>meter-analyzer-config/*.yaml</include>
                 <include>zabbix-rules/*.yaml</include>
                 <include>openapi-definitions/*/*.yaml</include>
-                <include>otel-rules/*</include>
+                <include>otel-rules/**</include>
                 <include>ui-initialized-templates/*/*.json</include>
                 <include>lal/*</include>
                 <include>log-mal-rules/*</include>
diff --git a/docs/en/changes/changes.md b/docs/en/changes/changes.md
index fee12e16e2..43a88d53f3 100644
--- a/docs/en/changes/changes.md
+++ b/docs/en/changes/changes.md
@@ -71,6 +71,8 @@
 * Remove improper self-obs metrics in JvmMetricsHandler(for Kafka channel).
 * gRPC stream canceling code is not logged as an error when the client cancels the stream. The client
   cancels the stream when the pod is terminated.
+* [**Breaking Change**] Change the way of loading MAL rules(support pattern).
+* Move k8s relative MAL files into `/otel-rules/k8s`.
 * [**Breaking Change**] Refactor service mesh protobuf definitions and split TCP-related metrics to individual definition.
 * Add `TCP{Service,ServiceInstance,ServiceRelation,ServiceInstanceRelation}` sources and split TCP-related entities out from
   original `Service,ServiceInstance,ServiceRelation,ServiceInstanceRelation`.
diff --git a/docs/en/concepts-and-designs/lal.md b/docs/en/concepts-and-designs/lal.md
index 95017917f3..48e978abbe 100644
--- a/docs/en/concepts-and-designs/lal.md
+++ b/docs/en/concepts-and-designs/lal.md
@@ -223,7 +223,7 @@ log-analyzer:
   selector: ${SW_LOG_ANALYZER:default}
   default:
     lalFiles: ${SW_LOG_LAL_FILES:my-lal-config} # files are under "lal" directory
-    malFiles: ${SW_LOG_MAL_FILES:my-lal-mal-config,another-lal-mal-config} # files are under "log-mal-rules" directory
+    malFiles: ${SW_LOG_MAL_FILES:my-lal-mal-config, folder1/another-lal-mal-config, folder2/*} # files are under "log-mal-rules" directory
 ```
 
 Examples are as follows:
diff --git a/docs/en/setup/backend/opentelemetry-receiver.md b/docs/en/setup/backend/opentelemetry-receiver.md
index a68b4c05ed..255529907e 100644
--- a/docs/en/setup/backend/opentelemetry-receiver.md
+++ b/docs/en/setup/backend/opentelemetry-receiver.md
@@ -29,16 +29,16 @@ and its value is from `Node.identifier.host_name` defined in OpenCensus Agent Pr
 or `net.host.name` (or `host.name` for some OTLP versions) resource attributes defined in OpenTelemetry proto,
 for identification of the metric data.
 
-| Rule Name | Description | Configuration File | Data Source |
-|----|----|-----|----|
-|istio-controlplane| Metrics of Istio Control Plane | otel-rules/istio-controlplane.yaml | Istio Control Plane -> OpenTelemetry Collector -- OC/OTLP exporter --> SkyWalking OAP Server |
-|oap| Metrics of SkyWalking OAP server itself | otel-rules/oap.yaml | SkyWalking OAP Server(SelfObservability) -> OpenTelemetry Collector -- OC/OTLP exporter --> SkyWalking OAP Server |
-|vm| Metrics of VMs | otel-rules/vm.yaml | Prometheus node-exporter(VMs) -> OpenTelemetry Collector -- OC/OTLP exporter --> SkyWalking OAP Server |
-|k8s-cluster| Metrics of K8s cluster | otel-rules/k8s-cluster.yaml | K8s kube-state-metrics -> OpenTelemetry Collector -- OC/OTLP exporter --> SkyWalking OAP Server |
-|k8s-node| Metrics of K8s cluster | otel-rules/k8s-node.yaml | cAdvisor & K8s kube-state-metrics -> OpenTelemetry Collector -- OC/OTLP exporter --> SkyWalking OAP Server |
-|k8s-service| Metrics of K8s cluster | otel-rules/k8s-service.yaml | cAdvisor & K8s kube-state-metrics -> OpenTelemetry Collector -- OC/OTLP exporter --> SkyWalking OAP Server |
-|mysql| Metrics of MYSQL| otel-rules/mysql.yaml | prometheus/mysqld_exporter -> OpenTelemetry Collector -- OC/OTLP exporter --> SkyWalking OAP Server |
-|postgresql| Metrics of PostgreSQL| otel-rules/postgresql.yaml | postgres_exporter -> OpenTelemetry Collector -- OC/OTLP exporter --> SkyWalking OAP Server |
-|apisix| Metrics of Apache APISIX| otel-rules/apisix.yaml | apisix prometheus plugin -> OpenTelemetry Collector -- OC/OTLP exporter --> SkyWalking OAP Server |
+| Description | Configuration File | Data Source |
+|----|-----|----|
+| Metrics of Istio Control Plane | otel-rules/istio-controlplane.yaml | Istio Control Plane -> OpenTelemetry Collector -- OC/OTLP exporter --> SkyWalking OAP Server |
+| Metrics of SkyWalking OAP server itself | otel-rules/oap.yaml | SkyWalking OAP Server(SelfObservability) -> OpenTelemetry Collector -- OC/OTLP exporter --> SkyWalking OAP Server |
+| Metrics of VMs | otel-rules/vm.yaml | Prometheus node-exporter(VMs) -> OpenTelemetry Collector -- OC/OTLP exporter --> SkyWalking OAP Server |
+| Metrics of K8s cluster | otel-rules/k8s-cluster.yaml | K8s kube-state-metrics -> OpenTelemetry Collector -- OC/OTLP exporter --> SkyWalking OAP Server |
+| Metrics of K8s cluster | otel-rules/k8s-node.yaml | cAdvisor & K8s kube-state-metrics -> OpenTelemetry Collector -- OC/OTLP exporter --> SkyWalking OAP Server |
+| Metrics of K8s cluster | otel-rules/k8s-service.yaml | cAdvisor & K8s kube-state-metrics -> OpenTelemetry Collector -- OC/OTLP exporter --> SkyWalking OAP Server |
+| Metrics of MYSQL| otel-rules/mysql.yaml | prometheus/mysqld_exporter -> OpenTelemetry Collector -- OC/OTLP exporter --> SkyWalking OAP Server |
+| Metrics of PostgreSQL| otel-rules/postgresql.yaml | postgres_exporter -> OpenTelemetry Collector -- OC/OTLP exporter --> SkyWalking OAP Server |
+| Metrics of Apache APISIX| otel-rules/apisix.yaml | apisix prometheus plugin -> OpenTelemetry Collector -- OC/OTLP exporter --> SkyWalking OAP Server |
 
 **Note**: You can also use OpenTelemetry exporter to transport the metrics to SkyWalking OAP directly. See [OpenTelemetry Exporter](./backend-meter.md#opentelemetry-exporter).
diff --git a/oap-server/analyzer/log-analyzer/src/main/java/org/apache/skywalking/oap/log/analyzer/provider/LogAnalyzerModuleConfig.java b/oap-server/analyzer/log-analyzer/src/main/java/org/apache/skywalking/oap/log/analyzer/provider/LogAnalyzerModuleConfig.java
index 88456db0e6..de995c51b8 100644
--- a/oap-server/analyzer/log-analyzer/src/main/java/org/apache/skywalking/oap/log/analyzer/provider/LogAnalyzerModuleConfig.java
+++ b/oap-server/analyzer/log-analyzer/src/main/java/org/apache/skywalking/oap/log/analyzer/provider/LogAnalyzerModuleConfig.java
@@ -19,6 +19,8 @@ package org.apache.skywalking.oap.log.analyzer.provider;
 
 import com.google.common.base.Splitter;
 import com.google.common.base.Strings;
+
+import java.io.IOException;
 import java.util.List;
 import lombok.EqualsAndHashCode;
 import lombok.Getter;
@@ -61,7 +63,11 @@ public class LogAnalyzerModuleConfig extends ModuleConfig {
         final List<String> files = Splitter.on(",")
                                            .omitEmptyStrings()
                                            .splitToList(Strings.nullToEmpty(getMalFiles()));
-        meterConfigs = Rules.loadRules(getMalPath(), files);
+        try {
+            meterConfigs = Rules.loadRules(getMalPath(), files);
+        } catch (IOException e) {
+            throw new ModuleStartException("Failed to load MAL rules", e);
+        }
 
         return meterConfigs;
     }
diff --git a/oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/prometheus/rule/Rules.java b/oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/prometheus/rule/Rules.java
index 1f0dfafbb5..d9d8f3401b 100644
--- a/oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/prometheus/rule/Rules.java
+++ b/oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/prometheus/rule/Rules.java
@@ -19,17 +19,26 @@
 package org.apache.skywalking.oap.meter.analyzer.prometheus.rule;
 
 import java.io.File;
-import java.io.FileNotFoundException;
+
 import java.io.FileReader;
 import java.io.IOException;
 import java.io.Reader;
-import java.util.Arrays;
+
+import java.nio.file.FileSystems;
+import java.nio.file.Files;
+import java.nio.file.Path;
+
 import java.util.Collections;
 import java.util.List;
+import java.util.Map;
 import java.util.Objects;
 import java.util.stream.Collectors;
-import org.apache.skywalking.oap.server.library.module.ModuleStartException;
+
+import java.util.stream.Stream;
+
+import org.apache.skywalking.oap.server.core.UnexpectedException;
 import org.apache.skywalking.oap.server.library.util.ResourceUtils;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.yaml.snakeyaml.Yaml;
@@ -40,36 +49,72 @@ import org.yaml.snakeyaml.Yaml;
 public class Rules {
     private static final Logger LOG = LoggerFactory.getLogger(Rule.class);
 
-    public static List<Rule> loadRules(final String path) throws ModuleStartException {
+    public static List<Rule> loadRules(final String path) throws IOException {
         return loadRules(path, Collections.emptyList());
     }
 
-    public static List<Rule> loadRules(final String path, List<String> enabledRules) throws ModuleStartException {
-        File[] rules;
-        try {
-            rules = ResourceUtils.getPathFiles(path);
-        } catch (FileNotFoundException e) {
-            throw new ModuleStartException("Load fetcher rules failed", e);
-        }
-        return Arrays.stream(rules)
-            .filter(File::isFile)
-            .map(f -> {
-                try (Reader r = new FileReader(f)) {
-                    String fileName = f.getName();
-                    int dotIndex = fileName.lastIndexOf('.');
-                    fileName = (dotIndex == -1) ? fileName : fileName.substring(0, dotIndex);
-                    if (!enabledRules.contains(fileName)) {
-                        return null;
+    public static List<Rule> loadRules(final String path, List<String> enabledRules) throws IOException {
+
+        final Path root = ResourceUtils.getPath(path);
+
+        Map<String, Boolean> formedEnabledRules = enabledRules
+                .stream()
+                .map(rule -> {
+                    rule = rule.trim();
+                    if (rule.startsWith("/")) {
+                        rule = rule.substring(1);
+                    }
+                    if (!rule.endsWith(".yaml") && !rule.endsWith(".yml")) {
+                        return rule + "{.yaml,.yml}";
                     }
-                    Rule rule = new Yaml().loadAs(r, Rule.class);
-                    rule.setName(fileName);
                     return rule;
-                } catch (IOException e) {
-                    LOG.debug("Reading file {} failed", f, e);
-                }
+                })
+                .collect(Collectors.toMap(rule -> rule, $ -> false));
+        List<Rule> rules;
+        try (Stream<Path> stream = Files.walk(root)) {
+            rules = stream
+                    .filter(it -> formedEnabledRules.keySet().stream()
+                                    .anyMatch(rule -> {
+                                        boolean matches = FileSystems.getDefault().getPathMatcher("glob:" + rule)
+                                                .matches(root.relativize(it));
+                                        if (matches) {
+                                            formedEnabledRules.put(rule, true);
+                                        }
+                                        return matches;
+                                    }))
+                    .map(pathPointer -> {
+                        // Use relativized file path without suffix as the rule name.
+                        String relativizePath = root.relativize(pathPointer).toString();
+                        String ruleName = relativizePath.substring(0, relativizePath.lastIndexOf("."));
+                        return getRulesFromFile(ruleName, pathPointer);
+                    })
+                    .filter(Objects::nonNull)
+                    .collect(Collectors.toList()) ;
+        }
+
+        if (formedEnabledRules.containsValue(false)) {
+            List<String> rulesNotFound = formedEnabledRules.keySet().stream()
+                    .filter(rule -> !formedEnabledRules.get(rule))
+                    .collect(Collectors.toList());
+            throw new UnexpectedException("Some configuration files of enabled rules are not found, enabled rules: " + rulesNotFound);
+        }
+        return rules;
+    }
+
+    private static Rule getRulesFromFile(String ruleName, Path path) {
+        File file = path.toFile();
+        if (!file.isFile() || file.isHidden()) {
+            return null;
+        }
+        try (Reader r = new FileReader(file)) {
+            Rule rule = new Yaml().loadAs(r, Rule.class);
+            if (rule == null) {
                 return null;
-            })
-            .filter(Objects::nonNull)
-            .collect(Collectors.toList());
+            }
+            rule.setName(ruleName);
+            return rule;
+        } catch (IOException e) {
+            throw new UnexpectedException("Load rule file" + file.getName() + " failed", e);
+        }
     }
 }
diff --git a/oap-server/analyzer/meter-analyzer/src/test/java/org/apache/skywalking/oap/meter/analyzer/dsl/rule/RuleLoaderFailTest.java b/oap-server/analyzer/meter-analyzer/src/test/java/org/apache/skywalking/oap/meter/analyzer/dsl/rule/RuleLoaderFailTest.java
new file mode 100644
index 0000000000..dbd8580ab3
--- /dev/null
+++ b/oap-server/analyzer/meter-analyzer/src/test/java/org/apache/skywalking/oap/meter/analyzer/dsl/rule/RuleLoaderFailTest.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.skywalking.oap.meter.analyzer.dsl.rule;
+
+import lombok.extern.slf4j.Slf4j;
+
+import org.apache.skywalking.oap.meter.analyzer.prometheus.rule.Rules;
+
+import org.apache.skywalking.oap.server.core.UnexpectedException;
+import org.apache.skywalking.oap.server.library.module.ModuleStartException;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+@Slf4j
+@RunWith(Parameterized.class)
+public class RuleLoaderFailTest {
+    @Parameterized.Parameter
+    public List<String> enabledRule;
+
+    @Parameterized.Parameters(name = "{index}: {0}")
+    public static Collection<Object[]> data() {
+        return Arrays.asList(new Object[][] {
+            {Arrays.asList("not-exist-folder/*")},
+            {Arrays.asList("not-exist-folder/not-exist-file.yml")},
+            {Arrays.asList("not-exist-folder/not-exist-file.yaml")},
+            {Arrays.asList("not-exist-single-file.yaml")},
+            {Arrays.asList("test-folder/not-exist-file.yaml")},
+            {Arrays.asList("test-folder/case1.yaml", "not-exist-single-file.yaml")},
+        });
+    }
+
+    @Test(expected = UnexpectedException.class)
+    public void test() throws ModuleStartException, IOException {
+        Rules.loadRules("otel-rules", enabledRule);
+    }
+}
diff --git a/oap-server/analyzer/meter-analyzer/src/test/java/org/apache/skywalking/oap/meter/analyzer/dsl/rule/RuleLoaderTest.java b/oap-server/analyzer/meter-analyzer/src/test/java/org/apache/skywalking/oap/meter/analyzer/dsl/rule/RuleLoaderTest.java
new file mode 100644
index 0000000000..dcd78a0197
--- /dev/null
+++ b/oap-server/analyzer/meter-analyzer/src/test/java/org/apache/skywalking/oap/meter/analyzer/dsl/rule/RuleLoaderTest.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.skywalking.oap.meter.analyzer.dsl.rule;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.skywalking.oap.meter.analyzer.prometheus.rule.Rule;
+import org.apache.skywalking.oap.meter.analyzer.prometheus.rule.Rules;
+
+import org.apache.skywalking.oap.server.library.module.ModuleStartException;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+@Slf4j
+@RunWith(Parameterized.class)
+public class RuleLoaderTest {
+    @Parameterized.Parameter
+    public List<String> enabledRule;
+    @Parameterized.Parameter(1)
+    public int rulesNumber;
+
+    @Parameterized.Parameters(name = "{index}: {0}")
+    public static Collection<Object[]> data() {
+        return Arrays.asList(new Object[][] {
+                {Arrays.asList("test-folder/*.yml"), 1},
+                {Arrays.asList("test-folder/*.yaml"), 2},
+                {Arrays.asList("test-folder/*"), 3},
+                {Arrays.asList("/test-folder/*"), 3},
+
+                {Arrays.asList("test-folder/case1"), 1},
+                {Arrays.asList("/test-folder/case1.yaml"), 1},
+                {Arrays.asList("/test-folder/case2.yml"), 1},
+
+                {Arrays.asList("single-file-case.yaml"), 1},
+                {Arrays.asList("single-file-case"), 1},
+                {Arrays.asList("/single-file-case"), 1},
+
+                {Arrays.asList("/single-file-case.yaml", "test-folder/*"), 4},
+                {Arrays.asList("/single-file-case.yaml", "test-folder/*.yml"), 2},
+                {Arrays.asList("/single-file-case.yaml", "test-folder/case1", "/test-folder/case2"), 3},
+                // test leading and trailing whitespace
+                {Arrays.asList("   /single-file-case.yaml    "), 1},
+        });
+    }
+
+    @Test
+    public void test() throws ModuleStartException, IOException {
+        List<Rule> rules = Rules.loadRules("otel-rules", enabledRule);
+        assertThat(rules.size(), is(rulesNumber));
+    }
+
+}
diff --git a/oap-server/analyzer/meter-analyzer/src/test/java/org/apache/skywalking/oap/meter/analyzer/dsl/rule/RuleLoaderYAMLFailTest.java b/oap-server/analyzer/meter-analyzer/src/test/java/org/apache/skywalking/oap/meter/analyzer/dsl/rule/RuleLoaderYAMLFailTest.java
new file mode 100644
index 0000000000..c5acb26607
--- /dev/null
+++ b/oap-server/analyzer/meter-analyzer/src/test/java/org/apache/skywalking/oap/meter/analyzer/dsl/rule/RuleLoaderYAMLFailTest.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.skywalking.oap.meter.analyzer.dsl.rule;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.skywalking.oap.meter.analyzer.prometheus.rule.Rules;
+import org.apache.skywalking.oap.server.library.module.ModuleStartException;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.yaml.snakeyaml.error.YAMLException;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+@Slf4j
+@RunWith(Parameterized.class)
+public class RuleLoaderYAMLFailTest {
+    @Parameterized.Parameter
+    public List<String> enabledRule;
+
+    @Parameterized.Parameters(name = "{index}: {0}")
+    public static Collection<Object[]> data() {
+        return Arrays.asList(new Object[][] {
+                {Arrays.asList("illegal-yaml/test.yml")},
+                {Arrays.asList("illegal-yaml/test")},
+                {Arrays.asList("illegal-yaml/*.yml")},
+                {Arrays.asList("/illegal-yaml/*")},
+        });
+    }
+
+    @Test(expected = YAMLException.class)
+    public void test() throws ModuleStartException, IOException {
+        Rules.loadRules("otel-rules", enabledRule);
+    }
+}
diff --git a/oap-server/server-starter/src/main/resources/otel-rules/k8s-instance.yaml b/oap-server/analyzer/meter-analyzer/src/test/resources/otel-rules/illegal-yaml/test.yml
similarity index 50%
copy from oap-server/server-starter/src/main/resources/otel-rules/k8s-instance.yaml
copy to oap-server/analyzer/meter-analyzer/src/test/resources/otel-rules/illegal-yaml/test.yml
index 8d723fbd4b..725376d0c7 100644
--- a/oap-server/server-starter/src/main/resources/otel-rules/k8s-instance.yaml
+++ b/oap-server/analyzer/meter-analyzer/src/test/resources/otel-rules/illegal-yaml/test.yml
@@ -13,11 +13,19 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-filter: "{ tags -> tags.job_name in [ 'kubernetes-cadvisor', 'kube-state-metrics' ] }" # The OpenTelemetry job name
-expSuffix: |-
-  service(['cluster' , 'service'], '::', Layer.K8S_SERVICE)
-  .instance(['cluster', 'service'], '::', ['pod'], '', Layer.K8S_SERVICE, { tags -> ['pod': tags.pod, 'namespace': tags.namespace] })
-metricPrefix: k8s_service_instance
-metricsRules:
-  - name: pod_instance_status
-    exp: kube_pod_status_phase.retagByK8sMeta('service' , K8sRetagType.Pod2Service , 'pod' , 'namespace').tagNotEqual('service' , '').sum(['cluster', 'namespace', 'service' , 'pod'])
+# This will parse a textual representation of a duration. The formats
+# accepted are based on the ISO-8601 duration format {@code PnDTnHnMn.nS}
+# with days considered to be exactly 24 hours.
+# <p>
+# Examples:
+# <pre>
+#    "PT20.345S" -- parses as "20.345 seconds"
+#    "PT15M"     -- parses as "15 minutes" (where a minute is 60 seconds)
+#    "PT10H"     -- parses as "10 hours" (where an hour is 3600 seconds)
+#    "P2D"       -- parses as "2 days" (where a day is 24 hours or 86400 seconds)
+#    "P2DT3H4M"  -- parses as "2 days, 3 hours and 4 minutes"
+#    "P-6H3M"    -- parses as "-6 hours and +3 minutes"
+#    "-P6H3M"    -- parses as "-6 hours and -3 minutes"
+#    "-P-6H+3M"  -- parses as "+6 hours and -3 minutes"
+# </pre>
+This is a not well-formed yml file.
\ No newline at end of file
diff --git a/oap-server/analyzer/meter-analyzer/src/test/resources/otel-rules/single-file-case.yaml b/oap-server/analyzer/meter-analyzer/src/test/resources/otel-rules/single-file-case.yaml
new file mode 100644
index 0000000000..1697f01503
--- /dev/null
+++ b/oap-server/analyzer/meter-analyzer/src/test/resources/otel-rules/single-file-case.yaml
@@ -0,0 +1,40 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# This will parse a textual representation of a duration. The formats
+# accepted are based on the ISO-8601 duration format {@code PnDTnHnMn.nS}
+# with days considered to be exactly 24 hours.
+# <p>
+# Examples:
+# <pre>
+#    "PT20.345S" -- parses as "20.345 seconds"
+#    "PT15M"     -- parses as "15 minutes" (where a minute is 60 seconds)
+#    "PT10H"     -- parses as "10 hours" (where an hour is 3600 seconds)
+#    "P2D"       -- parses as "2 days" (where a day is 24 hours or 86400 seconds)
+#    "P2DT3H4M"  -- parses as "2 days, 3 hours and 4 minutes"
+#    "P-6H3M"    -- parses as "-6 hours and +3 minutes"
+#    "-P6H3M"    -- parses as "-6 hours and -3 minutes"
+#    "-P-6H+3M"  -- parses as "+6 hours and -3 minutes"
+# </pre>
+filter: ""
+expSuffix:
+metricPrefix:
+metricsRules:
+  - name: test1
+    exp: test_expression_1
+  - name: test2
+    exp: test_expression_2
+  - name: test3
+    exp: test_expression_3
diff --git a/oap-server/analyzer/meter-analyzer/src/test/resources/otel-rules/test-folder/case1.yaml b/oap-server/analyzer/meter-analyzer/src/test/resources/otel-rules/test-folder/case1.yaml
new file mode 100644
index 0000000000..1697f01503
--- /dev/null
+++ b/oap-server/analyzer/meter-analyzer/src/test/resources/otel-rules/test-folder/case1.yaml
@@ -0,0 +1,40 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# This will parse a textual representation of a duration. The formats
+# accepted are based on the ISO-8601 duration format {@code PnDTnHnMn.nS}
+# with days considered to be exactly 24 hours.
+# <p>
+# Examples:
+# <pre>
+#    "PT20.345S" -- parses as "20.345 seconds"
+#    "PT15M"     -- parses as "15 minutes" (where a minute is 60 seconds)
+#    "PT10H"     -- parses as "10 hours" (where an hour is 3600 seconds)
+#    "P2D"       -- parses as "2 days" (where a day is 24 hours or 86400 seconds)
+#    "P2DT3H4M"  -- parses as "2 days, 3 hours and 4 minutes"
+#    "P-6H3M"    -- parses as "-6 hours and +3 minutes"
+#    "-P6H3M"    -- parses as "-6 hours and -3 minutes"
+#    "-P-6H+3M"  -- parses as "+6 hours and -3 minutes"
+# </pre>
+filter: ""
+expSuffix:
+metricPrefix:
+metricsRules:
+  - name: test1
+    exp: test_expression_1
+  - name: test2
+    exp: test_expression_2
+  - name: test3
+    exp: test_expression_3
diff --git a/oap-server/analyzer/meter-analyzer/src/test/resources/otel-rules/test-folder/case2.yml b/oap-server/analyzer/meter-analyzer/src/test/resources/otel-rules/test-folder/case2.yml
new file mode 100644
index 0000000000..1697f01503
--- /dev/null
+++ b/oap-server/analyzer/meter-analyzer/src/test/resources/otel-rules/test-folder/case2.yml
@@ -0,0 +1,40 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# This will parse a textual representation of a duration. The formats
+# accepted are based on the ISO-8601 duration format {@code PnDTnHnMn.nS}
+# with days considered to be exactly 24 hours.
+# <p>
+# Examples:
+# <pre>
+#    "PT20.345S" -- parses as "20.345 seconds"
+#    "PT15M"     -- parses as "15 minutes" (where a minute is 60 seconds)
+#    "PT10H"     -- parses as "10 hours" (where an hour is 3600 seconds)
+#    "P2D"       -- parses as "2 days" (where a day is 24 hours or 86400 seconds)
+#    "P2DT3H4M"  -- parses as "2 days, 3 hours and 4 minutes"
+#    "P-6H3M"    -- parses as "-6 hours and +3 minutes"
+#    "-P6H3M"    -- parses as "-6 hours and -3 minutes"
+#    "-P-6H+3M"  -- parses as "+6 hours and -3 minutes"
+# </pre>
+filter: ""
+expSuffix:
+metricPrefix:
+metricsRules:
+  - name: test1
+    exp: test_expression_1
+  - name: test2
+    exp: test_expression_2
+  - name: test3
+    exp: test_expression_3
diff --git a/oap-server/analyzer/meter-analyzer/src/test/resources/otel-rules/test-folder/case3.yaml b/oap-server/analyzer/meter-analyzer/src/test/resources/otel-rules/test-folder/case3.yaml
new file mode 100644
index 0000000000..1697f01503
--- /dev/null
+++ b/oap-server/analyzer/meter-analyzer/src/test/resources/otel-rules/test-folder/case3.yaml
@@ -0,0 +1,40 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# This will parse a textual representation of a duration. The formats
+# accepted are based on the ISO-8601 duration format {@code PnDTnHnMn.nS}
+# with days considered to be exactly 24 hours.
+# <p>
+# Examples:
+# <pre>
+#    "PT20.345S" -- parses as "20.345 seconds"
+#    "PT15M"     -- parses as "15 minutes" (where a minute is 60 seconds)
+#    "PT10H"     -- parses as "10 hours" (where an hour is 3600 seconds)
+#    "P2D"       -- parses as "2 days" (where a day is 24 hours or 86400 seconds)
+#    "P2DT3H4M"  -- parses as "2 days, 3 hours and 4 minutes"
+#    "P-6H3M"    -- parses as "-6 hours and +3 minutes"
+#    "-P6H3M"    -- parses as "-6 hours and -3 minutes"
+#    "-P-6H+3M"  -- parses as "+6 hours and -3 minutes"
+# </pre>
+filter: ""
+expSuffix:
+metricPrefix:
+metricsRules:
+  - name: test1
+    exp: test_expression_1
+  - name: test2
+    exp: test_expression_2
+  - name: test3
+    exp: test_expression_3
diff --git a/oap-server/analyzer/meter-analyzer/src/test/resources/otel-rules/test-folder/deeperFolder/caseUnReach.yaml b/oap-server/analyzer/meter-analyzer/src/test/resources/otel-rules/test-folder/deeperFolder/caseUnReach.yaml
new file mode 100644
index 0000000000..174164ed02
--- /dev/null
+++ b/oap-server/analyzer/meter-analyzer/src/test/resources/otel-rules/test-folder/deeperFolder/caseUnReach.yaml
@@ -0,0 +1,40 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# This will parse a textual representation of a duration. The formats
+# accepted are based on the ISO-8601 duration format {@code PnDTnHnMn.nS}
+# with days considered to be exactly 24 hours.
+# <p>
+# Examples:
+# <pre>
+#    "PT20.345S" -- parses as "20.345 seconds"
+#    "PT15M"     -- parses as "15 minutes" (where a minute is 60 seconds)
+#    "PT10H"     -- parses as "10 hours" (where an hour is 3600 seconds)
+#    "P2D"       -- parses as "2 days" (where a day is 24 hours or 86400 seconds)
+#    "P2DT3H4M"  -- parses as "2 days, 3 hours and 4 minutes"
+#    "P-6H3M"    -- parses as "-6 hours and +3 minutes"
+#    "-P6H3M"    -- parses as "-6 hours and -3 minutes"
+#    "-P-6H+3M"  -- parses as "+6 hours and -3 minutes"
+# </pre>
+filter: ""
+expSuffix:
+metricPrefix:
+metricsRules:
+  - name: test1
+    exp: test_expression_1
+  - name: test2
+    exp: test_expression_2
+  - name: test3
+    exp: test_expression_3
\ No newline at end of file
diff --git a/oap-server/server-starter/src/main/resources/otel-rules/k8s-instance.yaml b/oap-server/analyzer/meter-analyzer/src/test/resources/otel-rules/test-folder/empty.yaml
similarity index 51%
copy from oap-server/server-starter/src/main/resources/otel-rules/k8s-instance.yaml
copy to oap-server/analyzer/meter-analyzer/src/test/resources/otel-rules/test-folder/empty.yaml
index 8d723fbd4b..e35fc0204c 100644
--- a/oap-server/server-starter/src/main/resources/otel-rules/k8s-instance.yaml
+++ b/oap-server/analyzer/meter-analyzer/src/test/resources/otel-rules/test-folder/empty.yaml
@@ -13,11 +13,18 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-filter: "{ tags -> tags.job_name in [ 'kubernetes-cadvisor', 'kube-state-metrics' ] }" # The OpenTelemetry job name
-expSuffix: |-
-  service(['cluster' , 'service'], '::', Layer.K8S_SERVICE)
-  .instance(['cluster', 'service'], '::', ['pod'], '', Layer.K8S_SERVICE, { tags -> ['pod': tags.pod, 'namespace': tags.namespace] })
-metricPrefix: k8s_service_instance
-metricsRules:
-  - name: pod_instance_status
-    exp: kube_pod_status_phase.retagByK8sMeta('service' , K8sRetagType.Pod2Service , 'pod' , 'namespace').tagNotEqual('service' , '').sum(['cluster', 'namespace', 'service' , 'pod'])
+# This will parse a textual representation of a duration. The formats
+# accepted are based on the ISO-8601 duration format {@code PnDTnHnMn.nS}
+# with days considered to be exactly 24 hours.
+# <p>
+# Examples:
+# <pre>
+#    "PT20.345S" -- parses as "20.345 seconds"
+#    "PT15M"     -- parses as "15 minutes" (where a minute is 60 seconds)
+#    "PT10H"     -- parses as "10 hours" (where an hour is 3600 seconds)
+#    "P2D"       -- parses as "2 days" (where a day is 24 hours or 86400 seconds)
+#    "P2DT3H4M"  -- parses as "2 days, 3 hours and 4 minutes"
+#    "P-6H3M"    -- parses as "-6 hours and +3 minutes"
+#    "-P6H3M"    -- parses as "-6 hours and -3 minutes"
+#    "-P-6H+3M"  -- parses as "+6 hours and -3 minutes"
+# </pre>
diff --git a/oap-server/server-library/library-util/src/main/java/org/apache/skywalking/oap/server/library/util/ResourceUtils.java b/oap-server/server-library/library-util/src/main/java/org/apache/skywalking/oap/server/library/util/ResourceUtils.java
index eeba7241d5..a825ba0d29 100644
--- a/oap-server/server-library/library-util/src/main/java/org/apache/skywalking/oap/server/library/util/ResourceUtils.java
+++ b/oap-server/server-library/library-util/src/main/java/org/apache/skywalking/oap/server/library/util/ResourceUtils.java
@@ -25,6 +25,7 @@ import java.io.InputStreamReader;
 import java.io.Reader;
 import java.net.URL;
 import java.nio.charset.StandardCharsets;
+import java.nio.file.Path;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -90,4 +91,8 @@ public class ResourceUtils {
         }
         return fileList;
     }
+
+    public static Path getPath(String path) {
+        return new File(Objects.requireNonNull(ResourceUtils.class.getClassLoader().getResource(path)).getPath()).toPath();
+    }
 }
diff --git a/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/EnvoyMetricReceiverConfig.java b/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/EnvoyMetricReceiverConfig.java
index c13220657a..ed64c46972 100644
--- a/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/EnvoyMetricReceiverConfig.java
+++ b/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/EnvoyMetricReceiverConfig.java
@@ -19,6 +19,8 @@
 package org.apache.skywalking.oap.server.receiver.envoy;
 
 import com.google.common.base.Strings;
+
+import java.io.IOException;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
@@ -57,7 +59,11 @@ public class EnvoyMetricReceiverConfig extends ModuleConfig {
     }
 
     public List<Rule> rules() throws ModuleStartException {
-        return Rules.loadRules("envoy-metrics-rules", Arrays.asList("envoy", "envoy-svc-relation"));
+        try {
+            return Rules.loadRules("envoy-metrics-rules", Arrays.asList("envoy", "envoy-svc-relation"));
+        } catch (IOException e) {
+            throw new ModuleStartException("Failed to load envoy-metrics-rules", e);
+        }
     }
 
     public ServiceMetaInfoFactory serviceMetaInfoFactory() {
diff --git a/oap-server/server-receiver-plugin/otel-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/otel/oc/OCMetricHandler.java b/oap-server/server-receiver-plugin/otel-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/otel/oc/OCMetricHandler.java
index f7fd29248a..d5d4ea19d6 100644
--- a/oap-server/server-receiver-plugin/otel-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/otel/oc/OCMetricHandler.java
+++ b/oap-server/server-receiver-plugin/otel-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/otel/oc/OCMetricHandler.java
@@ -33,10 +33,13 @@ import io.opencensus.proto.metrics.v1.SummaryValue;
 import io.opencensus.proto.resource.v1.Resource;
 import io.vavr.Function1;
 import io.vavr.Tuple;
+
+import java.io.IOException;
 import java.time.Instant;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+
 import org.apache.skywalking.oap.server.library.util.StringUtil;
 import org.apache.skywalking.oap.meter.analyzer.MetricConvert;
 import org.apache.skywalking.oap.meter.analyzer.prometheus.PrometheusMetricConverter;
@@ -181,7 +184,12 @@ public class OCMetricHandler extends MetricsServiceGrpc.MetricsServiceImplBase i
             Splitter.on(",")
                 .omitEmptyStrings()
                 .splitToList(config.getEnabledOtelRules());
-        final List<Rule> rules = Rules.loadRules("otel-rules", enabledRules);
+        final List<Rule> rules;
+        try {
+            rules = Rules.loadRules("otel-rules", enabledRules);
+        } catch (IOException e) {
+            throw new ModuleStartException("Failed to load otel rules.", e);
+        }
         if (rules.isEmpty()) {
             return;
         }
diff --git a/oap-server/server-receiver-plugin/otel-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/otel/otlp/OpenTelemetryMetricHandler.java b/oap-server/server-receiver-plugin/otel-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/otel/otlp/OpenTelemetryMetricHandler.java
index b602b9ad7b..fd18e6970b 100644
--- a/oap-server/server-receiver-plugin/otel-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/otel/otlp/OpenTelemetryMetricHandler.java
+++ b/oap-server/server-receiver-plugin/otel-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/otel/otlp/OpenTelemetryMetricHandler.java
@@ -21,6 +21,8 @@ package org.apache.skywalking.oap.server.receiver.otel.otlp;
 import static io.opentelemetry.proto.metrics.v1.AggregationTemporality.AGGREGATION_TEMPORALITY_CUMULATIVE;
 import static java.util.stream.Collectors.toList;
 import static java.util.stream.Collectors.toMap;
+
+import java.io.IOException;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -81,7 +83,12 @@ public class OpenTelemetryMetricHandler
             Splitter.on(",")
                 .omitEmptyStrings()
                 .splitToList(config.getEnabledOtelRules());
-        final List<Rule> rules = Rules.loadRules("otel-rules", enabledRules);
+        final List<Rule> rules;
+        try {
+            rules = Rules.loadRules("otel-rules", enabledRules);
+        } catch (IOException e) {
+            throw new ModuleStartException("Failed to load otel rules.", e);
+        }
 
         if (rules.isEmpty()) {
             return;
diff --git a/oap-server/server-starter/src/main/resources/application.yml b/oap-server/server-starter/src/main/resources/application.yml
index e2fa7942da..48afe0dea0 100644
--- a/oap-server/server-starter/src/main/resources/application.yml
+++ b/oap-server/server-starter/src/main/resources/application.yml
@@ -349,7 +349,7 @@ receiver-otel:
   selector: ${SW_OTEL_RECEIVER:default}
   default:
     enabledHandlers: ${SW_OTEL_RECEIVER_ENABLED_HANDLERS:"oc,otlp"}
-    enabledOtelRules: ${SW_OTEL_RECEIVER_ENABLED_OTEL_RULES:"istio-controlplane,k8s-node,oap,vm,mysql,postgresql,apisix"}
+    enabledOtelRules: ${SW_OTEL_RECEIVER_ENABLED_OTEL_RULES:"apisix,k8s/*,istio-controlplane,vm,mysql,postgresql,oap"}
 
 receiver-zipkin:
   selector: ${SW_RECEIVER_ZIPKIN:-}
diff --git a/oap-server/server-starter/src/main/resources/otel-rules/k8s-cluster.yaml b/oap-server/server-starter/src/main/resources/otel-rules/k8s/k8s-cluster.yaml
similarity index 100%
rename from oap-server/server-starter/src/main/resources/otel-rules/k8s-cluster.yaml
rename to oap-server/server-starter/src/main/resources/otel-rules/k8s/k8s-cluster.yaml
diff --git a/oap-server/server-starter/src/main/resources/otel-rules/k8s-instance.yaml b/oap-server/server-starter/src/main/resources/otel-rules/k8s/k8s-instance.yaml
similarity index 100%
rename from oap-server/server-starter/src/main/resources/otel-rules/k8s-instance.yaml
rename to oap-server/server-starter/src/main/resources/otel-rules/k8s/k8s-instance.yaml
diff --git a/oap-server/server-starter/src/main/resources/otel-rules/k8s-node.yaml b/oap-server/server-starter/src/main/resources/otel-rules/k8s/k8s-node.yaml
similarity index 100%
rename from oap-server/server-starter/src/main/resources/otel-rules/k8s-node.yaml
rename to oap-server/server-starter/src/main/resources/otel-rules/k8s/k8s-node.yaml
diff --git a/oap-server/server-starter/src/main/resources/otel-rules/k8s-service.yaml b/oap-server/server-starter/src/main/resources/otel-rules/k8s/k8s-service.yaml
similarity index 100%
rename from oap-server/server-starter/src/main/resources/otel-rules/k8s-service.yaml
rename to oap-server/server-starter/src/main/resources/otel-rules/k8s/k8s-service.yaml
diff --git a/test/e2e-v2/cases/mysql/mysql-slowsql/docker-compose.yaml b/test/e2e-v2/cases/mysql/mysql-slowsql/docker-compose.yaml
index 4e74ab82f9..c2263301ff 100644
--- a/test/e2e-v2/cases/mysql/mysql-slowsql/docker-compose.yaml
+++ b/test/e2e-v2/cases/mysql/mysql-slowsql/docker-compose.yaml
@@ -32,8 +32,6 @@ services:
       - SW_DATA_SOURCE_PASSWORD=password
       - SW_JDBC_URL=jdbc:mysql://mysql:3306/swtest
       - SW_CORE_TOPN_REPORT_PERIOD=2
-      - SW_OTEL_RECEIVER=default
-      - SW_OTEL_RECEIVER_ENABLED_OTEL_RULES=mysql
     depends_on:
       mysql:
         condition: service_healthy