Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
SkyWalking
提交
cb16e524
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 搜索 >>
未验证
提交
cb16e524
编写于
3月 03, 2021
作者:
Z
Zhenxu Ke
提交者:
GitHub
3月 03, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Enhance the LAL to allow easily skipping logs with malformed formats (#6477)
上级
207cef79
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
107 addition
and
30 deletion
+107
-30
docs/en/concepts-and-designs/lal.md
docs/en/concepts-and-designs/lal.md
+29
-13
oap-server/analyzer/log-analyzer/src/main/java/org/apache/skywalking/oap/log/analyzer/dsl/spec/filter/FilterSpec.java
...ywalking/oap/log/analyzer/dsl/spec/filter/FilterSpec.java
+22
-10
oap-server/analyzer/log-analyzer/src/main/java/org/apache/skywalking/oap/log/analyzer/dsl/spec/parser/AbstractParserSpec.java
.../oap/log/analyzer/dsl/spec/parser/AbstractParserSpec.java
+43
-0
oap-server/analyzer/log-analyzer/src/main/java/org/apache/skywalking/oap/log/analyzer/dsl/spec/parser/JsonParserSpec.java
...king/oap/log/analyzer/dsl/spec/parser/JsonParserSpec.java
+8
-3
oap-server/analyzer/log-analyzer/src/main/java/org/apache/skywalking/oap/log/analyzer/dsl/spec/parser/TextParserSpec.java
...king/oap/log/analyzer/dsl/spec/parser/TextParserSpec.java
+3
-2
oap-server/analyzer/log-analyzer/src/main/java/org/apache/skywalking/oap/log/analyzer/dsl/spec/parser/YamlParserSpec.java
...king/oap/log/analyzer/dsl/spec/parser/YamlParserSpec.java
+1
-2
test/e2e/e2e-test/docker/log/lal.yaml
test/e2e/e2e-test/docker/log/lal.yaml
+1
-0
未找到文件。
docs/en/concepts-and-designs/lal.md
浏览文件 @
cb16e524
...
@@ -34,13 +34,7 @@ filter {
...
@@ -34,13 +34,7 @@ filter {
if
(
log
.
service
==
"TestingService"
)
{
// Don't waste resources on TestingServices
if
(
log
.
service
==
"TestingService"
)
{
// Don't waste resources on TestingServices
abort
{}
// all remaining components won't be executed at all
abort
{}
// all remaining components won't be executed at all
}
}
text
{
// ... parsers, extractors, sinks
if
(!
regexp
(
"(?<timestamp>\\d{8}) (?<thread>\\w+) (?<level>\\w+) (?<traceId>\\w+) (?<msg>.+)"
))
{
// if the logs don't match this regexp, skip it
abort
{}
}
}
// ... extractors, sinks
}
}
```
```
...
@@ -55,15 +49,35 @@ types of parsers at the moment, namely `json`, `yaml`, and `text`.
...
@@ -55,15 +49,35 @@ types of parsers at the moment, namely `json`, `yaml`, and `text`.
When a piece of log is parsed, there is a corresponding property available, called
`parsed`
, injected by LAL.
When a piece of log is parsed, there is a corresponding property available, called
`parsed`
, injected by LAL.
Property
`parsed`
is typically a map, containing all the fields parsed from the raw logs, for example, if the parser
Property
`parsed`
is typically a map, containing all the fields parsed from the raw logs, for example, if the parser
is
`json`
/
`yaml`
,
`parsed`
is a map containing all the key-values in the
`json`
/
`yaml`
, if the parser is
`text`
is
`json`
/
`yaml`
,
`parsed`
is a map containing all the key-values in the
`json`
/
`yaml`
, if the parser is
`text`
,
`parsed`
is a map containing all the captured groups and their values (for
`regexp`
and
`grok`
). See examples below.
,
`parsed`
is a map containing all the captured groups and their values (for
`regexp`
and
`grok`
).
All parsers share the following options:
| Option | Type | Description | Default Value |
| ------ | ---- | ----------- | ------------- |
|
`abortOnFailure`
|
`boolean`
| Whether the filter chain should abort if the parser failed to parse / match the logs |
`true`
|
See examples below.
#### `json`
#### `json`
<!-- TODO: is structured in the reported (gRPC) `LogData`, not much to do -->
```
groovy
filter
{
json
{
abortOnFailure
true
// this is optional because it's default behaviour
}
}
```
#### `yaml`
#### `yaml`
<!-- TODO: is structured in the reported (gRPC) `LogData`, not much to do -->
```
groovy
filter
{
yaml
{
abortOnFailure
true
// this is optional because it's default behaviour
}
}
```
#### `text`
#### `text`
...
@@ -78,8 +92,9 @@ all the captured groups can be used later in the extractors or sinks.
...
@@ -78,8 +92,9 @@ all the captured groups can be used later in the extractors or sinks.
```
groovy
```
groovy
filter
{
filter
{
text
{
text
{
regexp
"(?<timestamp>\\d{8}) (?<thread>\\w+) (?<level>\\w+) (?<traceId>\\w+) (?<msg>.+)"
abortOnFailure
true
// this is optional because it's default behaviour
// this is just a demo pattern
// this is just a demo pattern
regexp
"(?<timestamp>\\d{8}) (?<thread>\\w+) (?<level>\\w+) (?<traceId>\\w+) (?<msg>.+)"
}
}
extractor
{
extractor
{
tag
level:
parsed
.
level
tag
level:
parsed
.
level
...
@@ -91,9 +106,10 @@ filter {
...
@@ -91,9 +106,10 @@ filter {
}
}
```
```
-
`grok`
-
`grok`
(TODO)
<!-- TODO: grok Java library has poor performance, need to benchmark it, the idea is basically the same with `regexp` above -->
Because grok Java library has performance issue, we need some investigations and benchmark on it. Contributions are
welcome.
### Extractor
### Extractor
...
...
oap-server/analyzer/log-analyzer/src/main/java/org/apache/skywalking/oap/log/analyzer/dsl/spec/filter/FilterSpec.java
浏览文件 @
cb16e524
...
@@ -98,11 +98,17 @@ public class FilterSpec extends AbstractSpec {
...
@@ -98,11 +98,17 @@ public class FilterSpec extends AbstractSpec {
cl
.
call
();
cl
.
call
();
final
LogData
.
Builder
logData
=
BINDING
.
get
().
log
();
final
LogData
.
Builder
logData
=
BINDING
.
get
().
log
();
final
Map
<
String
,
Object
>
parsed
=
jsonParser
.
create
().
fromJson
(
try
{
logData
.
getBody
().
getJson
().
getJson
(),
parsedType
final
Map
<
String
,
Object
>
parsed
=
jsonParser
.
create
().
fromJson
(
);
logData
.
getBody
().
getJson
().
getJson
(),
parsedType
);
BINDING
.
get
().
parsed
(
parsed
);
BINDING
.
get
().
parsed
(
parsed
);
}
catch
(
final
Exception
e
)
{
if
(
jsonParser
.
abortOnFailure
())
{
BINDING
.
get
().
abort
();
}
}
}
}
@SuppressWarnings
({
"unused"
,
"unchecked"
})
@SuppressWarnings
({
"unused"
,
"unchecked"
})
...
@@ -114,11 +120,17 @@ public class FilterSpec extends AbstractSpec {
...
@@ -114,11 +120,17 @@ public class FilterSpec extends AbstractSpec {
cl
.
call
();
cl
.
call
();
final
LogData
.
Builder
logData
=
BINDING
.
get
().
log
();
final
LogData
.
Builder
logData
=
BINDING
.
get
().
log
();
final
Map
<
String
,
Object
>
parsed
=
(
Map
<
String
,
Object
>)
yamlParser
.
create
().
load
(
try
{
logData
.
getBody
().
getYaml
().
getYaml
()
final
Map
<
String
,
Object
>
parsed
=
(
Map
<
String
,
Object
>)
yamlParser
.
create
().
load
(
);
logData
.
getBody
().
getYaml
().
getYaml
()
);
BINDING
.
get
().
parsed
(
parsed
);
BINDING
.
get
().
parsed
(
parsed
);
}
catch
(
final
Exception
e
)
{
if
(
yamlParser
.
abortOnFailure
())
{
BINDING
.
get
().
abort
();
}
}
}
}
@SuppressWarnings
(
"unused"
)
@SuppressWarnings
(
"unused"
)
...
...
oap-server/analyzer/log-analyzer/src/main/java/org/apache/skywalking/oap/log/analyzer/dsl/spec/parser/AbstractParserSpec.java
0 → 100644
浏览文件 @
cb16e524
/*
* 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.log.analyzer.dsl.spec.parser
;
import
lombok.Getter
;
import
lombok.Setter
;
import
lombok.experimental.Accessors
;
import
org.apache.skywalking.oap.log.analyzer.dsl.spec.AbstractSpec
;
import
org.apache.skywalking.oap.log.analyzer.provider.LogAnalyzerModuleConfig
;
import
org.apache.skywalking.oap.server.library.module.ModuleManager
;
@Accessors
(
fluent
=
true
)
public
class
AbstractParserSpec
extends
AbstractSpec
{
/**
* Whether the filter chain should abort when parsing the logs failed.
*
* Failing to parse the logs means either parsing throws exceptions or the logs not matching the desired patterns.
*/
@Getter
@Setter
private
boolean
abortOnFailure
=
true
;
public
AbstractParserSpec
(
final
ModuleManager
moduleManager
,
final
LogAnalyzerModuleConfig
moduleConfig
)
{
super
(
moduleManager
,
moduleConfig
);
}
}
oap-server/analyzer/log-analyzer/src/main/java/org/apache/skywalking/oap/log/analyzer/dsl/spec/parser/JsonParserSpec.java
浏览文件 @
cb16e524
...
@@ -20,21 +20,26 @@ package org.apache.skywalking.oap.log.analyzer.dsl.spec.parser;
...
@@ -20,21 +20,26 @@ package org.apache.skywalking.oap.log.analyzer.dsl.spec.parser;
import
com.google.gson.Gson
;
import
com.google.gson.Gson
;
import
com.google.gson.GsonBuilder
;
import
com.google.gson.GsonBuilder
;
import
org.apache.skywalking.oap.log.analyzer.dsl.spec.AbstractSpec
;
import
org.apache.skywalking.oap.log.analyzer.provider.LogAnalyzerModuleConfig
;
import
org.apache.skywalking.oap.log.analyzer.provider.LogAnalyzerModuleConfig
;
import
org.apache.skywalking.oap.server.library.module.ModuleManager
;
import
org.apache.skywalking.oap.server.library.module.ModuleManager
;
public
class
JsonParserSpec
extends
AbstractSpec
{
public
class
JsonParserSpec
extends
Abstract
Parser
Spec
{
private
final
GsonBuilder
gsonBuilder
;
private
final
GsonBuilder
gsonBuilder
;
private
final
Gson
gson
;
public
JsonParserSpec
(
final
ModuleManager
moduleManager
,
public
JsonParserSpec
(
final
ModuleManager
moduleManager
,
final
LogAnalyzerModuleConfig
moduleConfig
)
{
final
LogAnalyzerModuleConfig
moduleConfig
)
{
super
(
moduleManager
,
moduleConfig
);
super
(
moduleManager
,
moduleConfig
);
gsonBuilder
=
new
GsonBuilder
();
gsonBuilder
=
new
GsonBuilder
();
// We just create a gson instance in advance for now (for the sake of performance),
// when we want to provide some extra options, we'll move this into method "create" then.
gson
=
gsonBuilder
.
create
();
}
}
public
Gson
create
()
{
public
Gson
create
()
{
return
gson
Builder
.
create
()
;
return
gson
;
}
}
}
}
oap-server/analyzer/log-analyzer/src/main/java/org/apache/skywalking/oap/log/analyzer/dsl/spec/parser/TextParserSpec.java
浏览文件 @
cb16e524
...
@@ -21,11 +21,10 @@ package org.apache.skywalking.oap.log.analyzer.dsl.spec.parser;
...
@@ -21,11 +21,10 @@ package org.apache.skywalking.oap.log.analyzer.dsl.spec.parser;
import
java.util.regex.Matcher
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
java.util.regex.Pattern
;
import
org.apache.skywalking.apm.network.logging.v3.LogData
;
import
org.apache.skywalking.apm.network.logging.v3.LogData
;
import
org.apache.skywalking.oap.log.analyzer.dsl.spec.AbstractSpec
;
import
org.apache.skywalking.oap.log.analyzer.provider.LogAnalyzerModuleConfig
;
import
org.apache.skywalking.oap.log.analyzer.provider.LogAnalyzerModuleConfig
;
import
org.apache.skywalking.oap.server.library.module.ModuleManager
;
import
org.apache.skywalking.oap.server.library.module.ModuleManager
;
public
class
TextParserSpec
extends
AbstractSpec
{
public
class
TextParserSpec
extends
Abstract
Parser
Spec
{
public
TextParserSpec
(
final
ModuleManager
moduleManager
,
public
TextParserSpec
(
final
ModuleManager
moduleManager
,
final
LogAnalyzerModuleConfig
moduleConfig
)
{
final
LogAnalyzerModuleConfig
moduleConfig
)
{
super
(
moduleManager
,
moduleConfig
);
super
(
moduleManager
,
moduleConfig
);
...
@@ -45,6 +44,8 @@ public class TextParserSpec extends AbstractSpec {
...
@@ -45,6 +44,8 @@ public class TextParserSpec extends AbstractSpec {
final
boolean
matched
=
matcher
.
find
();
final
boolean
matched
=
matcher
.
find
();
if
(
matched
)
{
if
(
matched
)
{
BINDING
.
get
().
parsed
(
matcher
);
BINDING
.
get
().
parsed
(
matcher
);
}
else
if
(
abortOnFailure
())
{
BINDING
.
get
().
abort
();
}
}
return
matched
;
return
matched
;
}
}
...
...
oap-server/analyzer/log-analyzer/src/main/java/org/apache/skywalking/oap/log/analyzer/dsl/spec/parser/YamlParserSpec.java
浏览文件 @
cb16e524
...
@@ -18,7 +18,6 @@
...
@@ -18,7 +18,6 @@
package
org.apache.skywalking.oap.log.analyzer.dsl.spec.parser
;
package
org.apache.skywalking.oap.log.analyzer.dsl.spec.parser
;
import
org.apache.skywalking.oap.log.analyzer.dsl.spec.AbstractSpec
;
import
org.apache.skywalking.oap.log.analyzer.provider.LogAnalyzerModuleConfig
;
import
org.apache.skywalking.oap.log.analyzer.provider.LogAnalyzerModuleConfig
;
import
org.apache.skywalking.oap.server.library.module.ModuleManager
;
import
org.apache.skywalking.oap.server.library.module.ModuleManager
;
import
org.yaml.snakeyaml.DumperOptions
;
import
org.yaml.snakeyaml.DumperOptions
;
...
@@ -27,7 +26,7 @@ import org.yaml.snakeyaml.Yaml;
...
@@ -27,7 +26,7 @@ import org.yaml.snakeyaml.Yaml;
import
org.yaml.snakeyaml.constructor.SafeConstructor
;
import
org.yaml.snakeyaml.constructor.SafeConstructor
;
import
org.yaml.snakeyaml.representer.Representer
;
import
org.yaml.snakeyaml.representer.Representer
;
public
class
YamlParserSpec
extends
AbstractSpec
{
public
class
YamlParserSpec
extends
Abstract
Parser
Spec
{
private
final
LoaderOptions
loaderOptions
;
private
final
LoaderOptions
loaderOptions
;
public
YamlParserSpec
(
final
ModuleManager
moduleManager
,
public
YamlParserSpec
(
final
ModuleManager
moduleManager
,
...
...
test/e2e/e2e-test/docker/log/lal.yaml
浏览文件 @
cb16e524
...
@@ -18,6 +18,7 @@ rules:
...
@@ -18,6 +18,7 @@ rules:
dsl
:
|
dsl
:
|
filter {
filter {
text {
text {
abortOnFailure false // for test purpose, we want to persist all logs
regexp $/(?s)(?<timestamp>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}) \[TID:(?<tid>.+?)] \[(?<thread>.+?)] (?<level>\w{4,}) (?<logger>.{1,36}) (?<msg>.+)/$
regexp $/(?s)(?<timestamp>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}) \[TID:(?<tid>.+?)] \[(?<thread>.+?)] (?<level>\w{4,}) (?<logger>.{1,36}) (?<msg>.+)/$
}
}
extractor {
extractor {
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录