Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
月轩居士
SkyWalking
提交
5e8b6e92
S
SkyWalking
项目概览
月轩居士
/
SkyWalking
与 Fork 源项目一致
Fork自
apache / SkyWalking
通知
4
Star
0
Fork
0
代码
文件
提交
分支
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 搜索 >>
未验证
提交
5e8b6e92
编写于
11月 11, 2020
作者:
Z
Zhenxu Ke
提交者:
GitHub
11月 11, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix NPE and open some methods for extensibility (#5832)
上级
c66ae0b0
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
64 addition
and
46 deletion
+64
-46
oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/LogEntry2MetricsAdapter.java
...ap/server/receiver/envoy/als/LogEntry2MetricsAdapter.java
+8
-4
oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/k8s/K8SServiceRegistry.java
...oap/server/receiver/envoy/als/k8s/K8SServiceRegistry.java
+19
-19
oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/k8s/K8sALSServiceMeshHTTPAnalysis.java
...receiver/envoy/als/k8s/K8sALSServiceMeshHTTPAnalysis.java
+2
-1
oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/k8s/ServiceNameFormatter.java
...p/server/receiver/envoy/als/k8s/ServiceNameFormatter.java
+3
-3
oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/mx/FieldsHelper.java
...alking/oap/server/receiver/envoy/als/mx/FieldsHelper.java
+16
-13
oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/mx/MetaExchangeALSHTTPAnalyzer.java
...er/receiver/envoy/als/mx/MetaExchangeALSHTTPAnalyzer.java
+15
-5
oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/test/java/org/apache/skywalking/oap/server/receiver/envoy/als/mx/FieldsHelperTest.java
...ng/oap/server/receiver/envoy/als/mx/FieldsHelperTest.java
+1
-1
未找到文件。
oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/LogEntry2MetricsAdapter.java
浏览文件 @
5e8b6e92
...
...
@@ -51,11 +51,11 @@ public class LogEntry2MetricsAdapter {
/**
* The access log entry that is to be adapted into metrics builders.
*/
pr
ivate
final
HTTPAccessLogEntry
entry
;
pr
otected
final
HTTPAccessLogEntry
entry
;
pr
ivate
final
ServiceMetaInfo
sourceService
;
pr
otected
final
ServiceMetaInfo
sourceService
;
pr
ivate
final
ServiceMetaInfo
targetService
;
pr
otected
final
ServiceMetaInfo
targetService
;
/**
* Adapt the {@code entry} into a downstream metrics {@link ServiceMeshMetric.Builder}.
...
...
@@ -94,7 +94,7 @@ public class LogEntry2MetricsAdapter {
protected
ServiceMeshMetric
.
Builder
adaptCommonPart
()
{
final
AccessLogCommon
properties
=
entry
.
getCommonProperties
();
final
String
endpoint
=
ofNullable
(
entry
.
getRequest
()).
map
(
HTTPRequestProperties:
:
getPath
).
orElse
(
"/"
);
final
String
endpoint
=
endpoint
(
);
final
int
responseCode
=
ofNullable
(
entry
.
getResponse
()).
map
(
HTTPResponseProperties:
:
getResponseCode
).
map
(
UInt32Value:
:
getValue
).
orElse
(
200
);
final
boolean
status
=
responseCode
>=
200
&&
responseCode
<
400
;
final
Protocol
protocol
=
requestProtocol
(
entry
.
getRequest
());
...
...
@@ -124,6 +124,10 @@ public class LogEntry2MetricsAdapter {
return
builder
;
}
protected
String
endpoint
()
{
return
ofNullable
(
entry
.
getRequest
()).
map
(
HTTPRequestProperties:
:
getPath
).
orElse
(
"/"
);
}
protected
static
long
formatAsLong
(
final
Timestamp
timestamp
)
{
return
Instant
.
ofEpochSecond
(
timestamp
.
getSeconds
(),
timestamp
.
getNanos
()).
toEpochMilli
();
}
...
...
oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/k8s/K8SServiceRegistry.java
浏览文件 @
5e8b6e92
...
...
@@ -52,20 +52,20 @@ import static java.util.Objects.isNull;
import
static
java
.
util
.
Objects
.
requireNonNull
;
@Slf4j
class
K8SServiceRegistry
{
final
Map
<
String
/* ip */
,
ServiceMetaInfo
>
ipServiceMetaInfoMap
;
public
class
K8SServiceRegistry
{
protected
final
Map
<
String
/* ip */
,
ServiceMetaInfo
>
ipServiceMetaInfoMap
;
final
Map
<
String
/* namespace:serviceName */
,
V1Service
>
idServiceMap
;
protected
final
Map
<
String
/* namespace:serviceName */
,
V1Service
>
idServiceMap
;
final
Map
<
String
/* ip */
,
V1Pod
>
ipPodMap
;
protected
final
Map
<
String
/* ip */
,
V1Pod
>
ipPodMap
;
final
Map
<
String
/* ip */
,
String
/* namespace:serviceName */
>
ipServiceMap
;
protected
final
Map
<
String
/* ip */
,
String
/* namespace:serviceName */
>
ipServiceMap
;
final
ExecutorService
executor
;
protected
final
ExecutorService
executor
;
final
ServiceNameFormatter
serviceNameFormatter
;
protected
final
ServiceNameFormatter
serviceNameFormatter
;
K8SServiceRegistry
(
final
EnvoyMetricReceiverConfig
config
)
{
public
K8SServiceRegistry
(
final
EnvoyMetricReceiverConfig
config
)
{
serviceNameFormatter
=
new
ServiceNameFormatter
(
config
.
getK8sServiceNameRule
());
ipServiceMetaInfoMap
=
new
ConcurrentHashMap
<>();
idServiceMap
=
new
ConcurrentHashMap
<>();
...
...
@@ -79,7 +79,7 @@ class K8SServiceRegistry {
);
}
void
start
()
throws
IOException
{
public
void
start
()
throws
IOException
{
final
ApiClient
apiClient
=
Config
.
defaultClient
();
apiClient
.
setHttpClient
(
apiClient
.
getHttpClient
()
.
newBuilder
()
...
...
@@ -200,7 +200,7 @@ class K8SServiceRegistry {
});
}
pr
ivate
void
addService
(
final
V1Service
service
)
{
pr
otected
void
addService
(
final
V1Service
service
)
{
Optional
.
ofNullable
(
service
.
getMetadata
()).
ifPresent
(
metadata
->
idServiceMap
.
put
(
metadata
.
getNamespace
()
+
":"
+
metadata
.
getName
(),
service
)
);
...
...
@@ -208,13 +208,13 @@ class K8SServiceRegistry {
recompose
();
}
pr
ivate
void
removeService
(
final
V1Service
service
)
{
pr
otected
void
removeService
(
final
V1Service
service
)
{
Optional
.
ofNullable
(
service
.
getMetadata
()).
ifPresent
(
metadata
->
idServiceMap
.
remove
(
metadata
.
getUid
())
);
}
pr
ivate
void
addPod
(
final
V1Pod
pod
)
{
pr
otected
void
addPod
(
final
V1Pod
pod
)
{
Optional
.
ofNullable
(
pod
.
getStatus
()).
ifPresent
(
status
->
ipPodMap
.
put
(
status
.
getPodIP
(),
pod
)
);
...
...
@@ -222,13 +222,13 @@ class K8SServiceRegistry {
recompose
();
}
pr
ivate
void
removePod
(
final
V1Pod
pod
)
{
pr
otected
void
removePod
(
final
V1Pod
pod
)
{
Optional
.
ofNullable
(
pod
.
getStatus
()).
ifPresent
(
status
->
ipPodMap
.
remove
(
status
.
getPodIP
())
);
}
pr
ivate
void
addEndpoints
(
final
V1Endpoints
endpoints
)
{
pr
otected
void
addEndpoints
(
final
V1Endpoints
endpoints
)
{
final
String
namespace
=
requireNonNull
(
endpoints
.
getMetadata
()).
getNamespace
();
final
String
name
=
requireNonNull
(
endpoints
.
getMetadata
()).
getName
();
...
...
@@ -241,7 +241,7 @@ class K8SServiceRegistry {
recompose
();
}
pr
ivate
void
removeEndpoints
(
final
V1Endpoints
endpoints
)
{
pr
otected
void
removeEndpoints
(
final
V1Endpoints
endpoints
)
{
requireNonNull
(
endpoints
.
getSubsets
()).
forEach
(
subset
->
requireNonNull
(
subset
.
getAddresses
()).
forEach
(
address
->
ipServiceMap
.
remove
(
address
.
getIp
())
...
...
@@ -249,7 +249,7 @@ class K8SServiceRegistry {
);
}
pr
ivate
List
<
ServiceMetaInfo
.
KeyValue
>
transformLabelsToTags
(
final
Map
<
String
,
String
>
labels
)
{
pr
otected
List
<
ServiceMetaInfo
.
KeyValue
>
transformLabelsToTags
(
final
Map
<
String
,
String
>
labels
)
{
if
(
isNull
(
labels
))
{
return
Collections
.
emptyList
();
}
...
...
@@ -259,7 +259,7 @@ class K8SServiceRegistry {
.
collect
(
Collectors
.
toList
());
}
ServiceMetaInfo
findService
(
final
String
ip
)
{
protected
ServiceMetaInfo
findService
(
final
String
ip
)
{
final
ServiceMetaInfo
service
=
ipServiceMetaInfoMap
.
get
(
ip
);
if
(
isNull
(
service
))
{
log
.
debug
(
"Unknown ip {}, ip -> service is null"
,
ip
);
...
...
@@ -268,7 +268,7 @@ class K8SServiceRegistry {
return
service
;
}
pr
ivate
void
recompose
()
{
pr
otected
void
recompose
()
{
ipPodMap
.
forEach
((
ip
,
pod
)
->
{
final
String
namespaceService
=
ipServiceMap
.
get
(
ip
);
final
V1Service
service
;
...
...
@@ -297,7 +297,7 @@ class K8SServiceRegistry {
});
}
boolean
isEmpty
()
{
protected
boolean
isEmpty
()
{
return
ipServiceMetaInfoMap
.
isEmpty
();
}
}
oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/k8s/K8sALSServiceMeshHTTPAnalysis.java
浏览文件 @
5e8b6e92
...
...
@@ -127,7 +127,8 @@ public class K8sALSServiceMeshHTTPAnalysis extends AbstractALSAnalyzer {
return
Collections
.
emptyList
();
}
final
Address
downstreamLocalAddress
=
properties
.
getDownstreamLocalAddress
();
final
Address
downstreamRemoteAddress
=
properties
.
getDownstreamRemoteAddress
();
final
Address
downstreamRemoteAddress
=
properties
.
hasDownstreamDirectRemoteAddress
()
?
properties
.
getDownstreamDirectRemoteAddress
()
:
properties
.
getDownstreamRemoteAddress
();
final
Address
upstreamRemoteAddress
=
properties
.
getUpstreamRemoteAddress
();
if
(
downstreamLocalAddress
==
null
||
downstreamRemoteAddress
==
null
||
upstreamRemoteAddress
==
null
)
{
return
Collections
.
emptyList
();
...
...
oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/k8s/ServiceNameFormatter.java
浏览文件 @
5e8b6e92
...
...
@@ -27,13 +27,13 @@ import java.util.regex.Pattern;
import
org.apache.commons.beanutils.PropertyUtils
;
import
org.apache.commons.lang3.StringUtils
;
class
ServiceNameFormatter
{
public
class
ServiceNameFormatter
{
private
final
List
<
String
>
properties
;
private
final
StringBuffer
serviceNamePattern
;
ServiceNameFormatter
(
String
rule
)
{
public
ServiceNameFormatter
(
String
rule
)
{
rule
=
StringUtils
.
defaultIfBlank
(
rule
,
"${service.metadata.name}"
);
this
.
properties
=
new
ArrayList
<>();
...
...
@@ -48,7 +48,7 @@ class ServiceNameFormatter {
}
}
String
format
(
final
Map
<
String
,
Object
>
context
)
throws
Exception
{
public
String
format
(
final
Map
<
String
,
Object
>
context
)
throws
Exception
{
final
Object
[]
values
=
new
Object
[
properties
.
size
()];
for
(
int
i
=
0
;
i
<
properties
.
size
();
i
++)
{
...
...
oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/mx/FieldsHelper.java
浏览文件 @
5e8b6e92
...
...
@@ -20,8 +20,6 @@ package org.apache.skywalking.oap.server.receiver.envoy.als.mx;
import
com.google.common.base.Splitter
;
import
com.google.common.base.Strings
;
import
com.google.common.reflect.Invokable
;
import
com.google.common.reflect.TypeToken
;
import
com.google.protobuf.Struct
;
import
com.google.protobuf.Value
;
import
java.io.InputStream
;
...
...
@@ -41,8 +39,7 @@ import org.apache.skywalking.oap.server.receiver.envoy.als.ServiceMetaInfo;
import
org.yaml.snakeyaml.Yaml
;
@Slf4j
@SuppressWarnings
(
"UnstableApiUsage"
)
enum
FieldsHelper
{
public
enum
FieldsHelper
{
SINGLETON
;
private
boolean
initialized
=
false
;
...
...
@@ -55,17 +52,24 @@ enum FieldsHelper {
/**
* The mappings from the field name of {@link ServiceMetaInfo} to its {@code setter}.
*/
private
Map
<
String
,
Invokable
<
ServiceMetaInfo
,
?>
>
fieldSetterMapping
;
private
Map
<
String
,
Method
>
fieldSetterMapping
;
public
void
init
(
final
String
file
)
throws
Exception
{
init
(
ResourceUtils
.
readToStream
(
file
));
init
(
ResourceUtils
.
readToStream
(
file
),
ServiceMetaInfo
.
class
);
}
public
void
init
(
final
String
file
,
final
Class
<?
extends
ServiceMetaInfo
>
serviceInfoClass
)
throws
Exception
{
init
(
ResourceUtils
.
readToStream
(
file
),
serviceInfoClass
);
}
@SuppressWarnings
(
"unchecked"
)
void
init
(
final
InputStream
inputStream
)
throws
ModuleStartException
{
public
void
init
(
final
InputStream
inputStream
,
final
Class
<?
extends
ServiceMetaInfo
>
serviceInfoClass
)
throws
ModuleStartException
{
if
(
initialized
)
{
return
;
}
final
Yaml
yaml
=
new
Yaml
();
final
Map
<
String
,
String
>
config
=
(
Map
<
String
,
String
>)
yaml
.
load
(
inputStream
);
...
...
@@ -92,11 +96,9 @@ enum FieldsHelper {
);
try
{
final
Method
setterMethod
=
ServiceMetaInfo
.
class
.
getMethod
(
"set"
+
StringUtils
.
capitalize
(
serviceMetaInfoFieldName
),
String
.
class
);
final
Invokable
<
ServiceMetaInfo
,
?>
setter
=
new
TypeToken
<
ServiceMetaInfo
>()
{
}.
method
(
setterMethod
);
setter
.
setAccessible
(
true
);
fieldSetterMapping
.
put
(
serviceMetaInfoFieldName
,
setter
);
final
Method
setterMethod
=
serviceInfoClass
.
getMethod
(
"set"
+
StringUtils
.
capitalize
(
serviceMetaInfoFieldName
),
String
.
class
);
setterMethod
.
setAccessible
(
true
);
fieldSetterMapping
.
put
(
serviceMetaInfoFieldName
,
setterMethod
);
}
catch
(
final
NoSuchMethodException
e
)
{
throw
new
ModuleStartException
(
"Initialize method error"
,
e
);
}
...
...
@@ -112,6 +114,7 @@ enum FieldsHelper {
* @throws Exception if failed to inflate the {@code serviceMetaInfo}
*/
public
void
inflate
(
final
Struct
metadata
,
final
ServiceMetaInfo
serviceMetaInfo
)
throws
Exception
{
final
Value
empty
=
Value
.
newBuilder
().
setStringValue
(
"-"
).
build
();
final
Value
root
=
Value
.
newBuilder
().
setStructValue
(
metadata
).
build
();
for
(
final
Map
.
Entry
<
String
,
ServiceNameFormat
>
entry
:
fieldNameMapping
.
entrySet
())
{
final
ServiceNameFormat
serviceNameFormat
=
entry
.
getValue
();
...
...
@@ -120,7 +123,7 @@ enum FieldsHelper {
final
List
<
String
>
properties
=
serviceNameFormat
.
properties
.
get
(
i
);
Value
value
=
root
;
for
(
final
String
property
:
properties
)
{
value
=
value
.
getStructValue
().
getFieldsOr
Throw
(
proper
ty
);
value
=
value
.
getStructValue
().
getFieldsOr
Default
(
property
,
emp
ty
);
}
values
[
i
]
=
value
.
getStringValue
();
}
...
...
oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/mx/MetaExchangeALSHTTPAnalyzer.java
浏览文件 @
5e8b6e92
...
...
@@ -44,9 +44,11 @@ import static org.apache.skywalking.oap.server.receiver.envoy.als.ServiceMetaInf
@Slf4j
public
class
MetaExchangeALSHTTPAnalyzer
extends
AbstractALSAnalyzer
{
p
rivate
static
final
String
UPSTREAM_KEY
=
"wasm.upstream_peer"
;
p
ublic
static
final
String
UPSTREAM_KEY
=
"wasm.upstream_peer"
;
private
static
final
String
DOWNSTREAM_KEY
=
"wasm.downstream_peer"
;
public
static
final
String
DOWNSTREAM_KEY
=
"wasm.downstream_peer"
;
protected
String
fieldMappingFile
=
"metadata-service-mapping.yaml"
;
@Override
public
String
name
()
{
...
...
@@ -56,7 +58,7 @@ public class MetaExchangeALSHTTPAnalyzer extends AbstractALSAnalyzer {
@Override
public
void
init
(
ModuleManager
manager
,
EnvoyMetricReceiverConfig
config
)
throws
ModuleStartException
{
try
{
FieldsHelper
.
SINGLETON
.
init
(
"metadata-service-mapping.yaml"
);
FieldsHelper
.
SINGLETON
.
init
(
fieldMappingFile
);
}
catch
(
final
Exception
e
)
{
throw
new
ModuleStartException
(
"Failed to load metadata-service-mapping.yaml"
,
e
);
}
...
...
@@ -74,7 +76,7 @@ public class MetaExchangeALSHTTPAnalyzer extends AbstractALSAnalyzer {
}
final
ServiceMetaInfo
currSvc
;
try
{
currSvc
=
new
ServiceMetaInfoAdapter
(
identifier
.
getNode
().
getMetadata
()
);
currSvc
=
adaptToServiceMetaInfo
(
identifier
);
}
catch
(
Exception
e
)
{
log
.
error
(
"Failed to inflate the ServiceMetaInfo from identifier.node.metadata. "
,
e
);
return
Collections
.
emptyList
();
...
...
@@ -88,7 +90,7 @@ public class MetaExchangeALSHTTPAnalyzer extends AbstractALSAnalyzer {
}
final
ServiceMetaInfo
svc
;
try
{
svc
=
new
ServiceMetaInfoAdapter
(
value
);
svc
=
adaptToServiceMetaInfo
(
value
);
}
catch
(
Exception
e
)
{
log
.
error
(
"Fail to parse metadata {} to FlatNode"
,
Base64
.
getEncoder
().
encode
(
value
.
toByteArray
()));
return
;
...
...
@@ -122,4 +124,12 @@ public class MetaExchangeALSHTTPAnalyzer extends AbstractALSAnalyzer {
return
result
;
}
protected
ServiceMetaInfo
adaptToServiceMetaInfo
(
final
Any
value
)
throws
Exception
{
return
new
ServiceMetaInfoAdapter
(
value
);
}
protected
ServiceMetaInfo
adaptToServiceMetaInfo
(
final
StreamAccessLogsMessage
.
Identifier
identifier
)
throws
Exception
{
return
new
ServiceMetaInfoAdapter
(
identifier
.
getNode
().
getMetadata
());
}
}
oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/test/java/org/apache/skywalking/oap/server/receiver/envoy/als/mx/FieldsHelperTest.java
浏览文件 @
5e8b6e92
...
...
@@ -84,7 +84,7 @@ public class FieldsHelperTest {
final
StreamAccessLogsMessage
.
Builder
requestBuilder
=
StreamAccessLogsMessage
.
newBuilder
();
JsonFormat
.
parser
().
merge
(
isr
,
requestBuilder
);
final
ServiceMetaInfo
info
=
new
ServiceMetaInfo
();
FieldsHelper
.
SINGLETON
.
init
(
new
ByteArrayInputStream
(
mapping
.
getBytes
()));
FieldsHelper
.
SINGLETON
.
init
(
new
ByteArrayInputStream
(
mapping
.
getBytes
())
,
ServiceMetaInfo
.
class
);
FieldsHelper
.
SINGLETON
.
inflate
(
requestBuilder
.
getIdentifier
().
getNode
().
getMetadata
(),
info
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录