Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
SkyWalking
提交
e497efd2
S
SkyWalking
项目概览
apache
/
SkyWalking
上一次同步 1 年多
通知
302
Star
21345
Fork
6091
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SkyWalking
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
e497efd2
编写于
11月 01, 2022
作者:
Y
yswdqz
提交者:
GitHub
11月 01, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Change the way of loading MAL rules (#9822)
上级
e4c88c23
变更
26
隐藏空白更改
内联
并排
Showing
26 changed file
with
574 addition
and
48 deletion
+574
-48
apm-dist/src/main/assembly/binary.xml
apm-dist/src/main/assembly/binary.xml
+1
-1
docs/en/changes/changes.md
docs/en/changes/changes.md
+2
-0
docs/en/concepts-and-designs/lal.md
docs/en/concepts-and-designs/lal.md
+1
-1
docs/en/setup/backend/opentelemetry-receiver.md
docs/en/setup/backend/opentelemetry-receiver.md
+11
-11
oap-server/analyzer/log-analyzer/src/main/java/org/apache/skywalking/oap/log/analyzer/provider/LogAnalyzerModuleConfig.java
...ng/oap/log/analyzer/provider/LogAnalyzerModuleConfig.java
+7
-1
oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/prometheus/rule/Rules.java
.../skywalking/oap/meter/analyzer/prometheus/rule/Rules.java
+73
-28
oap-server/analyzer/meter-analyzer/src/test/java/org/apache/skywalking/oap/meter/analyzer/dsl/rule/RuleLoaderFailTest.java
...lking/oap/meter/analyzer/dsl/rule/RuleLoaderFailTest.java
+58
-0
oap-server/analyzer/meter-analyzer/src/test/java/org/apache/skywalking/oap/meter/analyzer/dsl/rule/RuleLoaderTest.java
...kywalking/oap/meter/analyzer/dsl/rule/RuleLoaderTest.java
+76
-0
oap-server/analyzer/meter-analyzer/src/test/java/org/apache/skywalking/oap/meter/analyzer/dsl/rule/RuleLoaderYAMLFailTest.java
...g/oap/meter/analyzer/dsl/rule/RuleLoaderYAMLFailTest.java
+54
-0
oap-server/analyzer/meter-analyzer/src/test/resources/otel-rules/illegal-yaml/test.yml
...lyzer/src/test/resources/otel-rules/illegal-yaml/test.yml
+31
-0
oap-server/analyzer/meter-analyzer/src/test/resources/otel-rules/single-file-case.yaml
...lyzer/src/test/resources/otel-rules/single-file-case.yaml
+40
-0
oap-server/analyzer/meter-analyzer/src/test/resources/otel-rules/test-folder/case1.yaml
...yzer/src/test/resources/otel-rules/test-folder/case1.yaml
+40
-0
oap-server/analyzer/meter-analyzer/src/test/resources/otel-rules/test-folder/case2.yml
...lyzer/src/test/resources/otel-rules/test-folder/case2.yml
+40
-0
oap-server/analyzer/meter-analyzer/src/test/resources/otel-rules/test-folder/case3.yaml
...yzer/src/test/resources/otel-rules/test-folder/case3.yaml
+40
-0
oap-server/analyzer/meter-analyzer/src/test/resources/otel-rules/test-folder/deeperFolder/caseUnReach.yaml
...rces/otel-rules/test-folder/deeperFolder/caseUnReach.yaml
+40
-0
oap-server/analyzer/meter-analyzer/src/test/resources/otel-rules/test-folder/empty.yaml
...yzer/src/test/resources/otel-rules/test-folder/empty.yaml
+30
-0
oap-server/server-library/library-util/src/main/java/org/apache/skywalking/oap/server/library/util/ResourceUtils.java
...che/skywalking/oap/server/library/util/ResourceUtils.java
+5
-0
oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/EnvoyMetricReceiverConfig.java
.../oap/server/receiver/envoy/EnvoyMetricReceiverConfig.java
+7
-1
oap-server/server-receiver-plugin/otel-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/otel/oc/OCMetricHandler.java
...ywalking/oap/server/receiver/otel/oc/OCMetricHandler.java
+9
-1
oap-server/server-receiver-plugin/otel-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/otel/otlp/OpenTelemetryMetricHandler.java
...server/receiver/otel/otlp/OpenTelemetryMetricHandler.java
+8
-1
oap-server/server-starter/src/main/resources/application.yml
oap-server/server-starter/src/main/resources/application.yml
+1
-1
oap-server/server-starter/src/main/resources/otel-rules/k8s/k8s-cluster.yaml
...tarter/src/main/resources/otel-rules/k8s/k8s-cluster.yaml
+0
-0
oap-server/server-starter/src/main/resources/otel-rules/k8s/k8s-instance.yaml
...arter/src/main/resources/otel-rules/k8s/k8s-instance.yaml
+0
-0
oap-server/server-starter/src/main/resources/otel-rules/k8s/k8s-node.yaml
...r-starter/src/main/resources/otel-rules/k8s/k8s-node.yaml
+0
-0
oap-server/server-starter/src/main/resources/otel-rules/k8s/k8s-service.yaml
...tarter/src/main/resources/otel-rules/k8s/k8s-service.yaml
+0
-0
test/e2e-v2/cases/mysql/mysql-slowsql/docker-compose.yaml
test/e2e-v2/cases/mysql/mysql-slowsql/docker-compose.yaml
+0
-2
未找到文件。
apm-dist/src/main/assembly/binary.xml
浏览文件 @
e497efd2
...
...
@@ -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>
...
...
docs/en/changes/changes.md
浏览文件 @
e497efd2
...
...
@@ -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`
.
...
...
docs/en/concepts-and-designs/lal.md
浏览文件 @
e497efd2
...
...
@@ -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:
...
...
docs/en/setup/backend/opentelemetry-receiver.md
浏览文件 @
e497efd2
...
...
@@ -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
)
.
oap-server/analyzer/log-analyzer/src/main/java/org/apache/skywalking/oap/log/analyzer/provider/LogAnalyzerModuleConfig.java
浏览文件 @
e497efd2
...
...
@@ -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
;
}
...
...
oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/prometheus/rule/Rules.java
浏览文件 @
e497efd2
...
...
@@ -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
ModuleStart
Exception
{
public
static
List
<
Rule
>
loadRules
(
final
String
path
)
throws
IO
Exception
{
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
);
}
}
}
oap-server/analyzer/meter-analyzer/src/test/java/org/apache/skywalking/oap/meter/analyzer/dsl/rule/RuleLoaderFailTest.java
0 → 100644
浏览文件 @
e497efd2
/*
* 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
);
}
}
oap-server/analyzer/meter-analyzer/src/test/java/org/apache/skywalking/oap/meter/analyzer/dsl/rule/RuleLoaderTest.java
0 → 100644
浏览文件 @
e497efd2
/*
* 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
));
}
}
oap-server/analyzer/meter-analyzer/src/test/java/org/apache/skywalking/oap/meter/analyzer/dsl/rule/RuleLoaderYAMLFailTest.java
0 → 100644
浏览文件 @
e497efd2
/*
* 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
);
}
}
oap-server/analyzer/meter-analyzer/src/test/resources/otel-rules/illegal-yaml/test.yml
0 → 100644
浏览文件 @
e497efd2
# 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
oap-server/analyzer/meter-analyzer/src/test/resources/otel-rules/single-file-case.yaml
0 → 100644
浏览文件 @
e497efd2
# 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
oap-server/analyzer/meter-analyzer/src/test/resources/otel-rules/test-folder/case1.yaml
0 → 100644
浏览文件 @
e497efd2
# 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
oap-server/analyzer/meter-analyzer/src/test/resources/otel-rules/test-folder/case2.yml
0 → 100644
浏览文件 @
e497efd2
# 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
oap-server/analyzer/meter-analyzer/src/test/resources/otel-rules/test-folder/case3.yaml
0 → 100644
浏览文件 @
e497efd2
# 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
oap-server/analyzer/meter-analyzer/src/test/resources/otel-rules/test-folder/deeperFolder/caseUnReach.yaml
0 → 100644
浏览文件 @
e497efd2
# 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
oap-server/analyzer/meter-analyzer/src/test/resources/otel-rules/test-folder/empty.yaml
0 → 100644
浏览文件 @
e497efd2
# 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>
oap-server/server-library/library-util/src/main/java/org/apache/skywalking/oap/server/library/util/ResourceUtils.java
浏览文件 @
e497efd2
...
...
@@ -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
();
}
}
oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/EnvoyMetricReceiverConfig.java
浏览文件 @
e497efd2
...
...
@@ -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
()
{
...
...
oap-server/server-receiver-plugin/otel-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/otel/oc/OCMetricHandler.java
浏览文件 @
e497efd2
...
...
@@ -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
;
}
...
...
oap-server/server-receiver-plugin/otel-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/otel/otlp/OpenTelemetryMetricHandler.java
浏览文件 @
e497efd2
...
...
@@ -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
;
...
...
oap-server/server-starter/src/main/resources/application.yml
浏览文件 @
e497efd2
...
...
@@ -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:-}
...
...
oap-server/server-starter/src/main/resources/otel-rules/k8s-cluster.yaml
→
oap-server/server-starter/src/main/resources/otel-rules/k8s
/k8s
-cluster.yaml
浏览文件 @
e497efd2
文件已移动
oap-server/server-starter/src/main/resources/otel-rules/k8s-instance.yaml
→
oap-server/server-starter/src/main/resources/otel-rules/k8s
/k8s
-instance.yaml
浏览文件 @
e497efd2
文件已移动
oap-server/server-starter/src/main/resources/otel-rules/k8s-node.yaml
→
oap-server/server-starter/src/main/resources/otel-rules/k8s
/k8s
-node.yaml
浏览文件 @
e497efd2
文件已移动
oap-server/server-starter/src/main/resources/otel-rules/k8s-service.yaml
→
oap-server/server-starter/src/main/resources/otel-rules/k8s
/k8s
-service.yaml
浏览文件 @
e497efd2
文件已移动
test/e2e-v2/cases/mysql/mysql-slowsql/docker-compose.yaml
浏览文件 @
e497efd2
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录