未验证 提交 e497efd2 编写于 作者: Y yswdqz 提交者: GitHub

Change the way of loading MAL rules (#9822)

上级 e4c88c23
......@@ -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>
......
......@@ -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`.
......
......@@ -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:
......
......@@ -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).
......@@ -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;
}
......
......@@ -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);
}
}
}
/*
* 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);
}
}
/*
* 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));
}
}
/*
* 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);
}
}
# 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>
This is a not well-formed yml file.
\ No newline at end of file
# 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
# 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
# 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
# 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
# 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
# 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>
......@@ -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();
}
}
......@@ -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() {
......
......@@ -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;
}
......
......@@ -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;
......
......@@ -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:-}
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册