未验证 提交 4474907f 编写于 作者: wu-sheng's avatar wu-sheng 提交者: GitHub

[Inventory Design Change] Remove endpoint register and endpoint inventory (#4570)

* Finish step one, source and entity changed.

* Step 2, finish the basic and core DAO changes.

* Step 3. Change all source codes of backend, and make project compiling successfully.

* Make startup successful and persistence works.

* Fix dead codes in the MySQLTableInstaller.

* Fix mischange.

* Fix MySQL storage bootstrap error.

* Rollback dependency change.

* Simply enable tailing logs from container no mater it's in CI or not

* Fix segment table issue.

* Fix MySQL Instanller.

* Support Influxdb implementation of new endpoint traffic.

* Set and modify timeout to 90mins

* Remove unnecessary entity in the EndpointTraffic.

* Fix wrong entity builder and make name more clear.

* Fix 2 equal methods bug.

* Fix InfluxDB identifier(name) conflict issue.

* Fix endpoint topology query, endpoint id should be changed as a string.

* Fix a missing change.

* Fix a wrong commit.

* Column name can't be changed, due to it affect the hybrid metadb(h2/mysql) query, change it explicitly with double quotation marks.

* Fix formats.

* Remove endpoint/operation register from the agent. and change the plugin tests(without local tests). operationId relation codes have been removed from agent too.

* Try to fix the hytrix case.

* Fix 3 cases.

* Try to fix cases.

* Fix 2.

* Fix one.

* Fix the serviceId type mis-change.

* Fix int query

* Fix hystrix case.

* Fix a case.

* Fix EndpointCallRelationDispatcher set the source/dest endpoint without id encoding.

* Update documentation and add 2 test cases.
Co-authored-by: Nkezhenxu94 <kezhenxu94@163.com>
上级 4eb3df40
......@@ -28,7 +28,7 @@ on:
jobs:
CI:
runs-on: ubuntu-18.04
timeout-minutes: 180
timeout-minutes: 90
strategy:
fail-fast: true
steps:
......@@ -52,7 +52,7 @@ jobs:
CI-on-Windows:
runs-on: Windows-latest
timeout-minutes: 180
timeout-minutes: 90
strategy:
fail-fast: true
steps:
......@@ -74,7 +74,7 @@ jobs:
CI-on-MacOS:
runs-on: macos-latest
timeout-minutes: 180
timeout-minutes: 90
strategy:
fail-fast: true
steps:
......
......@@ -24,6 +24,7 @@ env:
jobs:
build:
runs-on: ubuntu-16.04
timeout-minutes: 90
strategy:
matrix:
es: [es6, es7]
......
......@@ -30,6 +30,7 @@ env:
jobs:
CoordinatorsStorage:
name: Coordinators & Storage
timeout-minutes: 90
runs-on: ubuntu-latest
strategy:
matrix:
......@@ -59,6 +60,7 @@ jobs:
Cluster:
runs-on: ubuntu-latest
timeout-minutes: 90
needs: [CoordinatorsStorage]
steps:
- name: Call me by your name
......
......@@ -31,6 +31,7 @@ jobs:
JavaVersions:
name: Agent Java Versions
runs-on: ubuntu-latest
timeout-minutes: 90
strategy:
matrix:
jdk: [8, 9, 10, 11, 12, 13, 14]
......@@ -58,6 +59,7 @@ jobs:
Single:
runs-on: ubuntu-latest
timeout-minutes: 90
needs: [JavaVersions]
steps:
- name: Singles Bar
......
......@@ -32,6 +32,7 @@ jobs:
PHPAgent:
name: PHP
runs-on: ubuntu-latest
timeout-minutes: 90
steps:
- uses: actions/checkout@v2
- name: checkout submodules
......
......@@ -31,6 +31,7 @@ jobs:
Profiling:
name: Profiling
runs-on: ubuntu-latest
timeout-minutes: 90
strategy:
matrix:
storage: ['h2', 'mysql', 'es6', 'es7', 'influxdb']
......
......@@ -31,6 +31,7 @@ jobs:
StoragePlugins:
name: Storage
runs-on: ubuntu-latest
timeout-minutes: 90
strategy:
matrix:
storage: ['mysql', 'es6', 'es7', 'influxdb']
......@@ -57,6 +58,7 @@ jobs:
Storage:
runs-on: ubuntu-latest
timeout-minutes: 90
needs: [StoragePlugins]
steps:
- name: To pass or not pass
......
......@@ -31,6 +31,7 @@ jobs:
TTL:
name: Storage TTL
runs-on: ubuntu-latest
timeout-minutes: 90
strategy:
matrix:
storage: ['es6', 'es7', 'influxdb']
......
......@@ -32,6 +32,7 @@ jobs:
FeatureGroup01:
name: Feature
runs-on: ubuntu-latest
timeout-minutes: 90
strategy:
matrix:
case: [auth, compatibility, ssl]
......@@ -59,6 +60,7 @@ jobs:
FeatureGroup02:
name: Agent Reboot & Lua Nginx
runs-on: ubuntu-latest
timeout-minutes: 90
steps:
- uses: actions/checkout@v2
- name: checkout submodules
......@@ -83,6 +85,7 @@ jobs:
FeatureGroup03:
name: Gateway
runs-on: ubuntu-latest
timeout-minutes: 90
steps:
- uses: actions/checkout@v2
- name: checkout submodules
......
......@@ -22,11 +22,10 @@ import org.apache.skywalking.apm.agent.core.commands.CommandExecutionException;
import org.apache.skywalking.apm.agent.core.commands.CommandExecutor;
import org.apache.skywalking.apm.agent.core.conf.RemoteDownstreamConfig;
import org.apache.skywalking.apm.agent.core.dictionary.DictionaryUtil;
import org.apache.skywalking.apm.agent.core.dictionary.EndpointNameDictionary;
import org.apache.skywalking.apm.agent.core.dictionary.NetworkAddressDictionary;
import org.apache.skywalking.apm.agent.core.logging.api.ILog;
import org.apache.skywalking.apm.agent.core.logging.api.LogManager;
import org.apache.skywalking.apm.agent.core.remote.ServiceAndEndpointRegisterClient;
import org.apache.skywalking.apm.agent.core.remote.ServiceRegisterClient;
import org.apache.skywalking.apm.network.trace.component.command.BaseCommand;
import org.apache.skywalking.apm.network.trace.component.command.ServiceResetCommand;
......@@ -40,13 +39,12 @@ public class ServiceResetCommandExecutor implements CommandExecutor {
public void execute(final BaseCommand command) throws CommandExecutionException {
LOGGER.warn("Received ServiceResetCommand, a re-register task is scheduled.");
ServiceManager.INSTANCE.findService(ServiceAndEndpointRegisterClient.class).coolDown();
ServiceManager.INSTANCE.findService(ServiceRegisterClient.class).coolDown();
RemoteDownstreamConfig.Agent.SERVICE_ID = DictionaryUtil.nullValue();
RemoteDownstreamConfig.Agent.SERVICE_INSTANCE_ID = DictionaryUtil.nullValue();
RemoteDownstreamConfig.Agent.INSTANCE_REGISTERED_TIME = DictionaryUtil.nullValue();
NetworkAddressDictionary.INSTANCE.clear();
EndpointNameDictionary.INSTANCE.clear();
}
}
......@@ -22,4 +22,6 @@ public class Constants {
public static String PATH_SEPARATOR = System.getProperty("file.separator", "/");
public static String LINE_SEPARATOR = System.getProperty("line.separator", "\n");
public static String EMPTY_STRING = "";
}
......@@ -165,18 +165,10 @@ public class ContextCarrier implements Serializable {
this.entryEndpointName = '#' + entryEndpointName;
}
void setEntryEndpointId(int entryOperationId) {
this.entryEndpointName = entryOperationId + "";
}
void setParentEndpointName(String parentEndpointName) {
this.parentEndpointName = '#' + parentEndpointName;
}
void setParentEndpointId(int parentOperationId) {
this.parentEndpointName = parentOperationId + "";
}
public ID getTraceSegmentId() {
return traceSegmentId;
}
......
......@@ -131,7 +131,8 @@ public class TracingContext implements AbstractTracerContext {
if (PROFILE_TASK_EXECUTION_SERVICE == null) {
PROFILE_TASK_EXECUTION_SERVICE = ServiceManager.INSTANCE.findService(ProfileTaskExecutionService.class);
}
this.profileStatus = PROFILE_TASK_EXECUTION_SERVICE.addProfiling(this, segment.getTraceSegmentId(), firstOPName);
this.profileStatus = PROFILE_TASK_EXECUTION_SERVICE.addProfiling(
this, segment.getTraceSegmentId(), firstOPName);
this.correlationContext = new CorrelationContext();
}
......@@ -184,56 +185,21 @@ public class TracingContext implements AbstractTracerContext {
String firstSpanOperationName = firstSpan.getOperationName();
List<TraceSegmentRef> refs = this.segment.getRefs();
int operationId = DictionaryUtil.inexistence();
String operationName = "";
int entryApplicationInstanceId;
if (refs != null && refs.size() > 0) {
TraceSegmentRef ref = refs.get(0);
operationId = ref.getEntryEndpointId();
operationName = ref.getEntryEndpointName();
entryApplicationInstanceId = ref.getEntryServiceInstanceId();
} else {
if (firstSpan.isEntry()) {
/*
* Since 6.6.0, if first span is not entry span, then this is an internal segment(no RPC),
* rather than an endpoint.
*/
operationId = firstSpan.getOperationId();
operationName = firstSpanOperationName;
}
operationName = firstSpanOperationName;
entryApplicationInstanceId = this.segment.getApplicationInstanceId();
}
carrier.setEntryServiceInstanceId(entryApplicationInstanceId);
if (operationId == DictionaryUtil.nullValue()) {
if (!StringUtil.isEmpty(operationName)) {
carrier.setEntryEndpointName(operationName);
} else {
/*
* Since 6.6.0, if first span is not entry span, then this is an internal segment(no RPC),
* rather than an endpoint.
*/
}
} else {
carrier.setEntryEndpointId(operationId);
}
int parentOperationId = firstSpan.getOperationId();
if (parentOperationId == DictionaryUtil.nullValue()) {
if (firstSpan.isEntry() && !StringUtil.isEmpty(firstSpanOperationName)) {
carrier.setParentEndpointName(firstSpanOperationName);
} else {
/*
* Since 6.6.0, if first span is not entry span, then this is an internal segment(no RPC),
* rather than an endpoint.
*/
carrier.setParentEndpointId(DictionaryUtil.inexistence());
}
} else {
carrier.setParentEndpointId(parentOperationId);
}
carrier.setEntryServiceInstanceId(entryApplicationInstanceId);
carrier.setEntryEndpointName(operationName);
carrier.setParentEndpointName(firstSpanOperationName);
carrier.setDistributedTraceIds(this.segment.getRelatedGlobalTraces());
......@@ -267,7 +233,9 @@ public class TracingContext implements AbstractTracerContext {
public ContextSnapshot capture() {
List<TraceSegmentRef> refs = this.segment.getRefs();
ContextSnapshot snapshot = new ContextSnapshot(
segment.getTraceSegmentId(), activeSpan().getSpanId(), segment.getRelatedGlobalTraces(), this.correlationContext);
segment.getTraceSegmentId(), activeSpan().getSpanId(), segment.getRelatedGlobalTraces(),
this.correlationContext
);
int entryOperationId;
String entryOperationName = "";
int entryApplicationInstanceId;
......@@ -276,51 +244,16 @@ public class TracingContext implements AbstractTracerContext {
if (refs != null && refs.size() > 0) {
TraceSegmentRef ref = refs.get(0);
entryOperationId = ref.getEntryEndpointId();
entryOperationName = ref.getEntryEndpointName();
entryApplicationInstanceId = ref.getEntryServiceInstanceId();
} else {
if (firstSpan.isEntry()) {
entryOperationId = firstSpan.getOperationId();
entryOperationName = firstSpanOperationName;
} else {
/*
* Since 6.6.0, if first span is not entry span, then this is an internal segment(no RPC),
* rather than an endpoint.
*/
entryOperationId = DictionaryUtil.inexistence();
}
entryOperationName = firstSpanOperationName;
entryApplicationInstanceId = this.segment.getApplicationInstanceId();
}
snapshot.setEntryApplicationInstanceId(entryApplicationInstanceId);
snapshot.setEntryOperationName(entryOperationName);
snapshot.setParentOperationName(firstSpanOperationName);
if (entryOperationId == DictionaryUtil.nullValue()) {
if (!StringUtil.isEmpty(entryOperationName)) {
snapshot.setEntryOperationName(entryOperationName);
} else {
/*
* Since 6.6.0, if first span is not entry span, then this is an internal segment(no RPC),
* rather than an endpoint.
*/
}
} else {
snapshot.setEntryOperationId(entryOperationId);
}
int parentOperationId = firstSpan.getOperationId();
if (parentOperationId == DictionaryUtil.nullValue()) {
if (firstSpan.isEntry() && !StringUtil.isEmpty(firstSpanOperationName)) {
snapshot.setParentOperationName(firstSpanOperationName);
} else {
/*
* Since 6.6.0, if first span is not entry span, then this is an internal segment(no RPC),
* rather than an endpoint.
*/
snapshot.setParentOperationId(DictionaryUtil.inexistence());
}
} else {
snapshot.setParentOperationId(parentOperationId);
}
return snapshot;
}
......@@ -368,25 +301,14 @@ public class TracingContext implements AbstractTracerContext {
* as the operation name could be overrided.
*/
profilingRecheck(parentSpan, operationName);
entrySpan = (AbstractTracingSpan) DictionaryManager.findEndpointSection()
.findOnly(segment.getServiceId(), operationName)
.doInCondition(
parentSpan::setOperationId, () -> parentSpan
.setOperationName(operationName));
parentSpan.setOperationName(operationName);
entrySpan = parentSpan;
return entrySpan.start();
} else {
entrySpan = (AbstractTracingSpan) DictionaryManager.findEndpointSection()
.findOnly(segment.getServiceId(), operationName)
.doInCondition(
operationId -> new EntrySpan(spanIdGenerator++,
parentSpanId,
operationId, owner
), () -> {
return new EntrySpan(
spanIdGenerator++, parentSpanId,
operationName, owner
);
});
entrySpan = new EntrySpan(
spanIdGenerator++, parentSpanId,
operationName, owner
);
entrySpan.start();
return push(entrySpan);
}
......
......@@ -110,12 +110,8 @@ public interface AbstractSpan extends AsyncSpan {
*/
int getSpanId();
int getOperationId();
String getOperationName();
AbstractSpan setOperationId(int operationId);
/**
* Reference other trace segment.
*
......
......@@ -43,7 +43,6 @@ public abstract class AbstractTracingSpan implements AbstractSpan {
protected int parentSpanId;
protected List<TagValuePair> tags;
protected String operationName;
protected int operationId;
protected SpanLayer layer;
/**
* The span has been tagged in async mode, required async stop to finish.
......@@ -90,15 +89,6 @@ public abstract class AbstractTracingSpan implements AbstractSpan {
protected AbstractTracingSpan(int spanId, int parentSpanId, String operationName, TracingContext owner) {
this.operationName = operationName;
this.operationId = DictionaryUtil.nullValue();
this.spanId = spanId;
this.parentSpanId = parentSpanId;
this.owner = owner;
}
protected AbstractTracingSpan(int spanId, int parentSpanId, int operationId, TracingContext owner) {
this.operationName = null;
this.operationId = operationId;
this.spanId = spanId;
this.parentSpanId = parentSpanId;
this.owner = owner;
......@@ -167,7 +157,10 @@ public abstract class AbstractTracingSpan implements AbstractSpan {
logs.add(new LogDataEntity.Builder().add(new KeyValuePair("event", "error"))
.add(new KeyValuePair("error.kind", t.getClass().getName()))
.add(new KeyValuePair("message", t.getMessage()))
.add(new KeyValuePair("stack", ThrowableTransformer.INSTANCE.convert2String(t, 4000)))
.add(new KeyValuePair(
"stack",
ThrowableTransformer.INSTANCE.convert2String(t, 4000)
))
.build(System.currentTimeMillis()));
return this;
}
......@@ -211,19 +204,6 @@ public abstract class AbstractTracingSpan implements AbstractSpan {
@Override
public AbstractTracingSpan setOperationName(String operationName) {
this.operationName = operationName;
this.operationId = DictionaryUtil.nullValue();
return this;
}
/**
* Set the operation id, which compress by the name.
*
* @return span instance, for chaining.
*/
@Override
public AbstractTracingSpan setOperationId(int operationId) {
this.operationId = operationId;
this.operationName = null;
return this;
}
......@@ -232,11 +212,6 @@ public abstract class AbstractTracingSpan implements AbstractSpan {
return spanId;
}
@Override
public int getOperationId() {
return operationId;
}
@Override
public String getOperationName() {
return operationName;
......@@ -283,11 +258,7 @@ public abstract class AbstractTracingSpan implements AbstractSpan {
spanBuilder.setParentSpanId(parentSpanId);
spanBuilder.setStartTime(startTime);
spanBuilder.setEndTime(endTime);
if (operationId != DictionaryUtil.nullValue()) {
spanBuilder.setOperationNameId(operationId);
} else {
spanBuilder.setOperationName(operationName);
}
spanBuilder.setOperationName(operationName);
if (isEntry()) {
spanBuilder.setSpanType(SpanType.Entry);
} else if (isExit()) {
......
......@@ -41,11 +41,6 @@ public class EntrySpan extends StackBasedTracingSpan {
this.currentMaxDepth = 0;
}
public EntrySpan(int spanId, int parentSpanId, int operationId, TracingContext owner) {
super(spanId, parentSpanId, operationId, owner);
this.currentMaxDepth = 0;
}
/**
* Set the {@link #startTime}, when the first start, which means the first service provided.
*/
......@@ -102,15 +97,6 @@ public class EntrySpan extends StackBasedTracingSpan {
}
}
@Override
public AbstractTracingSpan setOperationId(int operationId) {
if (stackDepth == currentMaxDepth) {
return super.setOperationId(operationId);
} else {
return this;
}
}
@Override
public EntrySpan log(Throwable t) {
super.log(t);
......
......@@ -118,14 +118,6 @@ public class ExitSpan extends StackBasedTracingSpan implements ExitTypeSpan {
}
}
/**
* Illegal operation. Operation name id is the registered endpoint, only work for entry span.
*/
@Override
public AbstractTracingSpan setOperationId(int operationId) {
throw new UnsupportedOperationException("Exit span doesn't support operation id");
}
@Override
public int getPeerId() {
return peerId;
......
......@@ -25,10 +25,6 @@ import org.apache.skywalking.apm.agent.core.context.TracingContext;
*/
public class LocalSpan extends AbstractTracingSpan {
public LocalSpan(int spanId, int parentSpanId, int operationId, TracingContext owner) {
super(spanId, parentSpanId, operationId, owner);
}
public LocalSpan(int spanId, int parentSpanId, String operationName, TracingContext owner) {
super(spanId, parentSpanId, operationName, owner);
}
......@@ -47,12 +43,4 @@ public class LocalSpan extends AbstractTracingSpan {
public AbstractSpan setPeer(String remotePeer) {
return this;
}
/**
* Illegal operation. Operation name id is the registered endpoint, only work for entry span.
*/
@Override
public AbstractTracingSpan setOperationId(int operationId) {
throw new UnsupportedOperationException("Exit span doesn't support operation id");
}
}
......@@ -100,21 +100,11 @@ public class NoopSpan implements AbstractSpan {
return 0;
}
@Override
public int getOperationId() {
return 0;
}
@Override
public String getOperationName() {
return "";
}
@Override
public AbstractSpan setOperationId(int operationId) {
return this;
}
@Override
public void ref(TraceSegmentRef ref) {
}
......
......@@ -40,25 +40,6 @@ public abstract class StackBasedTracingSpan extends AbstractTracingSpan {
this.peerId = DictionaryUtil.nullValue();
}
protected StackBasedTracingSpan(int spanId, int parentSpanId, int operationId, TracingContext owner) {
super(spanId, parentSpanId, operationId, owner);
this.stackDepth = 0;
this.peer = null;
this.peerId = DictionaryUtil.nullValue();
}
public StackBasedTracingSpan(int spanId, int parentSpanId, int operationId, int peerId, TracingContext owner) {
super(spanId, parentSpanId, operationId, owner);
this.peer = null;
this.peerId = peerId;
}
public StackBasedTracingSpan(int spanId, int parentSpanId, int operationId, String peer, TracingContext owner) {
super(spanId, parentSpanId, operationId, owner);
this.peer = peer;
this.peerId = DictionaryUtil.nullValue();
}
protected StackBasedTracingSpan(int spanId, int parentSpanId, String operationName, String peer,
TracingContext owner) {
super(spanId, parentSpanId, operationName, owner);
......@@ -89,17 +70,6 @@ public abstract class StackBasedTracingSpan extends AbstractTracingSpan {
@Override
public boolean finish(TraceSegment owner) {
if (--stackDepth == 0) {
/*
* Since 6.6.0, only entry span requires the op name register, which is endpoint.
*/
if (this.isEntry()) {
if (this.operationId == DictionaryUtil.nullValue()) {
this.operationId =
(Integer) DictionaryManager.findEndpointSection()
.findOrPrepare4Register(owner.getServiceId(), operationName)
.doInCondition(value -> value, DictionaryUtil::nullValue);
}
}
return super.finish(owner);
} else {
return false;
......
......@@ -18,6 +18,7 @@
package org.apache.skywalking.apm.agent.core.context.trace;
import org.apache.skywalking.apm.agent.core.conf.Constants;
import org.apache.skywalking.apm.agent.core.conf.RemoteDownstreamConfig;
import org.apache.skywalking.apm.agent.core.context.ContextCarrier;
import org.apache.skywalking.apm.agent.core.context.ContextSnapshot;
......@@ -47,13 +48,9 @@ public class TraceSegmentRef {
private int parentServiceInstanceId;
private String entryEndpointName;
private String entryEndpointName = Constants.EMPTY_STRING;
private int entryEndpointId = DictionaryUtil.nullValue();
private String parentEndpointName;
private int parentEndpointId = DictionaryUtil.nullValue();
private String parentEndpointName = Constants.EMPTY_STRING;
/**
* Transform a {@link ContextCarrier} to the <code>TraceSegmentRef</code>
......@@ -76,16 +73,12 @@ public class TraceSegmentRef {
if (!StringUtil.isEmpty(entryOperationName)) {
if (entryOperationName.charAt(0) == '#') {
this.entryEndpointName = entryOperationName.substring(1);
} else {
this.entryEndpointId = Integer.parseInt(entryOperationName);
}
}
String parentOperationName = carrier.getParentEndpointName();
if (!StringUtil.isEmpty(parentOperationName)) {
if (parentOperationName.charAt(0) == '#') {
this.parentEndpointName = parentOperationName.substring(1);
} else {
this.parentEndpointId = Integer.parseInt(parentOperationName);
}
}
}
......@@ -100,16 +93,12 @@ public class TraceSegmentRef {
if (!StringUtil.isEmpty(entryOperationName)) {
if (entryOperationName.charAt(0) == '#') {
this.entryEndpointName = entryOperationName.substring(1);
} else {
this.entryEndpointId = Integer.parseInt(entryOperationName);
}
}
String parentOperationName = snapshot.getParentOperationName();
if (!StringUtil.isEmpty(parentOperationName)) {
if (parentOperationName.charAt(0) == '#') {
this.parentEndpointName = parentOperationName.substring(1);
} else {
this.parentEndpointId = Integer.parseInt(parentOperationName);
}
}
}
......@@ -118,10 +107,6 @@ public class TraceSegmentRef {
return entryEndpointName;
}
public int getEntryEndpointId() {
return entryEndpointId;
}
public int getEntryServiceInstanceId() {
return entryServiceInstanceId;
}
......@@ -143,25 +128,9 @@ public class TraceSegmentRef {
refBuilder.setEntryServiceInstanceId(entryServiceInstanceId);
refBuilder.setParentTraceSegmentId(traceSegmentId.transform());
refBuilder.setParentSpanId(spanId);
/*
* entryEndpointId/entryEndpointName and parentEndpointId/parentEndpointName could be empty at same time.
* This is accepted in v2 format.
*
*/
if (entryEndpointId == DictionaryUtil.nullValue()) {
if (!StringUtil.isEmpty(entryEndpointName)) {
refBuilder.setEntryEndpoint(entryEndpointName);
}
} else {
refBuilder.setEntryEndpointId(entryEndpointId);
}
if (parentEndpointId == DictionaryUtil.nullValue()) {
if (!StringUtil.isEmpty(parentEndpointName)) {
refBuilder.setParentEndpoint(parentEndpointName);
}
} else {
refBuilder.setParentEndpointId(parentEndpointId);
}
refBuilder.setEntryEndpoint(entryEndpointName);
refBuilder.setParentEndpoint(parentEndpointName);
return refBuilder.build();
}
......
......@@ -25,11 +25,4 @@ public class DictionaryManager {
public static NetworkAddressDictionary findNetworkAddressSection() {
return NetworkAddressDictionary.INSTANCE;
}
/**
* @return {@link EndpointNameDictionary} to find service id.
*/
public static EndpointNameDictionary findEndpointSection() {
return EndpointNameDictionary.INSTANCE;
}
}
......@@ -26,11 +26,4 @@ public class DictionaryUtil {
public static boolean isNull(int id) {
return id == nullValue();
}
/**
* @return -1 represent the object doesn't exist.
*/
public static int inexistence() {
return -1;
}
}
/*
* 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.apm.agent.core.dictionary;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import org.apache.skywalking.apm.network.common.DetectPoint;
import org.apache.skywalking.apm.network.register.v2.Endpoint;
import org.apache.skywalking.apm.network.register.v2.EndpointMapping;
import org.apache.skywalking.apm.network.register.v2.EndpointMappingElement;
import org.apache.skywalking.apm.network.register.v2.Endpoints;
import org.apache.skywalking.apm.network.register.v2.RegisterGrpc;
import static org.apache.skywalking.apm.agent.core.conf.Config.Dictionary.ENDPOINT_NAME_BUFFER_SIZE;
public enum EndpointNameDictionary {
INSTANCE;
private Map<OperationNameKey, Integer> endpointDictionary = new ConcurrentHashMap<>();
private Set<OperationNameKey> unRegisterEndpoints = ConcurrentHashMap.newKeySet();
public PossibleFound findOrPrepare4Register(int serviceId, String endpointName) {
return find0(serviceId, endpointName, true);
}
public PossibleFound findOnly(int serviceId, String endpointName) {
return find0(serviceId, endpointName, false);
}
private PossibleFound find0(int serviceId, String endpointName, boolean registerWhenNotFound) {
if (endpointName == null || endpointName.length() == 0) {
return new NotFound();
}
OperationNameKey key = new OperationNameKey(serviceId, endpointName);
Integer operationId = endpointDictionary.get(key);
if (operationId != null) {
return new Found(operationId);
} else {
if (registerWhenNotFound && endpointDictionary.size() + unRegisterEndpoints.size() < ENDPOINT_NAME_BUFFER_SIZE) {
unRegisterEndpoints.add(key);
}
return new NotFound();
}
}
public void syncRemoteDictionary(RegisterGrpc.RegisterBlockingStub serviceNameDiscoveryServiceBlockingStub) {
if (unRegisterEndpoints.size() > 0) {
Endpoints.Builder builder = Endpoints.newBuilder();
for (OperationNameKey operationNameKey : unRegisterEndpoints) {
Endpoint endpoint = Endpoint.newBuilder()
.setServiceId(operationNameKey.getServiceId())
.setEndpointName(operationNameKey.getEndpointName())
.setFrom(DetectPoint.server)
.build();
builder.addEndpoints(endpoint);
}
EndpointMapping serviceNameMappingCollection = serviceNameDiscoveryServiceBlockingStub.doEndpointRegister(builder
.build());
if (serviceNameMappingCollection.getElementsCount() > 0) {
for (EndpointMappingElement element : serviceNameMappingCollection.getElementsList()) {
OperationNameKey key = new OperationNameKey(element.getServiceId(), element.getEndpointName());
unRegisterEndpoints.remove(key);
endpointDictionary.put(key, element.getEndpointId());
}
}
}
}
public void clear() {
endpointDictionary.clear();
}
@Getter
@ToString
@RequiredArgsConstructor
private static class OperationNameKey {
private final int serviceId;
private final String endpointName;
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
OperationNameKey key = (OperationNameKey) o;
boolean isServiceEndpointMatch = false;
if (serviceId == key.serviceId && endpointName.equals(key.endpointName)) {
isServiceEndpointMatch = true;
}
return isServiceEndpointMatch;
}
@Override
public int hashCode() {
int result = serviceId;
result = 31 * result + endpointName.hashCode();
return result;
}
}
}
......@@ -33,7 +33,6 @@ import org.apache.skywalking.apm.agent.core.commands.CommandService;
import org.apache.skywalking.apm.agent.core.conf.Config;
import org.apache.skywalking.apm.agent.core.conf.RemoteDownstreamConfig;
import org.apache.skywalking.apm.agent.core.dictionary.DictionaryUtil;
import org.apache.skywalking.apm.agent.core.dictionary.EndpointNameDictionary;
import org.apache.skywalking.apm.agent.core.dictionary.NetworkAddressDictionary;
import org.apache.skywalking.apm.agent.core.logging.api.ILog;
import org.apache.skywalking.apm.agent.core.logging.api.LogManager;
......@@ -57,15 +56,15 @@ import org.apache.skywalking.apm.util.StringUtil;
import static org.apache.skywalking.apm.agent.core.conf.Config.Collector.GRPC_UPSTREAM_TIMEOUT;
@DefaultImplementor
public class ServiceAndEndpointRegisterClient implements BootService, Runnable, GRPCChannelListener {
private static final ILog logger = LogManager.getLogger(ServiceAndEndpointRegisterClient.class);
public class ServiceRegisterClient implements BootService, Runnable, GRPCChannelListener {
private static final ILog logger = LogManager.getLogger(ServiceRegisterClient.class);
private static String INSTANCE_UUID;
private static List<KeyStringValuePair> SERVICE_INSTANCE_PROPERTIES;
private volatile GRPCChannelStatus status = GRPCChannelStatus.DISCONNECT;
private volatile RegisterGrpc.RegisterBlockingStub registerBlockingStub;
private volatile ServiceInstancePingGrpc.ServiceInstancePingBlockingStub serviceInstancePingStub;
private volatile ScheduledFuture<?> applicationRegisterFuture;
private volatile ScheduledFuture<?> serviceRegisterFuture;
private volatile long coolDownStartTime = -1;
@Override
......@@ -101,8 +100,8 @@ public class ServiceAndEndpointRegisterClient implements BootService, Runnable,
@Override
public void boot() {
applicationRegisterFuture = Executors.newSingleThreadScheduledExecutor(
new DefaultNamedThreadFactory("ServiceAndEndpointRegisterClient")
serviceRegisterFuture = Executors.newSingleThreadScheduledExecutor(
new DefaultNamedThreadFactory("ServiceRegisterClient")
).scheduleAtFixedRate(
new RunnableWithExceptionProtection(
this,
......@@ -118,12 +117,12 @@ public class ServiceAndEndpointRegisterClient implements BootService, Runnable,
@Override
public void shutdown() {
applicationRegisterFuture.cancel(true);
serviceRegisterFuture.cancel(true);
}
@Override
public void run() {
logger.debug("ServiceAndEndpointRegisterClient running, status:{}.", status);
logger.debug("ServiceRegisterClient running, status:{}.", status);
if (coolDownStartTime > 0) {
final long coolDownDurationInMillis = TimeUnit.MINUTES.toMillis(Config.Agent.COOL_DOWN_THRESHOLD);
......@@ -201,14 +200,12 @@ public class ServiceAndEndpointRegisterClient implements BootService, Runnable,
NetworkAddressDictionary.INSTANCE.syncRemoteDictionary(
registerBlockingStub.withDeadlineAfter(GRPC_UPSTREAM_TIMEOUT, TimeUnit.SECONDS));
EndpointNameDictionary.INSTANCE.syncRemoteDictionary(
registerBlockingStub.withDeadlineAfter(GRPC_UPSTREAM_TIMEOUT, TimeUnit.SECONDS));
ServiceManager.INSTANCE.findService(CommandService.class).receiveCommand(commands);
}
}
}
} catch (Throwable t) {
logger.error(t, "ServiceAndEndpointRegisterClient execute fail.");
logger.error(t, "ServiceRegisterClient execute fail.");
ServiceManager.INSTANCE.findService(GRPCChannelManager.class).reportError(t);
}
}
......
......@@ -21,7 +21,7 @@ org.apache.skywalking.apm.agent.core.context.ContextManager
org.apache.skywalking.apm.agent.core.sampling.SamplingService
org.apache.skywalking.apm.agent.core.remote.GRPCChannelManager
org.apache.skywalking.apm.agent.core.jvm.JVMService
org.apache.skywalking.apm.agent.core.remote.ServiceAndEndpointRegisterClient
org.apache.skywalking.apm.agent.core.remote.ServiceRegisterClient
org.apache.skywalking.apm.agent.core.context.ContextManagerExtendService
org.apache.skywalking.apm.agent.core.commands.CommandService
org.apache.skywalking.apm.agent.core.commands.CommandExecutorService
......
......@@ -59,7 +59,7 @@ public class ContextCarrierV2HeaderTest {
contextCarrier.setParentServiceInstanceId(1);
contextCarrier.setPeerHost("127.0.0.1:8080");
contextCarrier.setEntryEndpointName("/portal");
contextCarrier.setParentEndpointId(123);
contextCarrier.setParentEndpointName("/app");
contextCarrier.getCorrelationContext().put("test", "true");
......@@ -72,7 +72,7 @@ public class ContextCarrierV2HeaderTest {
* "1-3.4.5-1.2.3-4-1-1-#127.0.0.1:8080-#/portal-123"
*/
if (next.getHeadKey().equals(SW6CarrierItem.HEADER_NAME)) {
Assert.assertEquals("1-My40LjU=-MS4yLjM=-4-1-1-IzEyNy4wLjAuMTo4MDgw-Iy9wb3J0YWw=-MTIz", next.getHeadValue());
Assert.assertEquals("1-My40LjU=-MS4yLjM=-4-1-1-IzEyNy4wLjAuMTo4MDgw-Iy9wb3J0YWw=-Iy9hcHA=", next.getHeadValue());
} else if (next.getHeadKey().equals(SW7CorrelationCarrierItem.HEADER_NAME)) {
/**
* customKey:customValue
......@@ -89,7 +89,7 @@ public class ContextCarrierV2HeaderTest {
while (next.hasNext()) {
next = next.next();
if (next.getHeadKey().equals(SW6CarrierItem.HEADER_NAME)) {
Assert.assertEquals("1-My40LjU=-MS4yLjM=-4-1-1-IzEyNy4wLjAuMTo4MDgw-Iy9wb3J0YWw=-MTIz", next.getHeadValue());
Assert.assertEquals("1-My40LjU=-MS4yLjM=-4-1-1-IzEyNy4wLjAuMTo4MDgw-Iy9wb3J0YWw=-Iy9hcHA=", next.getHeadValue());
} else if (next.getHeadKey().equals(SW7CorrelationCarrierItem.HEADER_NAME)) {
Assert.assertEquals("dGVzdA==:dHJ1ZQ==", next.getHeadValue());
} else {
......@@ -113,7 +113,7 @@ public class ContextCarrierV2HeaderTest {
contextCarrier.setParentServiceInstanceId(1);
contextCarrier.setPeerHost("127.0.0.1:8080");
contextCarrier.setEntryEndpointName("/portal");
contextCarrier.setParentEndpointId(123);
contextCarrier.setParentEndpointName("/app");
contextCarrier.getCorrelationContext().put("test", "true");
......
......@@ -141,7 +141,6 @@ public class ContextManagerTest {
TraceSegmentRef ref = actualSegment.getRefs().get(0);
MatcherAssert.assertThat(TraceSegmentRefHelper.getPeerHost(ref), is("127.0.0.1:8080"));
assertThat(ref.getEntryEndpointName(), is("/portal/"));
assertThat(ref.getEntryEndpointId(), is(0));
List<AbstractTracingSpan> spanList = SegmentHelper.getSpan(actualSegment);
assertThat(spanList.size(), is(2));
......
......@@ -221,7 +221,6 @@ registryItems:
- { SERVICE_CODE: INSTANCE_COUNT(int) }
...
operationNames:
- SERVICE_CODE: [ ENTRY_SPAN_OPERATION(string), ... ]
...
```
......@@ -230,7 +229,7 @@ registryItems:
| --- | ---
| services | The registered service codes. Normally, not 0 should be enough.
| instances | The number of service instances exists in this test case.
| operationNames | Operation names of entry spans. Since 6.6.0, only these span name would do register, due to they are real endpoints.
| operationNames | Since 7.1.0, there is no operation name register. Ignore this.
**Segment verify description format**
......
......@@ -16,7 +16,8 @@ Service, Service Instance, Network address and Endpoint could do register to get
### Language based native agent protocol
There is two types of protocols to make language agents work in distributed environments.
1. **Cross Process Propagation Headers Protocol** is in wire data format, agent/SDK usually uses HTTP/MQ/HTTP2 headers
1. **Cross Process Propagation Headers Protocol** and **Cross Process Correlation Headers Protocol** are in wire data format,
agent/SDK usually uses HTTP/MQ/HTTP2 headers
to carry the data with rpc request. The remote agent will receive this in the request handler, and bind the context
with this specific request.
1. **Trace Data Protocol** is out of wire data, agent/SDK uses this to send traces and metrics to skywalking or other
......@@ -25,10 +26,14 @@ compatible backend.
[Cross Process Propagation Headers Protocol v2](Skywalking-Cross-Process-Propagation-Headers-Protocol-v2.md) is the new protocol for
in-wire context propagation, started in 6.0.0-beta release, v1 is no longer supported.
Since SkyWalking v6.0.0-beta, SkyWalking agent and backend are using Trace Data Protocol v2.
[SkyWalking Trace Data Protocol v2](Trace-Data-Protocol-v2.md) defines the communication way and format between agent and backend.
[Cross Process Correlation Headers Protocol v1](Skywalking-Cross-Process-Correlation-Headers-Protocol-v1.md) is a new in-wire context propagation additional and optional protocols.
Please read SkyWalking language agents documentations to see whether it is supported.
This protocol defines the data format of transporting custom data with `Cross Process Propagation Headers Protocol v2`.
SkyWalking javaagent begins to support this since 7.1.0.
Since SkyWalking v7.1.0, SkyWalking agent and backend are using Trace Data Protocol v2.1.
[SkyWalking Trace Data Protocol v2.1](Trace-Data-Protocol-v2.md) defines the communication way and format between agent and backend.
* [Cross Process Correlation Headers Protocol v1](Skywalking-Cross-Process-Correlation-Headers-Protocol-v1.md) is a new in-wire context propagation additional and optional protocols. Please read SkyWalking language agents documentations to see whether it is supported. This protocol defines the data format of transporting custom data with `Cross Process Propagation Headers Protocol v2`. SkyWalking javaagent begins to support this since 7.1.0.
### Service Mesh probe protocol
The probe in sidecar or proxy could use this protocol to send data to backendEnd. This service provided by gRPC, requires
......
# SkyWalking Cross Process Propagation Headers Protocol
* Version 2.0
* Version 2.1
SkyWalking is more likely an APM system, rather than common distributed tracing system.
The Headers is much more complex than them in order to improving analysis performance of collector.
......@@ -8,12 +8,6 @@ You can find many similar mechanism in other commercial APM system. (Some are ev
## Abstract
SkyWalking Cross Process Propagation Headers Protocol v2 is also named as sw6 protocol, which is for context propagation.
## Differences from v1
The major differences of v2 and v1, comes from SkyWalking's evolution, including
1. Mesh and languages are not same always, some info in headers should be optional.
1. BASE64 encoding required.
1. Sampling flag is included.
## Header Item
* Header Name: `sw6`
* Header Value: Split by `-`, the parts are following. The length of header value should be less than 2k(default).
......@@ -36,13 +30,19 @@ service. _This value can use exchange/compress collector service to get the id(i
- Optional(s)
Optional values could not exist if the agent/SDK haven't those info or the length of header is over the threshold(2k default).
1. Entry endpoint of the trace. **String(BASE64 encoded)**.
_This value can use exchange/compress collector service to get the id(integer) to represent the string. If you use the string, it must start with `#`, others use integer directly._
1. Parent endpoint of the parent service. **String(BASE64 encoded)**.
_This value can use exchange/compress collector service to get the id(integer) to represent the string. If you use the string, it must start with `#`, others use integer directly._
endpoint id = -1 and parent endpoint name is empty mean there is no real parent endpoint. Since 6.6.0
1. Entry endpoint of the trace. Add `#` as the prefix. **String(BASE64 encoded)**.
1. Parent endpoint of the parent service. Add `#` as the prefix. **String(BASE64 encoded)**.
## Sample values
1. Short version, `1-TRACEID-SEGMENTID-3-5-2-IPPORT`
1. Complete version, `1-TRACEID-SEGMENTID-3-5-2-IPPORT-ENTRYURI-PARENTURI`
## Differences from v2
The entry and parent endpoints in the header doesn't support ID format. Always use the literal string.
[SkyWalking v2](https://github.com/apache/skywalking/blob/v7.0.0/docs/en/protocols/Trace-Data-Protocol-v2.md)
## Differences from v1
The major differences of v2 and v1, comes from SkyWalking's evolution, including
1. Mesh and languages are not same always, some info in headers should be optional.
1. BASE64 encoding required.
1. Sampling flag is included.
......@@ -97,8 +97,8 @@ Example as following
"scopeId": 1,
"scope": "SERVICE",
"name": "serviceA",
"id0": 12,
"id1": 0,
"id0": "12",
"id1": "",
"ruleName": "service_resp_time_rule",
"alarmMessage": "alarmMessage xxxx",
"startTime": 1560524171000
......@@ -106,8 +106,8 @@ Example as following
"scopeId": 1,
"scope": "SERVICE",
"name": "serviceB",
"id0": 23,
"id1": 0,
"id0": "23",
"id1": "",
"ruleName": "service_resp_time_rule",
"alarmMessage": "alarmMessage yyy",
"startTime": 1560524171000
......@@ -124,8 +124,8 @@ message AlarmMessage {
int64 scopeId = 1;
string scope = 2;
string name = 3;
int64 id0 = 4;
int64 id1 = 5;
string id0 = 4;
string id1 = 5;
string ruleName = 6;
string alarmMessage = 7;
int64 startTime = 8;
......
......@@ -19,8 +19,8 @@
package org.apache.skywalking.oap.server.exporter.provider;
import lombok.Setter;
import org.apache.skywalking.oap.server.core.analysis.manual.endpoint.EndpointTraffic;
import org.apache.skywalking.oap.server.core.analysis.metrics.MetricsMetaInfo;
import org.apache.skywalking.oap.server.core.cache.EndpointInventoryCache;
import org.apache.skywalking.oap.server.core.cache.ServiceInstanceInventoryCache;
import org.apache.skywalking.oap.server.core.cache.ServiceInventoryCache;
import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
......@@ -29,7 +29,6 @@ import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
public class MetricFormatter {
private ServiceInventoryCache serviceInventoryCache;
private ServiceInstanceInventoryCache serviceInstanceInventoryCache;
private EndpointInventoryCache endpointInventoryCache;
protected String getEntityName(MetricsMetaInfo meta) {
int scope = meta.getScope();
......@@ -40,8 +39,7 @@ public class MetricFormatter {
int entityId = Integer.valueOf(meta.getId());
return serviceInstanceInventoryCache.get(entityId).getName();
} else if (DefaultScopeDefine.inEndpointCatalog(scope)) {
int entityId = Integer.valueOf(meta.getId());
return endpointInventoryCache.get(entityId).getName();
return EndpointTraffic.splitID(meta.getId()).getEndpointName();
} else if (scope == DefaultScopeDefine.ALL) {
return "";
} else {
......
......@@ -19,7 +19,6 @@
package org.apache.skywalking.oap.server.exporter.provider.grpc;
import org.apache.skywalking.oap.server.core.CoreModule;
import org.apache.skywalking.oap.server.core.cache.EndpointInventoryCache;
import org.apache.skywalking.oap.server.core.cache.ServiceInstanceInventoryCache;
import org.apache.skywalking.oap.server.core.cache.ServiceInventoryCache;
import org.apache.skywalking.oap.server.core.exporter.ExporterModule;
......@@ -67,7 +66,6 @@ public class GRPCExporterProvider extends ModuleProvider {
ModuleServiceHolder serviceHolder = getManager().find(CoreModule.NAME).provider();
exporter.setServiceInventoryCache(serviceHolder.getService(ServiceInventoryCache.class));
exporter.setServiceInstanceInventoryCache(serviceHolder.getService(ServiceInstanceInventoryCache.class));
exporter.setEndpointInventoryCache(serviceHolder.getService(EndpointInventoryCache.class));
exporter.initSubscriptionList();
}
......
......@@ -21,7 +21,6 @@ package org.apache.skywalking.oap.server.exporter.provider.grpc;
import java.util.Iterator;
import java.util.ServiceLoader;
import org.apache.skywalking.oap.server.core.CoreModule;
import org.apache.skywalking.oap.server.core.cache.EndpointInventoryCache;
import org.apache.skywalking.oap.server.core.cache.ServiceInstanceInventoryCache;
import org.apache.skywalking.oap.server.core.cache.ServiceInventoryCache;
import org.apache.skywalking.oap.server.core.exporter.ExporterModule;
......@@ -97,7 +96,6 @@ public class GRPCExporterProviderTest {
when(serviceHolder.getService(ServiceInventoryCache.class)).thenReturn(null);
when(serviceHolder.getService(ServiceInstanceInventoryCache.class)).thenReturn(null);
when(serviceHolder.getService(EndpointInventoryCache.class)).thenReturn(null);
doNothing().when(exporter).initSubscriptionList();
......
......@@ -21,6 +21,7 @@ package org.apache.skywalking.oap.server.core.alarm.provider;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.apache.skywalking.oap.server.core.CoreModule;
import org.apache.skywalking.oap.server.core.alarm.AlarmCallback;
import org.apache.skywalking.oap.server.core.alarm.EndpointMetaInAlarm;
......@@ -29,22 +30,21 @@ import org.apache.skywalking.oap.server.core.alarm.MetricsNotify;
import org.apache.skywalking.oap.server.core.alarm.ServiceInstanceMetaInAlarm;
import org.apache.skywalking.oap.server.core.alarm.ServiceMetaInAlarm;
import org.apache.skywalking.oap.server.core.alarm.provider.grpc.GRPCCallback;
import org.apache.skywalking.oap.server.core.analysis.manual.endpoint.EndpointTraffic;
import org.apache.skywalking.oap.server.core.analysis.metrics.Metrics;
import org.apache.skywalking.oap.server.core.analysis.metrics.MetricsMetaInfo;
import org.apache.skywalking.oap.server.core.analysis.metrics.WithMetadata;
import org.apache.skywalking.oap.server.core.cache.EndpointInventoryCache;
import org.apache.skywalking.oap.server.core.cache.ServiceInstanceInventoryCache;
import org.apache.skywalking.oap.server.core.cache.ServiceInventoryCache;
import org.apache.skywalking.oap.server.core.register.EndpointInventory;
import org.apache.skywalking.oap.server.core.register.ServiceInstanceInventory;
import org.apache.skywalking.oap.server.core.register.ServiceInventory;
import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
@Slf4j
public class NotifyHandler implements MetricsNotify {
private ServiceInventoryCache serviceInventoryCache;
private ServiceInstanceInventoryCache serviceInstanceInventoryCache;
private EndpointInventoryCache endpointInventoryCache;
private final AlarmCore core;
private final AlarmRulesWatcher alarmRulesWatcher;
......@@ -60,7 +60,8 @@ public class NotifyHandler implements MetricsNotify {
MetricsMetaInfo meta = withMetadata.getMeta();
int scope = meta.getScope();
if (!DefaultScopeDefine.inServiceCatalog(scope) && !DefaultScopeDefine.inServiceInstanceCatalog(scope) && !DefaultScopeDefine
if (!DefaultScopeDefine.inServiceCatalog(scope) && !DefaultScopeDefine.inServiceInstanceCatalog(
scope) && !DefaultScopeDefine
.inEndpointCatalog(scope)) {
return;
}
......@@ -71,7 +72,7 @@ public class NotifyHandler implements MetricsNotify {
ServiceInventory serviceInventory = serviceInventoryCache.get(serviceId);
ServiceMetaInAlarm serviceMetaInAlarm = new ServiceMetaInAlarm();
serviceMetaInAlarm.setMetricsName(meta.getMetricsName());
serviceMetaInAlarm.setId(serviceId);
serviceMetaInAlarm.setId(String.valueOf(serviceId));
serviceMetaInAlarm.setName(serviceInventory.getName());
metaInAlarm = serviceMetaInAlarm;
} else if (DefaultScopeDefine.inServiceInstanceCatalog(scope)) {
......@@ -79,21 +80,18 @@ public class NotifyHandler implements MetricsNotify {
ServiceInstanceInventory serviceInstanceInventory = serviceInstanceInventoryCache.get(serviceInstanceId);
ServiceInstanceMetaInAlarm instanceMetaInAlarm = new ServiceInstanceMetaInAlarm();
instanceMetaInAlarm.setMetricsName(meta.getMetricsName());
instanceMetaInAlarm.setId(serviceInstanceId);
instanceMetaInAlarm.setId(String.valueOf(serviceInstanceId));
instanceMetaInAlarm.setName(serviceInstanceInventory.getName());
metaInAlarm = instanceMetaInAlarm;
} else if (DefaultScopeDefine.inEndpointCatalog(scope)) {
int endpointId = Integer.parseInt(meta.getId());
EndpointInventory endpointInventory = endpointInventoryCache.get(endpointId);
EndpointMetaInAlarm endpointMetaInAlarm = new EndpointMetaInAlarm();
endpointMetaInAlarm.setMetricsName(meta.getMetricsName());
endpointMetaInAlarm.setId(endpointId);
int serviceId = endpointInventory.getServiceId();
ServiceInventory serviceInventory = serviceInventoryCache.get(serviceId);
String textName = endpointInventory.getName() + " in " + serviceInventory.getName();
final EndpointTraffic.EndpointID endpointID = EndpointTraffic.splitID(meta.getId());
ServiceInventory serviceInventory = serviceInventoryCache.get(endpointID.getServiceId());
String textName = endpointID.getEndpointName() + " in " + serviceInventory.getName();
endpointMetaInAlarm.setId(meta.getId());
endpointMetaInAlarm.setName(textName);
metaInAlarm = endpointMetaInAlarm;
} else {
......@@ -120,8 +118,5 @@ public class NotifyHandler implements MetricsNotify {
serviceInstanceInventoryCache = moduleManager.find(CoreModule.NAME)
.provider()
.getService(ServiceInstanceInventoryCache.class);
endpointInventoryCache = moduleManager.find(CoreModule.NAME)
.provider()
.getService(EndpointInventoryCache.class);
}
}
......@@ -30,8 +30,8 @@ message AlarmMessage {
int64 scopeId = 1;
string scope = 2;
string name = 3;
int64 id0 = 4;
int64 id1 = 5;
string id0 = 4;
string id1 = 5;
string ruleName = 6;
string alarmMessage = 7;
int64 startTime = 8;
......
......@@ -49,13 +49,13 @@ public class AlarmMessageFormatterTest {
}
@Override
public int getId0() {
return 0;
public String getId0() {
return "";
}
@Override
public int getId1() {
return 0;
public String getId1() {
return "";
}
});
......@@ -88,13 +88,13 @@ public class AlarmMessageFormatterTest {
}
@Override
public int getId0() {
return 1290;
public String getId0() {
return "1290";
}
@Override
public int getId1() {
return 0;
public String getId1() {
return "";
}
});
Assert.assertEquals("abc} words service - 1290 .. {", message);
......
......@@ -25,16 +25,16 @@ import org.apache.skywalking.oap.server.core.alarm.EndpointMetaInAlarm;
import org.apache.skywalking.oap.server.core.alarm.MetaInAlarm;
import org.apache.skywalking.oap.server.core.alarm.ServiceInstanceMetaInAlarm;
import org.apache.skywalking.oap.server.core.alarm.ServiceMetaInAlarm;
import org.apache.skywalking.oap.server.core.analysis.manual.endpoint.EndpointTraffic;
import org.apache.skywalking.oap.server.core.analysis.metrics.Metrics;
import org.apache.skywalking.oap.server.core.analysis.metrics.MetricsMetaInfo;
import org.apache.skywalking.oap.server.core.analysis.metrics.WithMetadata;
import org.apache.skywalking.oap.server.core.cache.EndpointInventoryCache;
import org.apache.skywalking.oap.server.core.cache.ServiceInstanceInventoryCache;
import org.apache.skywalking.oap.server.core.cache.ServiceInventoryCache;
import org.apache.skywalking.oap.server.core.register.EndpointInventory;
import org.apache.skywalking.oap.server.core.register.ServiceInstanceInventory;
import org.apache.skywalking.oap.server.core.register.ServiceInventory;
import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
import org.apache.skywalking.oap.server.core.source.DetectPoint;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
import org.apache.skywalking.oap.server.library.module.ModuleProviderHolder;
import org.apache.skywalking.oap.server.library.module.ModuleServiceHolder;
......@@ -76,8 +76,6 @@ public class NotifyHandlerTest {
private ServiceInstanceInventoryCache serviceInstanceInventoryCache;
private EndpointInventoryCache endpointInventoryCache;
private MockMetrics metrics;
private MetricsMetaInfo metadata;
......@@ -96,16 +94,15 @@ public class NotifyHandlerTest {
when(DefaultScopeDefine.inEndpointCatalog(0)).thenReturn(true);
String endpointInventoryName = "endpoint-inventory-name";
EndpointInventory endpointInventory = mock(EndpointInventory.class);
when(endpointInventory.getName()).thenReturn(endpointInventoryName);
EndpointTraffic endpointTraffic = mock(EndpointTraffic.class);
when(endpointTraffic.getName()).thenReturn(endpointInventoryName);
String serviceInventoryName = "service-inventory-name";
ServiceInventory serviceInventory = mock(ServiceInventory.class);
when(serviceInventory.getName()).thenReturn(serviceInventoryName);
when(serviceInventoryCache.get(anyInt())).thenReturn(serviceInventory);
when(endpointInventoryCache.get(anyInt())).thenReturn(endpointInventory);
when(metadata.getId()).thenReturn(EndpointTraffic.buildId(1, endpointInventoryName, DetectPoint.SERVER));
ArgumentCaptor<MetaInAlarm> metaCaptor = ArgumentCaptor.forClass(MetaInAlarm.class);
......@@ -115,7 +112,7 @@ public class NotifyHandlerTest {
MetaInAlarm metaInAlarm = metaCaptor.getValue();
assertTrue(metaInAlarm instanceof EndpointMetaInAlarm);
assertEquals(mockId, metaInAlarm.getId0());
assertEquals("1_ZW5kcG9pbnQtaW52ZW50b3J5LW5hbWU=_0", metaInAlarm.getId0());
assertEquals(DefaultScopeDefine.ENDPOINT_CATALOG_NAME, metaInAlarm.getScope());
assertEquals(metricsName, metaInAlarm.getMetricsName());
assertEquals(endpointInventoryName + " in " + serviceInventoryName, metaInAlarm.getName());
......@@ -148,7 +145,7 @@ public class NotifyHandlerTest {
assertTrue(metaInAlarm instanceof ServiceInstanceMetaInAlarm);
assertEquals(metricsName, metaInAlarm.getMetricsName());
assertEquals(mockId, metaInAlarm.getId0());
assertEquals(mockId + "", metaInAlarm.getId0());
assertEquals(DefaultScopeDefine.SERVICE_INSTANCE_CATALOG_NAME, metaInAlarm.getScope());
assertEquals(instanceInventoryName, metaInAlarm.getName());
assertEquals(DefaultScopeDefine.SERVICE_INSTANCE, metaInAlarm.getScopeId());
......@@ -177,7 +174,7 @@ public class NotifyHandlerTest {
assertTrue(metaInAlarm instanceof ServiceMetaInAlarm);
assertEquals(metricsName, metaInAlarm.getMetricsName());
assertEquals(mockId, metaInAlarm.getId0());
assertEquals(mockId + "", metaInAlarm.getId0());
assertEquals(DefaultScopeDefine.SERVICE_CATALOG_NAME, metaInAlarm.getScope());
assertEquals(serviceInventoryName, metaInAlarm.getName());
assertEquals(DefaultScopeDefine.SERVICE, metaInAlarm.getScopeId());
......@@ -238,11 +235,10 @@ public class NotifyHandlerTest {
serviceInventoryCache = mock(ServiceInventoryCache.class);
serviceInstanceInventoryCache = mock(ServiceInstanceInventoryCache.class);
endpointInventoryCache = mock(EndpointInventoryCache.class);
when(moduleServiceHolder.getService(ServiceInventoryCache.class)).thenReturn(serviceInventoryCache);
when(moduleServiceHolder.getService(ServiceInstanceInventoryCache.class)).thenReturn(serviceInstanceInventoryCache);
when(moduleServiceHolder.getService(EndpointInventoryCache.class)).thenReturn(endpointInventoryCache);
when(moduleServiceHolder.getService(ServiceInstanceInventoryCache.class)).thenReturn(
serviceInstanceInventoryCache);
AlarmCore core = mock(AlarmCore.class);
......
......@@ -23,6 +23,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import org.apache.skywalking.oap.server.core.Const;
import org.apache.skywalking.oap.server.core.alarm.AlarmCallback;
import org.apache.skywalking.oap.server.core.alarm.AlarmMessage;
import org.apache.skywalking.oap.server.core.alarm.MetaInAlarm;
......@@ -143,8 +144,9 @@ public class RunningRuleTest {
// check at 201808301442
alarmMessages = runningRule.check();
Assert.assertEquals(1, alarmMessages.size());
Assert.assertEquals("response percentile of endpoint Service_123 is lower than expected values", alarmMessages.get(0)
.getAlarmMessage());
Assert.assertEquals(
"response percentile of endpoint Service_123 is lower than expected values", alarmMessages.get(0)
.getAlarmMessage());
}
@Test
......@@ -283,19 +285,19 @@ public class RunningRuleTest {
}
@Override
public int getId0() {
return id;
public String getId0() {
return "" + id;
}
@Override
public int getId1() {
return 0;
public String getId1() {
return Const.EMPTY_STRING;
}
@Override
public boolean equals(Object o) {
MetaInAlarm target = (MetaInAlarm) o;
return id == target.getId0();
return (id + "").equals(target.getId0());
}
@Override
......
......@@ -66,8 +66,8 @@ public class GRPChookCallbackTest {
private void mockAlarmMessage() {
AlarmMessage alarmMessage = new AlarmMessage();
alarmMessage.setId0(1);
alarmMessage.setId1(2);
alarmMessage.setId0("1");
alarmMessage.setId1("2");
alarmMessage.setScope(Scope.Service.name());
alarmMessage.setName("mock alarm message");
alarmMessage.setAlarmMessage("message");
......
......@@ -21,6 +21,7 @@ package org.apache.skywalking.oap.server.core;
public class Const {
public static final int NONE = 0;
public static final String ID_SPLIT = "_";
public static final String ID_PARSER_SPLIT = "\\_";
public static final String LINE = "-";
public static final String SPACE = " ";
public static final String KEY_VALUE_SPLIT = ",";
......@@ -28,7 +29,7 @@ public class Const {
public static final String ARRAY_PARSER_SPLIT = "\\|";
public static final int USER_SERVICE_ID = 1;
public static final int USER_INSTANCE_ID = 1;
public static final int USER_ENDPOINT_ID = 1;
public static final String USER_ENDPOINT_NAME = "User";
public static final int INEXISTENCE_ENDPOINT_ID = -1;
public static final String USER_CODE = "User";
public static final String SEGMENT_SPAN_SPLIT = "S";
......
......@@ -20,7 +20,6 @@ package org.apache.skywalking.oap.server.core;
import java.util.ArrayList;
import java.util.List;
import org.apache.skywalking.oap.server.core.cache.EndpointInventoryCache;
import org.apache.skywalking.oap.server.core.cache.NetworkAddressInventoryCache;
import org.apache.skywalking.oap.server.core.cache.ProfileTaskCache;
import org.apache.skywalking.oap.server.core.cache.ServiceInstanceInventoryCache;
......@@ -39,7 +38,6 @@ import org.apache.skywalking.oap.server.core.query.ProfileTaskQueryService;
import org.apache.skywalking.oap.server.core.query.TopNRecordsQueryService;
import org.apache.skywalking.oap.server.core.query.TopologyQueryService;
import org.apache.skywalking.oap.server.core.query.TraceQueryService;
import org.apache.skywalking.oap.server.core.register.service.IEndpointInventoryRegister;
import org.apache.skywalking.oap.server.core.register.service.INetworkAddressInventoryRegister;
import org.apache.skywalking.oap.server.core.register.service.IServiceInstanceInventoryRegister;
import org.apache.skywalking.oap.server.core.register.service.IServiceInventoryRegister;
......@@ -122,14 +120,12 @@ public class CoreModule extends ModuleDefine {
private void addRegisterService(List<Class> classes) {
classes.add(IServiceInventoryRegister.class);
classes.add(IServiceInstanceInventoryRegister.class);
classes.add(IEndpointInventoryRegister.class);
classes.add(INetworkAddressInventoryRegister.class);
}
private void addCacheService(List<Class> classes) {
classes.add(ServiceInventoryCache.class);
classes.add(ServiceInstanceInventoryCache.class);
classes.add(EndpointInventoryCache.class);
classes.add(NetworkAddressInventoryCache.class);
}
......
......@@ -30,7 +30,6 @@ import org.apache.skywalking.oap.server.core.analysis.worker.MetricsStreamProces
import org.apache.skywalking.oap.server.core.analysis.worker.TopNStreamProcessor;
import org.apache.skywalking.oap.server.core.annotation.AnnotationScan;
import org.apache.skywalking.oap.server.core.cache.CacheUpdateTimer;
import org.apache.skywalking.oap.server.core.cache.EndpointInventoryCache;
import org.apache.skywalking.oap.server.core.cache.NetworkAddressInventoryCache;
import org.apache.skywalking.oap.server.core.cache.ProfileTaskCache;
import org.apache.skywalking.oap.server.core.cache.ServiceInstanceInventoryCache;
......@@ -55,8 +54,6 @@ import org.apache.skywalking.oap.server.core.query.ProfileTaskQueryService;
import org.apache.skywalking.oap.server.core.query.TopNRecordsQueryService;
import org.apache.skywalking.oap.server.core.query.TopologyQueryService;
import org.apache.skywalking.oap.server.core.query.TraceQueryService;
import org.apache.skywalking.oap.server.core.register.service.EndpointInventoryRegister;
import org.apache.skywalking.oap.server.core.register.service.IEndpointInventoryRegister;
import org.apache.skywalking.oap.server.core.register.service.INetworkAddressInventoryRegister;
import org.apache.skywalking.oap.server.core.register.service.IServiceInstanceInventoryRegister;
import org.apache.skywalking.oap.server.core.register.service.IServiceInventoryRegister;
......@@ -170,7 +167,8 @@ public class CoreModuleProvider extends ModuleProvider {
if (moduleConfig.isGRPCSslEnabled()) {
grpcServer = new GRPCServer(moduleConfig.getGRPCHost(), moduleConfig.getGRPCPort(),
Paths.get(moduleConfig.getGRPCSslCertChainPath()).toFile(),
Paths.get(moduleConfig.getGRPCSslKeyPath()).toFile());
Paths.get(moduleConfig.getGRPCSslKeyPath()).toFile()
);
} else {
grpcServer = new GRPCServer(moduleConfig.getGRPCHost(), moduleConfig.getGRPCPort());
}
......@@ -222,11 +220,6 @@ public class CoreModuleProvider extends ModuleProvider {
this.registerServiceImplementation(
IServiceInstanceInventoryRegister.class, new ServiceInstanceInventoryRegister(getManager()));
this.registerServiceImplementation(
EndpointInventoryCache.class, new EndpointInventoryCache(getManager(), moduleConfig));
this.registerServiceImplementation(
IEndpointInventoryRegister.class, new EndpointInventoryRegister(getManager()));
this.registerServiceImplementation(
NetworkAddressInventoryCache.class, new NetworkAddressInventoryCache(getManager(), moduleConfig));
this.registerServiceImplementation(
......@@ -254,7 +247,9 @@ public class CoreModuleProvider extends ModuleProvider {
if (moduleConfig.isGRPCSslEnabled()) {
this.remoteClientManager = new RemoteClientManager(getManager(), moduleConfig.getRemoteTimeout(),
Paths.get(moduleConfig.getGRPCSslTrustedCAPath()).toFile());
Paths.get(moduleConfig.getGRPCSslTrustedCAPath())
.toFile()
);
} else {
this.remoteClientManager = new RemoteClientManager(getManager(), moduleConfig.getRemoteTimeout());
}
......
......@@ -34,8 +34,8 @@ public class AlarmMessage {
private int scopeId;
private String scope;
private String name;
private int id0;
private int id1;
private String id0;
private String id1;
private String ruleName;
private String alarmMessage;
private long startTime;
......
......@@ -57,9 +57,9 @@ public class AlarmRecord extends Record {
@Column(columnName = NAME)
private String name;
@Column(columnName = ID0)
private int id0;
private String id0;
@Column(columnName = ID1)
private int id1;
private String id1;
@Column(columnName = START_TIME)
private long startTime;
@Column(columnName = ALARM_MESSAGE, matchQuery = true)
......@@ -85,8 +85,8 @@ public class AlarmRecord extends Record {
AlarmRecord record = new AlarmRecord();
record.setScope(((Number) dbMap.get(SCOPE)).intValue());
record.setName((String) dbMap.get(NAME));
record.setId0(((Number) dbMap.get(ID0)).intValue());
record.setId1(((Number) dbMap.get(ID1)).intValue());
record.setId0((String) dbMap.get(ID0));
record.setId1((String) dbMap.get(ID1));
record.setAlarmMessage((String) dbMap.get(ALARM_MESSAGE));
record.setStartTime(((Number) dbMap.get(START_TIME)).longValue());
record.setTimeBucket(((Number) dbMap.get(TIME_BUCKET)).longValue());
......
......@@ -21,6 +21,7 @@ package org.apache.skywalking.oap.server.core.alarm;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import org.apache.skywalking.oap.server.core.Const;
import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
@Getter(AccessLevel.PUBLIC)
......@@ -28,7 +29,7 @@ import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
public class EndpointMetaInAlarm extends MetaInAlarm {
private String metricsName;
private int id;
private String id;
private String name;
private String[] tags;
private String[] properties;
......@@ -44,12 +45,12 @@ public class EndpointMetaInAlarm extends MetaInAlarm {
}
@Override
public int getId0() {
public String getId0() {
return id;
}
@Override
public int getId1() {
return 0;
public String getId1() {
return Const.EMPTY_STRING;
}
}
......@@ -36,12 +36,12 @@ public abstract class MetaInAlarm {
*
* @return the primary id.
*/
public abstract int getId0();
public abstract String getId0();
/**
* Only exist in multiple IDs case, Such as ServiceRelation, id1 represents the dest service id
*/
public abstract int getId1();
public abstract String getId1();
@Override
public boolean equals(Object o) {
......@@ -50,7 +50,7 @@ public abstract class MetaInAlarm {
if (o == null || getClass() != o.getClass())
return false;
MetaInAlarm that = (MetaInAlarm) o;
return getId0() == that.getId0() && getId1() == that.getId1();
return getId0().equals(that.getId0()) && getId1().equals(that.getId1());
}
@Override
......
......@@ -21,6 +21,7 @@ package org.apache.skywalking.oap.server.core.alarm;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import org.apache.skywalking.oap.server.core.Const;
import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
@Getter(AccessLevel.PUBLIC)
......@@ -28,7 +29,7 @@ import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
public class ServiceInstanceMetaInAlarm extends MetaInAlarm {
private String metricsName;
private int id;
private String id;
private String name;
private String[] tags;
private String[] properties;
......@@ -44,12 +45,12 @@ public class ServiceInstanceMetaInAlarm extends MetaInAlarm {
}
@Override
public int getId0() {
public String getId0() {
return id;
}
@Override
public int getId1() {
return 0;
public String getId1() {
return Const.EMPTY_STRING;
}
}
......@@ -21,6 +21,7 @@ package org.apache.skywalking.oap.server.core.alarm;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import org.apache.skywalking.oap.server.core.Const;
import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
@Getter(AccessLevel.PUBLIC)
......@@ -28,7 +29,7 @@ import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
public class ServiceMetaInAlarm extends MetaInAlarm {
private String metricsName;
private int id;
private String id;
private String name;
private String[] tags;
private String[] properties;
......@@ -44,12 +45,12 @@ public class ServiceMetaInAlarm extends MetaInAlarm {
}
@Override
public int getId0() {
public String getId0() {
return id;
}
@Override
public int getId1() {
return 0;
public String getId1() {
return Const.EMPTY_STRING;
}
}
......@@ -59,4 +59,9 @@ public @interface Stream {
* InventoryStreamProcessor}, {@link TopNStreamProcessor} and {@link NoneStreamingProcessor} for more details.
*/
Class<? extends StreamProcessor> processor();
/**
* @return true if this metrics stream support down sampling.
*/
boolean supportDownSampling() default true;
}
......@@ -18,12 +18,20 @@
package org.apache.skywalking.oap.server.core.analysis.manual;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.skywalking.oap.server.core.Const;
import org.apache.skywalking.oap.server.core.UnexpectedException;
public class RelationDefineUtil {
/**
* @return the service or instance relationship string id.
*/
public static String buildEntityId(RelationDefine define) {
return String.valueOf(define.source) + Const.ID_SPLIT + String.valueOf(define.dest) + Const.ID_SPLIT + String.valueOf(define.componentId);
return define.source + Const.ID_SPLIT + define.dest + Const.ID_SPLIT + define.componentId;
}
/**
......@@ -37,16 +45,54 @@ public class RelationDefineUtil {
return new RelationDefine(Integer.parseInt(parts[0]), Integer.parseInt(parts[1]), Integer.parseInt(parts[2]));
}
/**
* @return the endpoint relationship string id.
*/
public static String buildEndpointRelationEntityId(EndpointRelationDefine define) {
return define.sourceServiceId
+ Const.ID_SPLIT
+ new String(
Base64.getEncoder().encode(define.source.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8)
+ Const.ID_SPLIT
+ define.destServiceId
+ Const.ID_SPLIT
+ new String(
Base64.getEncoder().encode(define.dest.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8)
+ Const.ID_SPLIT
+ define.componentId;
}
public static EndpointRelationDefine splitEndpointRelationEntityId(String entityId) {
String[] parts = entityId.split(Const.ID_SPLIT);
if (parts.length != 5) {
throw new UnexpectedException("Illegal endpoint Relation entity id, " + entityId);
}
return new EndpointRelationDefine(
Integer.parseInt(parts[0]),
new String(Base64.getDecoder().decode(parts[1]), StandardCharsets.UTF_8),
Integer.parseInt(parts[2]),
new String(Base64.getDecoder().decode(parts[3]), StandardCharsets.UTF_8),
Integer.parseInt(parts[4])
);
}
@RequiredArgsConstructor
@Getter
@EqualsAndHashCode
public static class RelationDefine {
private int source;
private int dest;
private int componentId;
public RelationDefine(int source, int dest, int componentId) {
this.source = source;
this.dest = dest;
this.componentId = componentId;
}
private final int source;
private final int dest;
private final int componentId;
}
@RequiredArgsConstructor
@Getter
@EqualsAndHashCode
public static class EndpointRelationDefine {
private final int sourceServiceId;
private final String source;
private final int destServiceId;
private final String dest;
private final int componentId;
}
}
......@@ -16,29 +16,37 @@
*
*/
package org.apache.skywalking.oap.server.core.register;
package org.apache.skywalking.oap.server.core.analysis.manual.endpoint;
import com.google.common.base.Strings;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.apache.skywalking.oap.server.core.Const;
import org.apache.skywalking.oap.server.core.UnexpectedException;
import org.apache.skywalking.oap.server.core.analysis.Stream;
import org.apache.skywalking.oap.server.core.register.worker.InventoryStreamProcessor;
import org.apache.skywalking.oap.server.core.analysis.metrics.Metrics;
import org.apache.skywalking.oap.server.core.analysis.worker.MetricsStreamProcessor;
import org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData;
import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
import org.apache.skywalking.oap.server.core.source.DetectPoint;
import org.apache.skywalking.oap.server.core.source.ScopeDeclaration;
import org.apache.skywalking.oap.server.core.storage.StorageBuilder;
import org.apache.skywalking.oap.server.core.storage.annotation.Column;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.ENDPOINT_INVENTORY;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.ENDPOINT_TRAFFIC;
@ScopeDeclaration(id = ENDPOINT_INVENTORY, name = "EndpointInventory")
@Stream(name = EndpointInventory.INDEX_NAME, scopeId = DefaultScopeDefine.ENDPOINT_INVENTORY, builder = EndpointInventory.Builder.class, processor = InventoryStreamProcessor.class)
public class EndpointInventory extends RegisterSource {
@ScopeDeclaration(id = ENDPOINT_TRAFFIC, name = "EndpointTraffic")
@Stream(name = EndpointTraffic.INDEX_NAME, scopeId = DefaultScopeDefine.ENDPOINT_TRAFFIC,
builder = EndpointTraffic.Builder.class, processor = MetricsStreamProcessor.class,
supportDownSampling = false)
public class EndpointTraffic extends Metrics {
public static final String INDEX_NAME = "endpoint_inventory";
public static final String INDEX_NAME = "endpoint_traffic";
public static final String SERVICE_ID = "service_id";
public static final String NAME = "name";
......@@ -57,21 +65,59 @@ public class EndpointInventory extends RegisterSource {
@Column(columnName = DETECT_POINT)
private int detectPoint;
public static String buildId(int serviceId, String endpointName, int detectPoint) {
return serviceId + Const.ID_SPLIT + endpointName + Const.ID_SPLIT + detectPoint;
public static String buildId(int serviceId, String endpointName, DetectPoint detectPoint) {
return buildId(serviceId, endpointName, detectPoint.value());
}
public static String buildId(EndpointTraffic endpointTraffic) {
return buildId(endpointTraffic.serviceId, endpointTraffic.name, endpointTraffic.detectPoint);
}
private static String buildId(int serviceId, String endpointName, int detectPoint) {
return serviceId + Const.ID_SPLIT
+ new String(
Base64.getEncoder().encode(endpointName.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8)
+ Const.ID_SPLIT + detectPoint;
}
/**
* @param id in the storage of endpoint traffic
* @return [serviceId, endpointName, detectPoint]
*/
public static EndpointID splitID(String id) {
final String[] strings = id.split(Const.ID_PARSER_SPLIT);
if (strings.length != 3) {
throw new UnexpectedException("Can't split endpoint id into 3 parts, " + id);
}
return new EndpointID(
Integer.parseInt(strings[0]), new String(Base64.getDecoder().decode(strings[1]), StandardCharsets.UTF_8),
DetectPoint.valueOf(Integer.parseInt(strings[2]))
);
}
@RequiredArgsConstructor
public static class EndpointID {
@Getter
private final int serviceId;
@Getter
private final String endpointName;
@Getter
private final DetectPoint detectPoint;
}
@Override
public String id() {
return buildId(serviceId, name, detectPoint);
// Downgrade the time bucket to day level only.
// supportDownSampling == false for this entity.
String splitJointId = String.valueOf(getTimeBucket() / 10000);
splitJointId += Const.ID_SPLIT + buildId(this);
return splitJointId;
}
@Override
public int hashCode() {
int result = 17;
result = 31 * result + serviceId;
result = 31 * result + name.hashCode();
result = 31 * result + detectPoint;
result = 31 * result + buildId(this).hashCode();
return result;
}
......@@ -84,7 +130,7 @@ public class EndpointInventory extends RegisterSource {
if (getClass() != obj.getClass())
return false;
EndpointInventory source = (EndpointInventory) obj;
EndpointTraffic source = (EndpointTraffic) obj;
if (serviceId != source.getServiceId())
return false;
if (!name.equals(source.getName()))
......@@ -95,13 +141,10 @@ public class EndpointInventory extends RegisterSource {
@Override
public RemoteData.Builder serialize() {
RemoteData.Builder remoteBuilder = RemoteData.newBuilder();
remoteBuilder.addDataIntegers(getSequence());
remoteBuilder.addDataIntegers(serviceId);
remoteBuilder.addDataIntegers(detectPoint);
remoteBuilder.addDataLongs(getRegisterTime());
remoteBuilder.addDataLongs(getHeartbeatTime());
remoteBuilder.addDataLongs(getLastUpdateTime());
remoteBuilder.addDataLongs(getTimeBucket());
remoteBuilder.addDataStrings(Strings.isNullOrEmpty(name) ? Const.EMPTY_STRING : name);
return remoteBuilder;
......@@ -109,47 +152,67 @@ public class EndpointInventory extends RegisterSource {
@Override
public void deserialize(RemoteData remoteData) {
setSequence(remoteData.getDataIntegers(0));
setServiceId(remoteData.getDataIntegers(1));
setDetectPoint(remoteData.getDataIntegers(2));
setServiceId(remoteData.getDataIntegers(0));
setDetectPoint(remoteData.getDataIntegers(1));
setRegisterTime(remoteData.getDataLongs(0));
setHeartbeatTime(remoteData.getDataLongs(1));
setLastUpdateTime(remoteData.getDataLongs(2));
setTimeBucket(remoteData.getDataLongs(0));
setName(remoteData.getDataStrings(0));
}
@Override
public int remoteHashCode() {
return 0;
int result = 17;
result = 31 * result + serviceId;
result = 31 * result + name.hashCode();
result = 31 * result + detectPoint;
return result;
}
@Override
public void combine(final Metrics metrics) {
}
@Override
public void calculate() {
}
@Override
public Metrics toHour() {
return null;
}
@Override
public Metrics toDay() {
return null;
}
@Override
public Metrics toMonth() {
return null;
}
public static class Builder implements StorageBuilder<EndpointInventory> {
public static class Builder implements StorageBuilder<EndpointTraffic> {
@Override
public EndpointInventory map2Data(Map<String, Object> dbMap) {
EndpointInventory inventory = new EndpointInventory();
inventory.setSequence(((Number) dbMap.get(SEQUENCE)).intValue());
public EndpointTraffic map2Data(Map<String, Object> dbMap) {
EndpointTraffic inventory = new EndpointTraffic();
inventory.setServiceId(((Number) dbMap.get(SERVICE_ID)).intValue());
inventory.setName((String) dbMap.get(NAME));
inventory.setDetectPoint(((Number) dbMap.get(DETECT_POINT)).intValue());
inventory.setRegisterTime(((Number) dbMap.get(REGISTER_TIME)).longValue());
inventory.setHeartbeatTime(((Number) dbMap.get(HEARTBEAT_TIME)).longValue());
inventory.setLastUpdateTime(((Number) dbMap.get(LAST_UPDATE_TIME)).longValue());
inventory.setTimeBucket(((Number) dbMap.get(TIME_BUCKET)).longValue());
return inventory;
}
@Override
public Map<String, Object> data2Map(EndpointInventory storageData) {
public Map<String, Object> data2Map(EndpointTraffic storageData) {
Map<String, Object> map = new HashMap<>();
map.put(SEQUENCE, storageData.getSequence());
map.put(SERVICE_ID, storageData.getServiceId());
map.put(NAME, storageData.getName());
map.put(DETECT_POINT, storageData.getDetectPoint());
map.put(REGISTER_TIME, storageData.getRegisterTime());
map.put(HEARTBEAT_TIME, storageData.getHeartbeatTime());
map.put(LAST_UPDATE_TIME, storageData.getLastUpdateTime());
map.put(TIME_BUCKET, storageData.getTimeBucket());
return map;
}
}
......
......@@ -16,16 +16,26 @@
*
*/
package org.apache.skywalking.oap.server.core.register.service;
package org.apache.skywalking.oap.server.core.analysis.manual.endpoint;
import org.apache.skywalking.oap.server.core.analysis.SourceDispatcher;
import org.apache.skywalking.oap.server.core.analysis.worker.MetricsStreamProcessor;
import org.apache.skywalking.oap.server.core.source.DetectPoint;
import org.apache.skywalking.oap.server.library.module.Service;
import org.apache.skywalking.oap.server.core.source.Endpoint;
public interface IEndpointInventoryRegister extends Service {
public class EndpointTrafficDispatcher implements SourceDispatcher<Endpoint> {
int getOrCreate(int serviceId, String endpointName, DetectPoint detectPoint);
@Override
public void dispatch(final Endpoint source) {
generateTraffic(source);
}
int get(int serviceId, String endpointName, DetectPoint detectPoint);
void heartbeat(int endpointId, long heartBeatTime);
public void generateTraffic(final Endpoint source) {
EndpointTraffic traffic = new EndpointTraffic();
traffic.setTimeBucket(source.getTimeBucket());
traffic.setName(source.getName());
traffic.setServiceId(source.getServiceId());
traffic.setDetectPoint(DetectPoint.SERVER.value());
MetricsStreamProcessor.getInstance().in(traffic);
}
}
......@@ -19,7 +19,9 @@
package org.apache.skywalking.oap.server.core.analysis.manual.endpointrelation;
import org.apache.skywalking.oap.server.core.analysis.SourceDispatcher;
import org.apache.skywalking.oap.server.core.analysis.manual.endpoint.EndpointTraffic;
import org.apache.skywalking.oap.server.core.analysis.worker.MetricsStreamProcessor;
import org.apache.skywalking.oap.server.core.source.DetectPoint;
import org.apache.skywalking.oap.server.core.source.EndpointRelation;
public class EndpointCallRelationDispatcher implements SourceDispatcher<EndpointRelation> {
......@@ -36,10 +38,12 @@ public class EndpointCallRelationDispatcher implements SourceDispatcher<Endpoint
private void serverSide(EndpointRelation source) {
EndpointRelationServerSideMetrics metrics = new EndpointRelationServerSideMetrics();
metrics.setTimeBucket(source.getTimeBucket());
metrics.setSourceEndpointId(source.getEndpointId());
metrics.setDestEndpointId(source.getChildEndpointId());
metrics.setSourceEndpoint(
EndpointTraffic.buildId(source.getServiceId(), source.getEndpoint(), DetectPoint.SERVER));
metrics.setDestEndpoint(
EndpointTraffic.buildId(source.getChildServiceId(), source.getChildEndpoint(), DetectPoint.SERVER));
metrics.setComponentId(source.getComponentId());
metrics.buildEntityId();
metrics.setEntityId(source.getEntityId());
MetricsStreamProcessor.getInstance().in(metrics);
}
}
......@@ -20,7 +20,6 @@ package org.apache.skywalking.oap.server.core.analysis.manual.endpointrelation;
import java.util.HashMap;
import java.util.Map;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import org.apache.skywalking.oap.server.core.Const;
......@@ -37,26 +36,26 @@ import org.apache.skywalking.oap.server.core.storage.annotation.IDColumn;
public class EndpointRelationServerSideMetrics extends Metrics {
public static final String INDEX_NAME = "endpoint_relation_server_side";
public static final String SOURCE_ENDPOINT_ID = "source_endpoint_id";
public static final String DEST_ENDPOINT_ID = "dest_endpoint_id";
public static final String SOURCE_ENDPOINT = "source_endpoint";
public static final String DEST_ENDPOINT = "dest_endpoint";
public static final String COMPONENT_ID = "component_id";
@Setter
@Getter
@Column(columnName = SOURCE_ENDPOINT_ID)
@Column(columnName = SOURCE_ENDPOINT)
@IDColumn
private int sourceEndpointId;
private String sourceEndpoint;
@Setter
@Getter
@Column(columnName = DEST_ENDPOINT_ID)
@Column(columnName = DEST_ENDPOINT)
@IDColumn
private int destEndpointId;
private String destEndpoint;
@Setter
@Getter
@Column(columnName = COMPONENT_ID)
@IDColumn
private int componentId;
@Setter(AccessLevel.PRIVATE)
@Setter
@Getter
@Column(columnName = ENTITY_ID)
@IDColumn
......@@ -65,19 +64,10 @@ public class EndpointRelationServerSideMetrics extends Metrics {
@Override
public String id() {
String splitJointId = String.valueOf(getTimeBucket());
splitJointId += Const.ID_SPLIT + sourceEndpointId;
splitJointId += Const.ID_SPLIT + destEndpointId;
splitJointId += Const.ID_SPLIT + componentId;
splitJointId += Const.ID_SPLIT + entityId;
return splitJointId;
}
public void buildEntityId() {
String splitJointId = String.valueOf(sourceEndpointId);
splitJointId += Const.ID_SPLIT + String.valueOf(destEndpointId);
splitJointId += Const.ID_SPLIT + String.valueOf(componentId);
entityId = splitJointId;
}
@Override
public void combine(Metrics metrics) {
......@@ -92,8 +82,8 @@ public class EndpointRelationServerSideMetrics extends Metrics {
public Metrics toHour() {
EndpointRelationServerSideMetrics metrics = new EndpointRelationServerSideMetrics();
metrics.setTimeBucket(toTimeBucketInHour());
metrics.setSourceEndpointId(getSourceEndpointId());
metrics.setDestEndpointId(getDestEndpointId());
metrics.setSourceEndpoint(getSourceEndpoint());
metrics.setDestEndpoint(getDestEndpoint());
metrics.setComponentId(getComponentId());
metrics.setEntityId(getEntityId());
return metrics;
......@@ -103,8 +93,8 @@ public class EndpointRelationServerSideMetrics extends Metrics {
public Metrics toDay() {
EndpointRelationServerSideMetrics metrics = new EndpointRelationServerSideMetrics();
metrics.setTimeBucket(toTimeBucketInDay());
metrics.setSourceEndpointId(getSourceEndpointId());
metrics.setDestEndpointId(getDestEndpointId());
metrics.setSourceEndpoint(getSourceEndpoint());
metrics.setDestEndpoint(getDestEndpoint());
metrics.setComponentId(getComponentId());
metrics.setEntityId(getEntityId());
return metrics;
......@@ -114,8 +104,8 @@ public class EndpointRelationServerSideMetrics extends Metrics {
public Metrics toMonth() {
EndpointRelationServerSideMetrics metrics = new EndpointRelationServerSideMetrics();
metrics.setTimeBucket(toTimeBucketInMonth());
metrics.setSourceEndpointId(getSourceEndpointId());
metrics.setDestEndpointId(getDestEndpointId());
metrics.setSourceEndpoint(getSourceEndpoint());
metrics.setDestEndpoint(getDestEndpoint());
metrics.setComponentId(getComponentId());
metrics.setEntityId(getEntityId());
return metrics;
......@@ -124,42 +114,42 @@ public class EndpointRelationServerSideMetrics extends Metrics {
@Override
public int remoteHashCode() {
int result = 17;
result = 31 * result + sourceEndpointId;
result = 31 * result + destEndpointId;
result = 31 * result + sourceEndpoint.hashCode();
result = 31 * result + destEndpoint.hashCode();
result = 31 * result + componentId;
return result;
}
@Override
public void deserialize(RemoteData remoteData) {
setSourceEndpointId(remoteData.getDataIntegers(0));
setDestEndpointId(remoteData.getDataIntegers(1));
setComponentId(remoteData.getDataIntegers(2));
setComponentId(remoteData.getDataIntegers(0));
setTimeBucket(remoteData.getDataLongs(0));
setEntityId(remoteData.getDataStrings(0));
setSourceEndpoint(remoteData.getDataStrings(1));
setDestEndpoint(remoteData.getDataStrings(2));
}
@Override
public RemoteData.Builder serialize() {
RemoteData.Builder remoteBuilder = RemoteData.newBuilder();
remoteBuilder.addDataIntegers(getSourceEndpointId());
remoteBuilder.addDataIntegers(getDestEndpointId());
remoteBuilder.addDataIntegers(getComponentId());
remoteBuilder.addDataLongs(getTimeBucket());
remoteBuilder.addDataStrings(getEntityId());
remoteBuilder.addDataStrings(getSourceEndpoint());
remoteBuilder.addDataStrings(getDestEndpoint());
return remoteBuilder;
}
@Override
public int hashCode() {
int result = 17;
result = 31 * result + sourceEndpointId;
result = 31 * result + destEndpointId;
result = 31 * result + sourceEndpoint.hashCode();
result = 31 * result + destEndpoint.hashCode();
result = 31 * result + componentId;
result = 31 * result + (int) getTimeBucket();
return result;
......@@ -175,9 +165,9 @@ public class EndpointRelationServerSideMetrics extends Metrics {
return false;
EndpointRelationServerSideMetrics metrics = (EndpointRelationServerSideMetrics) obj;
if (sourceEndpointId != metrics.sourceEndpointId)
if (!sourceEndpoint.equals(metrics.sourceEndpoint))
return false;
if (destEndpointId != metrics.destEndpointId)
if (!destEndpoint.equals(metrics.destEndpoint))
return false;
if (componentId != metrics.componentId)
return false;
......@@ -190,8 +180,8 @@ public class EndpointRelationServerSideMetrics extends Metrics {
@Override
public EndpointRelationServerSideMetrics map2Data(Map<String, Object> dbMap) {
EndpointRelationServerSideMetrics metrics = new EndpointRelationServerSideMetrics();
metrics.setSourceEndpointId(((Number) dbMap.get(SOURCE_ENDPOINT_ID)).intValue());
metrics.setDestEndpointId(((Number) dbMap.get(DEST_ENDPOINT_ID)).intValue());
metrics.setSourceEndpoint((String) dbMap.get(SOURCE_ENDPOINT));
metrics.setDestEndpoint((String) dbMap.get(DEST_ENDPOINT));
metrics.setComponentId(((Number) dbMap.get(COMPONENT_ID)).intValue());
metrics.setTimeBucket(((Number) dbMap.get(TIME_BUCKET)).longValue());
metrics.setEntityId((String) dbMap.get(ENTITY_ID));
......@@ -201,8 +191,8 @@ public class EndpointRelationServerSideMetrics extends Metrics {
@Override
public Map<String, Object> data2Map(EndpointRelationServerSideMetrics storageData) {
Map<String, Object> map = new HashMap<>();
map.put(SOURCE_ENDPOINT_ID, storageData.getSourceEndpointId());
map.put(DEST_ENDPOINT_ID, storageData.getDestEndpointId());
map.put(SOURCE_ENDPOINT, storageData.getSourceEndpoint());
map.put(DEST_ENDPOINT, storageData.getDestEndpoint());
map.put(COMPONENT_ID, storageData.getComponentId());
map.put(TIME_BUCKET, storageData.getTimeBucket());
map.put(ENTITY_ID, storageData.getEntityId());
......
......@@ -32,6 +32,7 @@ public abstract class AbstractLogRecord extends Record {
public static final String SERVICE_ID = "service_id";
public static final String SERVICE_INSTANCE_ID = "service_instance_id";
public static final String ENDPOINT_NAME = "endpoint_name";
public static final String ENDPOINT_ID = "endpoint_id";
public static final String TRACE_ID = "trace_id";
public static final String IS_ERROR = "is_error";
......@@ -51,7 +52,11 @@ public abstract class AbstractLogRecord extends Record {
@Setter
@Getter
@Column(columnName = ENDPOINT_ID)
private int endpointId;
private String endpointId;
@Setter
@Getter
@Column(columnName = ENDPOINT_NAME)
private String endpointName;
@Setter
@Getter
@Column(columnName = TRACE_ID)
......@@ -86,7 +91,8 @@ public abstract class AbstractLogRecord extends Record {
protected void map2Data(T record, Map<String, Object> dbMap) {
record.setServiceId(((Number) dbMap.get(SERVICE_ID)).intValue());
record.setServiceInstanceId(((Number) dbMap.get(SERVICE_INSTANCE_ID)).intValue());
record.setEndpointId(((Number) dbMap.get(ENDPOINT_ID)).intValue());
record.setEndpointId((String) dbMap.get(ENDPOINT_ID));
record.setEndpointName((String) dbMap.get(ENDPOINT_NAME));
record.setIsError(((Number) dbMap.get(IS_ERROR)).intValue());
record.setTraceId((String) dbMap.get(TRACE_ID));
record.setStatusCode((String) dbMap.get(STATUS_CODE));
......@@ -102,6 +108,7 @@ public abstract class AbstractLogRecord extends Record {
map.put(SERVICE_ID, record.getServiceId());
map.put(SERVICE_INSTANCE_ID, record.getServiceInstanceId());
map.put(ENDPOINT_ID, record.getEndpointId());
map.put(ENDPOINT_NAME, record.getEndpointName());
map.put(TRACE_ID, record.getTraceId());
map.put(IS_ERROR, record.getIsError());
map.put(STATUS_CODE, record.getStatusCode());
......
......@@ -32,6 +32,7 @@ public class HTTPAccessLogDispatcher implements SourceDispatcher<HTTPAccessLog>
record.setServiceId(source.getServiceId());
record.setServiceInstanceId(source.getServiceInstanceId());
record.setEndpointId(source.getEndpointId());
record.setEndpointName(source.getEndpointName());
record.setTraceId(source.getTraceId());
record.setIsError(source.getIsError());
record.setStatusCode(source.getStatusCode());
......
......@@ -71,10 +71,8 @@ public class ServiceRelationClientSideMetrics extends Metrics {
}
public void buildEntityId() {
String splitJointId = String.valueOf(sourceServiceId);
splitJointId += Const.ID_SPLIT + String.valueOf(destServiceId);
splitJointId += Const.ID_SPLIT + String.valueOf(componentId);
entityId = splitJointId;
entityId = RelationDefineUtil.buildEntityId(
new RelationDefineUtil.RelationDefine(sourceServiceId, destServiceId, componentId));
}
@Override
......
......@@ -66,15 +66,14 @@ public class ServiceRelationServerSideMetrics extends Metrics {
@Override
public String id() {
String splitJointId = String.valueOf(getTimeBucket());
splitJointId += Const.ID_SPLIT + RelationDefineUtil.buildEntityId(new RelationDefineUtil.RelationDefine(sourceServiceId, destServiceId, componentId));
splitJointId += Const.ID_SPLIT + RelationDefineUtil.buildEntityId(
new RelationDefineUtil.RelationDefine(sourceServiceId, destServiceId, componentId));
return splitJointId;
}
public void buildEntityId() {
String splitJointId = String.valueOf(sourceServiceId);
splitJointId += Const.ID_SPLIT + String.valueOf(destServiceId);
splitJointId += Const.ID_SPLIT + String.valueOf(componentId);
entityId = splitJointId;
entityId = RelationDefineUtil.buildEntityId(
new RelationDefineUtil.RelationDefine(sourceServiceId, destServiceId, componentId));
}
@Override
......
......@@ -73,7 +73,7 @@ public class SegmentRecord extends Record {
@Setter
@Getter
@Column(columnName = ENDPOINT_ID)
private int endpointId;
private String endpointId;
@Setter
@Getter
@Column(columnName = START_TIME)
......@@ -137,7 +137,7 @@ public class SegmentRecord extends Record {
record.setServiceId(((Number) dbMap.get(SERVICE_ID)).intValue());
record.setServiceInstanceId(((Number) dbMap.get(SERVICE_INSTANCE_ID)).intValue());
record.setEndpointName((String) dbMap.get(ENDPOINT_NAME));
record.setEndpointId(((Number) dbMap.get(ENDPOINT_ID)).intValue());
record.setEndpointId((String) dbMap.get(ENDPOINT_ID));
record.setStartTime(((Number) dbMap.get(START_TIME)).longValue());
record.setEndTime(((Number) dbMap.get(END_TIME)).longValue());
record.setLatency(((Number) dbMap.get(LATENCY)).intValue());
......
......@@ -113,24 +113,27 @@ public class MetricsStreamProcessor implements StreamProcessor<Metrics> {
MetricsPersistentWorker dayPersistentWorker = null;
MetricsPersistentWorker monthPersistentWorker = null;
if (configService.shouldToHour()) {
Model model = modelSetter.putIfAbsent(
metricsClass, stream.scopeId(), new Storage(stream.name(), true, true, Downsampling.Hour), false);
hourPersistentWorker = worker(moduleDefineHolder, metricsDAO, model);
MetricsTransWorker transWorker = null;
if (stream.supportDownSampling()) {
if (configService.shouldToHour()) {
Model model = modelSetter.putIfAbsent(
metricsClass, stream.scopeId(), new Storage(stream.name(), true, true, Downsampling.Hour), false);
hourPersistentWorker = worker(moduleDefineHolder, metricsDAO, model);
}
if (configService.shouldToDay()) {
Model model = modelSetter.putIfAbsent(
metricsClass, stream.scopeId(), new Storage(stream.name(), true, true, Downsampling.Day), false);
dayPersistentWorker = worker(moduleDefineHolder, metricsDAO, model);
}
if (configService.shouldToMonth()) {
Model model = modelSetter.putIfAbsent(
metricsClass, stream.scopeId(), new Storage(stream.name(), true, true, Downsampling.Month), false);
monthPersistentWorker = worker(moduleDefineHolder, metricsDAO, model);
}
transWorker = new MetricsTransWorker(
moduleDefineHolder, stream.name(), hourPersistentWorker, dayPersistentWorker, monthPersistentWorker);
}
if (configService.shouldToDay()) {
Model model = modelSetter.putIfAbsent(
metricsClass, stream.scopeId(), new Storage(stream.name(), true, true, Downsampling.Day), false);
dayPersistentWorker = worker(moduleDefineHolder, metricsDAO, model);
}
if (configService.shouldToMonth()) {
Model model = modelSetter.putIfAbsent(
metricsClass, stream.scopeId(), new Storage(stream.name(), true, true, Downsampling.Month), false);
monthPersistentWorker = worker(moduleDefineHolder, metricsDAO, model);
}
MetricsTransWorker transWorker = new MetricsTransWorker(
moduleDefineHolder, stream.name(), hourPersistentWorker, dayPersistentWorker, monthPersistentWorker);
Model model = modelSetter.putIfAbsent(
metricsClass, stream.scopeId(), new Storage(stream.name(), true, true, Downsampling.Minute), false);
......
/*
* 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.server.core.cache;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import java.util.Objects;
import org.apache.skywalking.oap.server.core.Const;
import org.apache.skywalking.oap.server.core.CoreModuleConfig;
import org.apache.skywalking.oap.server.core.register.EndpointInventory;
import org.apache.skywalking.oap.server.core.storage.StorageModule;
import org.apache.skywalking.oap.server.core.storage.cache.IEndpointInventoryCacheDAO;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
import org.apache.skywalking.oap.server.library.module.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static java.util.Objects.isNull;
import static java.util.Objects.nonNull;
public class EndpointInventoryCache implements Service {
private static final Logger logger = LoggerFactory.getLogger(EndpointInventoryCache.class);
private final ModuleManager moduleManager;
private final EndpointInventory userEndpoint;
private final Cache<String, Integer> endpointNameCache;
private final Cache<Integer, EndpointInventory> endpointIdCache;
private IEndpointInventoryCacheDAO cacheDAO;
public EndpointInventoryCache(ModuleManager moduleManager, CoreModuleConfig moduleConfig) {
this.moduleManager = moduleManager;
this.userEndpoint = new EndpointInventory();
this.userEndpoint.setSequence(Const.USER_ENDPOINT_ID);
this.userEndpoint.setName(Const.USER_CODE);
this.userEndpoint.setServiceId(Const.USER_SERVICE_ID);
long initialSize = moduleConfig.getMaxSizeOfEndpointInventory() / 10L;
int initialCapacitySize = (int) (initialSize > Integer.MAX_VALUE ? Integer.MAX_VALUE : initialSize);
endpointNameCache = CacheBuilder.newBuilder()
.initialCapacity(initialCapacitySize)
.maximumSize(moduleConfig.getMaxSizeOfEndpointInventory())
.build();
endpointIdCache = CacheBuilder.newBuilder()
.initialCapacity(initialCapacitySize)
.maximumSize(moduleConfig.getMaxSizeOfEndpointInventory())
.build();
}
private IEndpointInventoryCacheDAO getCacheDAO() {
if (isNull(cacheDAO)) {
cacheDAO = moduleManager.find(StorageModule.NAME).provider().getService(IEndpointInventoryCacheDAO.class);
}
return cacheDAO;
}
public int getEndpointId(int serviceId, String endpointName, int detectPoint) {
String id = EndpointInventory.buildId(serviceId, endpointName, detectPoint);
Integer endpointId = endpointNameCache.getIfPresent(id);
if (Objects.isNull(endpointId) || endpointId == Const.NONE) {
endpointId = getCacheDAO().getEndpointId(serviceId, endpointName, detectPoint);
if (endpointId != Const.NONE) {
endpointNameCache.put(id, endpointId);
}
}
return endpointId;
}
public EndpointInventory get(int endpointId) {
if (Const.USER_ENDPOINT_ID == endpointId) {
return userEndpoint;
}
EndpointInventory endpointInventory = endpointIdCache.getIfPresent(endpointId);
if (isNull(endpointInventory)) {
endpointInventory = getCacheDAO().get(endpointId);
if (nonNull(endpointInventory)) {
endpointIdCache.put(endpointId, endpointInventory);
} else {
logger.warn("EndpointInventory id {} is not in cache and persistent storage.", endpointId);
}
}
return endpointInventory;
}
}
......@@ -22,12 +22,11 @@ import java.io.IOException;
import java.util.List;
import org.apache.skywalking.oap.server.core.CoreModule;
import org.apache.skywalking.oap.server.core.analysis.Downsampling;
import org.apache.skywalking.oap.server.core.cache.EndpointInventoryCache;
import org.apache.skywalking.oap.server.core.analysis.manual.endpoint.EndpointTraffic;
import org.apache.skywalking.oap.server.core.cache.ServiceInstanceInventoryCache;
import org.apache.skywalking.oap.server.core.cache.ServiceInventoryCache;
import org.apache.skywalking.oap.server.core.query.entity.Order;
import org.apache.skywalking.oap.server.core.query.entity.TopNEntity;
import org.apache.skywalking.oap.server.core.register.EndpointInventory;
import org.apache.skywalking.oap.server.core.register.ServiceInstanceInventory;
import org.apache.skywalking.oap.server.core.register.ServiceInventory;
import org.apache.skywalking.oap.server.core.storage.StorageModule;
......@@ -55,8 +54,9 @@ public class AggregationQueryService implements Service {
}
public List<TopNEntity> getServiceTopN(final String indName, final int topN, final Downsampling downsampling,
final long startTB, final long endTB, final Order order) throws IOException {
List<TopNEntity> topNEntities = getAggregationQueryDAO().getServiceTopN(indName, ValueColumnMetadata.INSTANCE.getValueCName(indName), topN, downsampling, startTB, endTB, order);
final long startTB, final long endTB, final Order order) throws IOException {
List<TopNEntity> topNEntities = getAggregationQueryDAO().getServiceTopN(
indName, ValueColumnMetadata.INSTANCE.getValueCName(indName), topN, downsampling, startTB, endTB, order);
for (TopNEntity entity : topNEntities) {
ServiceInventory inventory = moduleManager.find(CoreModule.NAME)
.provider()
......@@ -69,10 +69,15 @@ public class AggregationQueryService implements Service {
return topNEntities;
}
public List<TopNEntity> getAllServiceInstanceTopN(final String indName, final int topN,
final Downsampling downsampling, final long startTB, final long endTB, final Order order) throws IOException {
List<TopNEntity> topNEntities = getAggregationQueryDAO().getAllServiceInstanceTopN(indName, ValueColumnMetadata.INSTANCE
.getValueCName(indName), topN, downsampling, startTB, endTB, order);
public List<TopNEntity> getAllServiceInstanceTopN(final String indName,
final int topN,
final Downsampling downsampling,
final long startTB,
final long endTB,
final Order order) throws IOException {
List<TopNEntity> topNEntities = getAggregationQueryDAO().getAllServiceInstanceTopN(
indName, ValueColumnMetadata.INSTANCE
.getValueCName(indName), topN, downsampling, startTB, endTB, order);
for (TopNEntity entity : topNEntities) {
ServiceInstanceInventory inventory = moduleManager.find(CoreModule.NAME)
.provider()
......@@ -85,10 +90,16 @@ public class AggregationQueryService implements Service {
return topNEntities;
}
public List<TopNEntity> getServiceInstanceTopN(final int serviceId, final String indName, final int topN,
final Downsampling downsampling, final long startTB, final long endTB, final Order order) throws IOException {
List<TopNEntity> topNEntities = getAggregationQueryDAO().getServiceInstanceTopN(serviceId, indName, ValueColumnMetadata.INSTANCE
.getValueCName(indName), topN, downsampling, startTB, endTB, order);
public List<TopNEntity> getServiceInstanceTopN(final int serviceId,
final String indName,
final int topN,
final Downsampling downsampling,
final long startTB,
final long endTB,
final Order order) throws IOException {
List<TopNEntity> topNEntities = getAggregationQueryDAO().getServiceInstanceTopN(
serviceId, indName, ValueColumnMetadata.INSTANCE
.getValueCName(indName), topN, downsampling, startTB, endTB, order);
for (TopNEntity entity : topNEntities) {
ServiceInstanceInventory inventory = moduleManager.find(CoreModule.NAME)
.provider()
......@@ -101,33 +112,33 @@ public class AggregationQueryService implements Service {
return topNEntities;
}
public List<TopNEntity> getAllEndpointTopN(final String indName, final int topN, final Downsampling downsampling,
final long startTB, final long endTB, final Order order) throws IOException {
List<TopNEntity> topNEntities = getAggregationQueryDAO().getAllEndpointTopN(indName, ValueColumnMetadata.INSTANCE.getValueCName(indName), topN, downsampling, startTB, endTB, order);
public List<TopNEntity> getAllEndpointTopN(final String indName,
final int topN,
final Downsampling downsampling,
final long startTB,
final long endTB,
final Order order) throws IOException {
List<TopNEntity> topNEntities = getAggregationQueryDAO().getAllEndpointTopN(
indName, ValueColumnMetadata.INSTANCE.getValueCName(indName), topN, downsampling, startTB, endTB, order);
for (TopNEntity entity : topNEntities) {
EndpointInventory inventory = moduleManager.find(CoreModule.NAME)
.provider()
.getService(EndpointInventoryCache.class)
.get(Integer.parseInt(entity.getId()));
if (inventory != null) {
entity.setName(inventory.getName());
}
entity.setName(EndpointTraffic.splitID(entity.getId()).getEndpointName());
}
return topNEntities;
}
public List<TopNEntity> getEndpointTopN(final int serviceId, final String indName, final int topN,
final Downsampling downsampling, final long startTB, final long endTB, final Order order) throws IOException {
List<TopNEntity> topNEntities = getAggregationQueryDAO().getEndpointTopN(serviceId, indName, ValueColumnMetadata.INSTANCE
.getValueCName(indName), topN, downsampling, startTB, endTB, order);
public List<TopNEntity> getEndpointTopN(final int serviceId,
final String indName,
final int topN,
final Downsampling downsampling,
final long startTB,
final long endTB,
final Order order) throws IOException {
List<TopNEntity> topNEntities = getAggregationQueryDAO().getEndpointTopN(
serviceId, indName, ValueColumnMetadata.INSTANCE
.getValueCName(indName), topN, downsampling, startTB, endTB, order);
for (TopNEntity entity : topNEntities) {
EndpointInventory inventory = moduleManager.find(CoreModule.NAME)
.provider()
.getService(EndpointInventoryCache.class)
.get(Integer.parseInt(entity.getId()));
if (inventory != null) {
entity.setName(inventory.getName());
}
entity.setName(EndpointTraffic.splitID(entity.getId()).getEndpointName());
}
return topNEntities;
}
......
......@@ -21,7 +21,6 @@ package org.apache.skywalking.oap.server.core.query;
import java.io.IOException;
import org.apache.skywalking.oap.server.core.Const;
import org.apache.skywalking.oap.server.core.CoreModule;
import org.apache.skywalking.oap.server.core.cache.EndpointInventoryCache;
import org.apache.skywalking.oap.server.core.cache.ServiceInstanceInventoryCache;
import org.apache.skywalking.oap.server.core.cache.ServiceInventoryCache;
import org.apache.skywalking.oap.server.core.query.entity.LogState;
......@@ -38,7 +37,6 @@ public class LogQueryService implements Service {
private ILogQueryDAO logQueryDAO;
private ServiceInventoryCache serviceInventoryCache;
private ServiceInstanceInventoryCache serviceInstanceInventoryCache;
private EndpointInventoryCache endpointInventoryCache;
public LogQueryService(ModuleManager moduleManager) {
this.moduleManager = moduleManager;
......@@ -69,21 +67,21 @@ public class LogQueryService implements Service {
return serviceInstanceInventoryCache;
}
private EndpointInventoryCache getEndpointInventoryCache() {
if (endpointInventoryCache == null) {
this.endpointInventoryCache = moduleManager.find(CoreModule.NAME)
.provider()
.getService(EndpointInventoryCache.class);
}
return endpointInventoryCache;
}
public Logs queryLogs(final String metricName, int serviceId, int serviceInstanceId, int endpointId, String traceId,
LogState state, String stateCode, Pagination paging, final long startTB, final long endTB) throws IOException {
public Logs queryLogs(final String metricName,
int serviceId,
int serviceInstanceId,
String endpointId,
String traceId,
LogState state,
String stateCode,
Pagination paging,
final long startTB,
final long endTB) throws IOException {
PaginationUtils.Page page = PaginationUtils.INSTANCE.exchange(paging);
Logs logs = getLogQueryDAO().queryLogs(metricName, serviceId, serviceInstanceId, endpointId, traceId, state, stateCode, paging, page
.getFrom(), page.getLimit(), startTB, endTB);
Logs logs = getLogQueryDAO().queryLogs(
metricName, serviceId, serviceInstanceId, endpointId, traceId, state, stateCode, paging, page
.getFrom(), page.getLimit(), startTB, endTB);
logs.getLogs().forEach(log -> {
if (log.getServiceId() != Const.NONE) {
log.setServiceName(getServiceInventoryCache().get(log.getServiceId()).getName());
......@@ -92,9 +90,7 @@ public class LogQueryService implements Service {
log.setServiceInstanceName(getServiceInstanceInventoryCache().get(log.getServiceInstanceId())
.getName());
}
if (log.getEndpointId() != Const.NONE) {
log.setEndpointName(getEndpointInventoryCache().get(log.getEndpointId()).getName());
}
log.setEndpointId(log.getEndpointId());
});
return logs;
}
......
......@@ -21,7 +21,7 @@ package org.apache.skywalking.oap.server.core.query;
import java.io.IOException;
import java.util.List;
import org.apache.skywalking.oap.server.core.CoreModule;
import org.apache.skywalking.oap.server.core.cache.EndpointInventoryCache;
import org.apache.skywalking.oap.server.core.analysis.manual.endpoint.EndpointTraffic;
import org.apache.skywalking.oap.server.core.cache.ServiceInventoryCache;
import org.apache.skywalking.oap.server.core.query.entity.ClusterBrief;
import org.apache.skywalking.oap.server.core.query.entity.Database;
......@@ -29,7 +29,6 @@ import org.apache.skywalking.oap.server.core.query.entity.Endpoint;
import org.apache.skywalking.oap.server.core.query.entity.EndpointInfo;
import org.apache.skywalking.oap.server.core.query.entity.Service;
import org.apache.skywalking.oap.server.core.query.entity.ServiceInstance;
import org.apache.skywalking.oap.server.core.register.EndpointInventory;
import org.apache.skywalking.oap.server.core.register.NodeType;
import org.apache.skywalking.oap.server.core.storage.StorageModule;
import org.apache.skywalking.oap.server.core.storage.query.IMetadataQueryDAO;
......@@ -40,7 +39,6 @@ public class MetadataQueryService implements org.apache.skywalking.oap.server.li
private final ModuleManager moduleManager;
private IMetadataQueryDAO metadataQueryDAO;
private ServiceInventoryCache serviceInventoryCache;
private EndpointInventoryCache endpointInventoryCache;
public MetadataQueryService(ModuleManager moduleManager) {
this.moduleManager = moduleManager;
......@@ -62,15 +60,6 @@ public class MetadataQueryService implements org.apache.skywalking.oap.server.li
return serviceInventoryCache;
}
private EndpointInventoryCache getEndpointInventoryCache() {
if (endpointInventoryCache == null) {
endpointInventoryCache = moduleManager.find(CoreModule.NAME)
.provider()
.getService(EndpointInventoryCache.class);
}
return endpointInventoryCache;
}
public ClusterBrief getGlobalBrief(final long startTimestamp, final long endTimestamp) throws IOException {
ClusterBrief clusterBrief = new ClusterBrief();
clusterBrief.setNumOfService(getMetadataQueryDAO().numOfService(startTimestamp, endTimestamp));
......@@ -94,17 +83,17 @@ public class MetadataQueryService implements org.apache.skywalking.oap.server.li
}
public List<Service> searchServices(final long startTimestamp, final long endTimestamp,
final String keyword) throws IOException {
final String keyword) throws IOException {
return getMetadataQueryDAO().searchServices(startTimestamp, endTimestamp, keyword);
}
public List<ServiceInstance> getServiceInstances(final long startTimestamp, final long endTimestamp,
final String serviceId) throws IOException {
final String serviceId) throws IOException {
return getMetadataQueryDAO().getServiceInstances(startTimestamp, endTimestamp, serviceId);
}
public List<Endpoint> searchEndpoint(final String keyword, final String serviceId,
final int limit) throws IOException {
public List<Endpoint> searchEndpoint(final String keyword, final int serviceId,
final int limit) throws IOException {
return getMetadataQueryDAO().searchEndpoint(keyword, serviceId, limit);
}
......@@ -112,14 +101,15 @@ public class MetadataQueryService implements org.apache.skywalking.oap.server.li
return getMetadataQueryDAO().searchService(serviceCode);
}
public EndpointInfo getEndpointInfo(final int endpointId) throws IOException {
EndpointInventory endpointInventory = getEndpointInventoryCache().get(endpointId);
public EndpointInfo getEndpointInfo(final String endpointId) throws IOException {
final EndpointTraffic.EndpointID endpointID = EndpointTraffic.splitID(endpointId);
int serviceId = endpointID.getServiceId();
EndpointInfo endpointInfo = new EndpointInfo();
endpointInfo.setId(endpointInventory.getSequence());
endpointInfo.setName(endpointInventory.getName());
endpointInfo.setServiceId(endpointInventory.getServiceId());
endpointInfo.setServiceName(getServiceInventoryCache().get(endpointInventory.getServiceId()).getName());
endpointInfo.setId(endpointId);
endpointInfo.setName(endpointID.getEndpointName());
endpointInfo.setServiceId(serviceId);
endpointInfo.setServiceName(getServiceInventoryCache().get(serviceId).getName());
return endpointInfo;
}
}
......@@ -24,13 +24,10 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.skywalking.apm.network.language.agent.v2.SegmentObject;
import org.apache.skywalking.oap.server.core.Const;
import org.apache.skywalking.oap.server.core.CoreModule;
import org.apache.skywalking.oap.server.core.CoreModuleConfig;
import org.apache.skywalking.oap.server.core.analysis.manual.segment.SegmentRecord;
import org.apache.skywalking.oap.server.core.cache.EndpointInventoryCache;
import org.apache.skywalking.oap.server.core.cache.NetworkAddressInventoryCache;
import org.apache.skywalking.oap.server.core.cache.ServiceInstanceInventoryCache;
import org.apache.skywalking.oap.server.core.cache.ServiceInventoryCache;
......@@ -45,7 +42,6 @@ import org.apache.skywalking.oap.server.core.query.entity.ProfileTask;
import org.apache.skywalking.oap.server.core.query.entity.ProfileTaskLog;
import org.apache.skywalking.oap.server.core.query.entity.ProfiledSegment;
import org.apache.skywalking.oap.server.core.query.entity.ProfiledSpan;
import org.apache.skywalking.oap.server.core.register.EndpointInventory;
import org.apache.skywalking.oap.server.core.register.ServiceInstanceInventory;
import org.apache.skywalking.oap.server.core.register.ServiceInventory;
import org.apache.skywalking.oap.server.core.storage.StorageModule;
......@@ -57,7 +53,6 @@ import org.apache.skywalking.oap.server.library.module.Service;
import org.apache.skywalking.oap.server.library.util.CollectionUtils;
import static java.util.Objects.isNull;
import static java.util.Objects.nonNull;
/**
* handle profile task queries
......@@ -71,13 +66,15 @@ public class ProfileTaskQueryService implements Service {
private ServiceInstanceInventoryCache serviceInstanceInventoryCache;
private NetworkAddressInventoryCache networkAddressInventoryCache;
private IComponentLibraryCatalogService componentLibraryCatalogService;
private EndpointInventoryCache endpointInventoryCache;
private final ProfileAnalyzer profileAnalyzer;
public ProfileTaskQueryService(ModuleManager moduleManager, CoreModuleConfig moduleConfig) {
this.moduleManager = moduleManager;
this.profileAnalyzer = new ProfileAnalyzer(moduleManager, moduleConfig.getMaxPageSizeOfQueryProfileSnapshot(), moduleConfig.getMaxSizeOfAnalyzeProfileSnapshot());
this.profileAnalyzer = new ProfileAnalyzer(
moduleManager, moduleConfig.getMaxPageSizeOfQueryProfileSnapshot(),
moduleConfig.getMaxSizeOfAnalyzeProfileSnapshot()
);
}
private IProfileTaskQueryDAO getProfileTaskDAO() {
......@@ -143,15 +140,6 @@ public class ProfileTaskQueryService implements Service {
return componentLibraryCatalogService;
}
private EndpointInventoryCache getEndpointInventoryCache() {
if (endpointInventoryCache == null) {
this.endpointInventoryCache = moduleManager.find(CoreModule.NAME)
.provider()
.getService(EndpointInventoryCache.class);
}
return endpointInventoryCache;
}
/**
* search profile task list
*
......@@ -180,7 +168,8 @@ public class ProfileTaskQueryService implements Service {
// filter all task logs
task.setLogs(taskLogList.stream().filter(l -> Objects.equal(l.getTaskId(), task.getId())).map(l -> {
// get instance name from cache
final ServiceInstanceInventory instanceInventory = serviceInstanceInventoryCache.get(l.getInstanceId());
final ServiceInstanceInventory instanceInventory = serviceInstanceInventoryCache.get(
l.getInstanceId());
if (instanceInventory != null) {
l.setInstanceName(instanceInventory.getName());
}
......@@ -199,7 +188,8 @@ public class ProfileTaskQueryService implements Service {
return getProfileThreadSnapshotQueryDAO().queryProfiledSegments(taskId);
}
public ProfileAnalyzation getProfileAnalyze(final String segmentId, final List<ProfileAnalyzeTimeRange> timeRanges) throws IOException {
public ProfileAnalyzation getProfileAnalyze(final String segmentId,
final List<ProfileAnalyzeTimeRange> timeRanges) throws IOException {
return profileAnalyzer.analyze(segmentId, timeRanges);
}
......@@ -228,6 +218,7 @@ public class ProfileTaskQueryService implements Service {
span.setError(spanObject.getIsError());
span.setLayer(spanObject.getSpanLayer().name());
span.setType(spanObject.getSpanType().name());
span.setEndpointName(spanObject.getOperationName());
if (spanObject.getPeerId() == 0) {
span.setPeer(spanObject.getPeer());
......@@ -235,17 +226,6 @@ public class ProfileTaskQueryService implements Service {
span.setPeer(getNetworkAddressInventoryCache().get(spanObject.getPeerId()).getName());
}
String endpointName = spanObject.getOperationName();
if (spanObject.getOperationNameId() != 0) {
EndpointInventory endpointInventory = getEndpointInventoryCache().get(spanObject.getOperationNameId());
if (nonNull(endpointInventory)) {
endpointName = endpointInventory.getName();
} else {
endpointName = Const.EMPTY_STRING;
}
}
span.setEndpointName(endpointName);
final ServiceInventory serviceInventory = getServiceInventoryCache().get(segmentObject.getServiceId());
if (serviceInventory != null) {
span.setServiceCode(serviceInventory.getName());
......
......@@ -60,16 +60,14 @@ public class ServiceInstanceTopologyBuilder {
ServiceInstanceTopology build(List<Call.CallDetail> serviceInstanceRelationClientCalls,
List<Call.CallDetail> serviceInstanceRelationServerCalls) {
filterZeroSourceOrTargetReference(serviceInstanceRelationClientCalls);
filterZeroSourceOrTargetReference(serviceInstanceRelationServerCalls);
Map<Integer, ServiceInstanceNode> nodes = new HashMap<>();
List<Call> calls = new LinkedList<>();
HashMap<String, Call> callMap = new HashMap<>();
for (Call.CallDetail clientCall : serviceInstanceRelationClientCalls) {
ServiceInstanceInventory sourceInstance = serviceInstanceInventoryCache.get(clientCall.getSource());
ServiceInstanceInventory targetInstance = serviceInstanceInventoryCache.get(clientCall.getTarget());
ServiceInstanceInventory sourceInstance = serviceInstanceInventoryCache.get(Integer.parseInt(clientCall.getSource()));
ServiceInstanceInventory targetInstance = serviceInstanceInventoryCache.get(Integer.parseInt(clientCall.getTarget()));
if (isNull(sourceInstance) || isNull(targetInstance)) {
continue;
......@@ -113,8 +111,8 @@ public class ServiceInstanceTopologyBuilder {
}
for (Call.CallDetail serverCall : serviceInstanceRelationServerCalls) {
ServiceInstanceInventory sourceInstance = serviceInstanceInventoryCache.get(serverCall.getSource());
ServiceInstanceInventory targetInstance = serviceInstanceInventoryCache.get(serverCall.getTarget());
ServiceInstanceInventory sourceInstance = serviceInstanceInventoryCache.get(Integer.parseInt(serverCall.getSource()));
ServiceInstanceInventory targetInstance = serviceInstanceInventoryCache.get(Integer.parseInt(serverCall.getTarget()));
if (isNull(sourceInstance) || isNull(targetInstance)) {
continue;
......@@ -202,13 +200,4 @@ public class ServiceInstanceTopologyBuilder {
}
return instanceNode;
}
private void filterZeroSourceOrTargetReference(List<Call.CallDetail> serviceRelationClientCalls) {
for (int i = serviceRelationClientCalls.size() - 1; i >= 0; i--) {
Call.CallDetail call = serviceRelationClientCalls.get(i);
if (call.getSource() == 0 || call.getTarget() == 0) {
serviceRelationClientCalls.remove(i);
}
}
}
}
......@@ -55,16 +55,14 @@ class TopologyBuilder {
}
Topology build(List<Call.CallDetail> serviceRelationClientCalls, List<Call.CallDetail> serviceRelationServerCalls) {
filterZeroSourceOrTargetReference(serviceRelationClientCalls);
filterZeroSourceOrTargetReference(serviceRelationServerCalls);
Map<Integer, Node> nodes = new HashMap<>();
List<Call> calls = new LinkedList<>();
HashMap<String, Call> callMap = new HashMap<>();
for (Call.CallDetail clientCall : serviceRelationClientCalls) {
ServiceInventory source = serviceInventoryCache.get(clientCall.getSource());
ServiceInventory target = serviceInventoryCache.get(clientCall.getTarget());
ServiceInventory source = serviceInventoryCache.get(Integer.parseInt(clientCall.getSource()));
ServiceInventory target = serviceInventoryCache.get(Integer.parseInt(clientCall.getTarget()));
if (isNull(source) || isNull(target)) {
continue;
......@@ -107,8 +105,8 @@ class TopologyBuilder {
}
for (Call.CallDetail serverCall : serviceRelationServerCalls) {
ServiceInventory source = serviceInventoryCache.get(serverCall.getSource());
ServiceInventory target = serviceInventoryCache.get(serverCall.getTarget());
ServiceInventory source = serviceInventoryCache.get(Integer.parseInt(serverCall.getSource()));
ServiceInventory target = serviceInventoryCache.get(Integer.parseInt(serverCall.getTarget()));
if (isNull(source) || isNull(target)) {
continue;
......@@ -117,7 +115,7 @@ class TopologyBuilder {
if (source.getSequence() == Const.USER_SERVICE_ID) {
if (!nodes.containsKey(source.getSequence())) {
Node visualUserNode = new Node();
visualUserNode.setId(source.getSequence());
visualUserNode.setId(String.valueOf(source.getSequence()));
visualUserNode.setName(Const.USER_CODE);
visualUserNode.setType(Const.USER_CODE.toUpperCase());
visualUserNode.setReal(false);
......@@ -128,7 +126,7 @@ class TopologyBuilder {
if (BooleanUtils.valueToBoolean(source.getIsAddress())) {
if (!nodes.containsKey(source.getSequence())) {
Node conjecturalNode = new Node();
conjecturalNode.setId(source.getSequence());
conjecturalNode.setId(String.valueOf(source.getSequence()));
conjecturalNode.setName(source.getName());
conjecturalNode.setType(
componentLibraryCatalogService.getServerNameBasedOnComponent(serverCall.getComponentId()));
......@@ -178,7 +176,7 @@ class TopologyBuilder {
private Node buildNode(ServiceInventory serviceInventory) {
Node serviceNode = new Node();
serviceNode.setId(serviceInventory.getSequence());
serviceNode.setId(String.valueOf(serviceInventory.getSequence()));
serviceNode.setName(serviceInventory.getName());
if (BooleanUtils.valueToBoolean(serviceInventory.getIsAddress())) {
serviceNode.setReal(false);
......@@ -187,13 +185,4 @@ class TopologyBuilder {
}
return serviceNode;
}
private void filterZeroSourceOrTargetReference(List<Call.CallDetail> serviceRelationClientCalls) {
for (int i = serviceRelationClientCalls.size() - 1; i >= 0; i--) {
Call.CallDetail call = serviceRelationClientCalls.get(i);
if (call.getSource() == 0 || call.getTarget() == 0) {
serviceRelationClientCalls.remove(i);
}
}
}
}
......@@ -27,7 +27,7 @@ import java.util.Set;
import org.apache.skywalking.oap.server.core.Const;
import org.apache.skywalking.oap.server.core.CoreModule;
import org.apache.skywalking.oap.server.core.analysis.Downsampling;
import org.apache.skywalking.oap.server.core.cache.EndpointInventoryCache;
import org.apache.skywalking.oap.server.core.analysis.manual.endpoint.EndpointTraffic;
import org.apache.skywalking.oap.server.core.config.IComponentLibraryCatalogService;
import org.apache.skywalking.oap.server.core.query.entity.Call;
import org.apache.skywalking.oap.server.core.query.entity.Node;
......@@ -50,7 +50,6 @@ public class TopologyQueryService implements Service {
private final ModuleManager moduleManager;
private ITopologyQueryDAO topologyQueryDAO;
private IMetadataQueryDAO metadataQueryDAO;
private EndpointInventoryCache endpointInventoryCache;
private IComponentLibraryCatalogService componentLibraryCatalogService;
public TopologyQueryService(ModuleManager moduleManager) {
......@@ -80,15 +79,6 @@ public class TopologyQueryService implements Service {
return componentLibraryCatalogService;
}
private EndpointInventoryCache getEndpointInventoryCache() {
if (endpointInventoryCache == null) {
endpointInventoryCache = moduleManager.find(CoreModule.NAME)
.provider()
.getService(EndpointInventoryCache.class);
}
return endpointInventoryCache;
}
public Topology getGlobalTopology(final Downsampling downsampling, final long startTB,
final long endTB) throws IOException {
logger.debug("Downsampling: {}, startTimeBucket: {}, endTimeBucket: {}", downsampling, startTB, endTB);
......@@ -121,7 +111,7 @@ public class TopologyQueryService implements Service {
// Client side relationships exclude the given services(#serviceIds)
// The given services(#serviceIds)'s component names have been included inside `serviceRelationServerCalls`
if (!serviceIds.contains(call.getSource())) {
outScopeSourceServiceIds.add(call.getSource());
outScopeSourceServiceIds.add(Integer.parseInt(call.getSource()));
}
});
if (CollectionUtils.isNotEmpty(outScopeSourceServiceIds)) {
......@@ -131,7 +121,7 @@ public class TopologyQueryService implements Service {
topology.getNodes().forEach(node -> {
if (Strings.isNullOrEmpty(node.getType())) {
for (Call.CallDetail call : sourceCalls) {
if (node.getId() == call.getTarget()) {
if (node.getId().equals(call.getTarget())) {
node.setType(getComponentLibraryCatalogService().getComponentName(call.getComponentId()));
break;
}
......@@ -163,7 +153,7 @@ public class TopologyQueryService implements Service {
}
public Topology getEndpointTopology(final Downsampling downsampling, final long startTB, final long endTB,
final int endpointId) throws IOException {
final String endpointId) throws IOException {
List<Call.CallDetail> serverSideCalls = getTopologyQueryDAO().loadSpecifiedDestOfServerSideEndpointRelations(
downsampling, startTB, endTB, endpointId);
......@@ -177,7 +167,7 @@ public class TopologyQueryService implements Service {
topology.getCalls().add(call);
});
Set<Integer> nodeIds = new HashSet<>();
Set<String> nodeIds = new HashSet<>();
serverSideCalls.forEach(call -> {
if (!nodeIds.contains(call.getSource())) {
topology.getNodes().add(buildEndpointNode(call.getSource()));
......@@ -192,10 +182,11 @@ public class TopologyQueryService implements Service {
return topology;
}
private Node buildEndpointNode(int endpointId) {
private Node buildEndpointNode(String endpointId) {
Node node = new Node();
node.setId(endpointId);
node.setName(getEndpointInventoryCache().get(endpointId).getName());
final EndpointTraffic.EndpointID endpointID = EndpointTraffic.splitID(endpointId);
node.setName(endpointID.getEndpointName());
node.setType(Const.EMPTY_STRING);
node.setReal(true);
return node;
......
......@@ -30,7 +30,6 @@ import org.apache.skywalking.apm.network.language.agent.v2.SpanObjectV2;
import org.apache.skywalking.oap.server.core.Const;
import org.apache.skywalking.oap.server.core.CoreModule;
import org.apache.skywalking.oap.server.core.analysis.manual.segment.SegmentRecord;
import org.apache.skywalking.oap.server.core.cache.EndpointInventoryCache;
import org.apache.skywalking.oap.server.core.cache.NetworkAddressInventoryCache;
import org.apache.skywalking.oap.server.core.cache.ServiceInventoryCache;
import org.apache.skywalking.oap.server.core.config.IComponentLibraryCatalogService;
......@@ -44,7 +43,6 @@ import org.apache.skywalking.oap.server.core.query.entity.Span;
import org.apache.skywalking.oap.server.core.query.entity.Trace;
import org.apache.skywalking.oap.server.core.query.entity.TraceBrief;
import org.apache.skywalking.oap.server.core.query.entity.TraceState;
import org.apache.skywalking.oap.server.core.register.EndpointInventory;
import org.apache.skywalking.oap.server.core.register.ServiceInventory;
import org.apache.skywalking.oap.server.core.storage.StorageModule;
import org.apache.skywalking.oap.server.core.storage.query.ITraceQueryDAO;
......@@ -59,7 +57,6 @@ public class TraceQueryService implements Service {
private final ModuleManager moduleManager;
private ITraceQueryDAO traceQueryDAO;
private ServiceInventoryCache serviceInventoryCache;
private EndpointInventoryCache endpointInventoryCache;
private NetworkAddressInventoryCache networkAddressInventoryCache;
private IComponentLibraryCatalogService componentLibraryCatalogService;
......@@ -83,15 +80,6 @@ public class TraceQueryService implements Service {
return serviceInventoryCache;
}
private EndpointInventoryCache getEndpointInventoryCache() {
if (endpointInventoryCache == null) {
this.endpointInventoryCache = moduleManager.find(CoreModule.NAME)
.provider()
.getService(EndpointInventoryCache.class);
}
return endpointInventoryCache;
}
private NetworkAddressInventoryCache getNetworkAddressInventoryCache() {
if (networkAddressInventoryCache == null) {
this.networkAddressInventoryCache = moduleManager.find(CoreModule.NAME)
......@@ -110,14 +98,25 @@ public class TraceQueryService implements Service {
return componentLibraryCatalogService;
}
public TraceBrief queryBasicTraces(final int serviceId, final int serviceInstanceId, final int endpointId,
final String traceId, final String endpointName, final int minTraceDuration, int maxTraceDuration,
final TraceState traceState, final QueryOrder queryOrder, final Pagination paging, final long startTB,
final long endTB) throws IOException {
public TraceBrief queryBasicTraces(final int serviceId,
final int serviceInstanceId,
final String endpointId,
final String traceId,
final String endpointName,
final int minTraceDuration,
int maxTraceDuration,
final TraceState traceState,
final QueryOrder queryOrder,
final Pagination paging,
final long startTB,
final long endTB) throws IOException {
PaginationUtils.Page page = PaginationUtils.INSTANCE.exchange(paging);
return getTraceQueryDAO().queryBasicTraces(startTB, endTB, minTraceDuration, maxTraceDuration, endpointName, serviceId, serviceInstanceId, endpointId, traceId, page
.getLimit(), page.getFrom(), traceState, queryOrder);
return getTraceQueryDAO().queryBasicTraces(
startTB, endTB, minTraceDuration, maxTraceDuration, endpointName, serviceId, serviceInstanceId, endpointId,
traceId, page
.getLimit(), page.getFrom(), traceState, queryOrder
);
}
public Trace queryTrace(final String traceId) throws IOException {
......@@ -131,7 +130,9 @@ public class TraceQueryService implements Service {
if (nonNull(segment)) {
SegmentObject segmentObject = SegmentObject.parseFrom(segment.getDataBinary());
trace.getSpans()
.addAll(buildSpanV2List(traceId, segment.getSegmentId(), segment.getServiceId(), segmentObject.getSpansList()));
.addAll(buildSpanV2List(traceId, segment.getSegmentId(), segment.getServiceId(),
segmentObject.getSpansList()
));
}
}
}
......@@ -156,7 +157,7 @@ public class TraceQueryService implements Service {
}
private List<Span> buildSpanV2List(String traceId, String segmentId, int serviceId,
List<SpanObjectV2> spanObjects) {
List<SpanObjectV2> spanObjects) {
List<Span> spans = new ArrayList<>();
spanObjects.forEach(spanObject -> {
......@@ -183,16 +184,7 @@ public class TraceQueryService implements Service {
span.setPeer(getNetworkAddressInventoryCache().get(spanObject.getPeerId()).getName());
}
String endpointName = spanObject.getOperationName();
if (spanObject.getOperationNameId() != 0) {
EndpointInventory endpointInventory = getEndpointInventoryCache().get(spanObject.getOperationNameId());
if (nonNull(endpointInventory)) {
endpointName = endpointInventory.getName();
} else {
endpointName = Const.EMPTY_STRING;
}
}
span.setEndpointName(endpointName);
span.setEndpointName(spanObject.getOperationName());
final ServiceInventory serviceInventory = getServiceInventoryCache().get(serviceId);
if (serviceInventory != null) {
......@@ -228,7 +220,8 @@ public class TraceQueryService implements Service {
.collect(Collectors.joining("."));
ref.setParentSegmentId(parentSegmentId);
span.setSegmentParentSpanId(ref.getParentSegmentId() + Const.SEGMENT_SPAN_SPLIT + ref.getParentSpanId());
span.setSegmentParentSpanId(
ref.getParentSegmentId() + Const.SEGMENT_SPAN_SPLIT + ref.getParentSpanId());
span.getRefs().add(ref);
});
......
......@@ -29,8 +29,8 @@ import org.apache.skywalking.oap.server.core.source.DetectPoint;
@Getter
@Setter
public class Call {
private Integer source;
private Integer target;
private String source;
private String target;
private List<String> sourceComponents;
private List<String> targetComponents;
private String id;
......@@ -45,11 +45,11 @@ public class Call {
detectPoints = new ArrayList<>();
}
public void setSource(int source) {
public void setSource(String source) {
this.source = source;
}
public void setTarget(int target) {
public void setTarget(String target) {
this.target = target;
}
......@@ -84,8 +84,8 @@ public class Call {
public static class CallDetail {
@Setter(AccessLevel.PRIVATE)
private String id;
private Integer source;
private Integer target;
private String source;
private String target;
private DetectPoint detectPoint;
private Integer componentId;
......
......@@ -24,6 +24,6 @@ import lombok.Setter;
@Getter
@Setter
public class Endpoint {
private int id;
private String id;
private String name;
}
......@@ -24,7 +24,7 @@ import lombok.Setter;
@Getter
@Setter
public class EndpointInfo {
private int id;
private String id;
private String name;
private int serviceId;
private String serviceName;
......
......@@ -28,8 +28,8 @@ public class Log {
private int serviceId;
private String serviceInstanceName;
private int serviceInstanceId;
private String endpointId;
private String endpointName;
private int endpointId;
private String traceId;
private String timestamp;
private boolean isError;
......
......@@ -24,7 +24,7 @@ import lombok.Setter;
@Getter
@Setter
public class Node {
private int id;
private String id;
private String name;
private String type;
private boolean isReal;
......
/*
* 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.server.core.register.service;
import java.util.Objects;
import org.apache.skywalking.oap.server.core.Const;
import org.apache.skywalking.oap.server.core.CoreModule;
import org.apache.skywalking.oap.server.core.cache.EndpointInventoryCache;
import org.apache.skywalking.oap.server.core.register.EndpointInventory;
import org.apache.skywalking.oap.server.core.register.worker.InventoryStreamProcessor;
import org.apache.skywalking.oap.server.core.source.DetectPoint;
import org.apache.skywalking.oap.server.library.module.ModuleDefineHolder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static java.util.Objects.isNull;
public class EndpointInventoryRegister implements IEndpointInventoryRegister {
private static final Logger logger = LoggerFactory.getLogger(EndpointInventoryRegister.class);
private final ModuleDefineHolder moduleDefineHolder;
private EndpointInventoryCache cacheService;
public EndpointInventoryRegister(ModuleDefineHolder moduleDefineHolder) {
this.moduleDefineHolder = moduleDefineHolder;
}
private EndpointInventoryCache getCacheService() {
if (isNull(cacheService)) {
cacheService = moduleDefineHolder.find(CoreModule.NAME).provider().getService(EndpointInventoryCache.class);
}
return cacheService;
}
@Override
public int getOrCreate(int serviceId, String endpointName, DetectPoint detectPoint) {
int endpointId = getCacheService().getEndpointId(serviceId, endpointName, detectPoint.ordinal());
if (endpointId == Const.NONE) {
EndpointInventory endpointInventory = new EndpointInventory();
endpointInventory.setServiceId(serviceId);
endpointInventory.setName(endpointName);
endpointInventory.setDetectPoint(detectPoint.ordinal());
long now = System.currentTimeMillis();
endpointInventory.setRegisterTime(now);
endpointInventory.setHeartbeatTime(now);
InventoryStreamProcessor.getInstance().in(endpointInventory);
}
return endpointId;
}
@Override
public int get(int serviceId, String endpointName, DetectPoint detectPoint) {
return getCacheService().getEndpointId(serviceId, endpointName, detectPoint.ordinal());
}
@Override
public void heartbeat(int endpointId, long heartBeatTime) {
EndpointInventory endpointInventory = getCacheService().get(endpointId);
if (Objects.nonNull(endpointInventory)) {
endpointInventory.setHeartbeatTime(heartBeatTime);
InventoryStreamProcessor.getInstance().in(endpointInventory);
} else {
logger.warn("Endpoint {} heartbeat, but not found in storage.", endpointId);
}
}
}
......@@ -30,7 +30,8 @@ public abstract class AbstractLog extends Source {
private long timestamp;
private int serviceId;
private int serviceInstanceId;
private int endpointId;
private String endpointId;
private String endpointName;
private String traceId;
private int isError;
private String statusCode;
......
......@@ -54,7 +54,7 @@ public class DefaultScopeDefine {
public static final int ALARM = 13;
public static final int SERVICE_INVENTORY = 14;
public static final int SERVICE_INSTANCE_INVENTORY = 15;
public static final int ENDPOINT_INVENTORY = 16;
public static final int ENDPOINT_TRAFFIC = 16;
public static final int DATABASE_ACCESS = 17;
public static final int DATABASE_SLOW_STATEMENT = 18;
public static final int SERVICE_INSTANCE_CLR_CPU = 19;
......
......@@ -18,10 +18,14 @@
package org.apache.skywalking.oap.server.core.source;
import lombok.RequiredArgsConstructor;
import org.apache.skywalking.apm.network.language.agent.SpanType;
@RequiredArgsConstructor
public enum DetectPoint {
SERVER, CLIENT, PROXY, UNRECOGNIZED;
SERVER(0), CLIENT(1), PROXY(2), UNRECOGNIZED(3);
private final int value;
public static DetectPoint fromSpanType(SpanType spanType) {
switch (spanType) {
......@@ -36,17 +40,20 @@ public enum DetectPoint {
}
}
public static DetectPoint fromNetworkProtocolDetectPoint(
org.apache.skywalking.apm.network.common.DetectPoint detectPoint) {
switch (detectPoint) {
case client:
return CLIENT;
case server:
public static DetectPoint valueOf(int value) {
switch (value) {
case 0:
return SERVER;
case proxy:
case UNRECOGNIZED:
case 1:
return CLIENT;
case 2:
return PROXY;
default:
return UNRECOGNIZED;
}
}
public int value() {
return this.value;
}
}
......@@ -20,6 +20,7 @@ package org.apache.skywalking.oap.server.core.source;
import lombok.Getter;
import lombok.Setter;
import org.apache.skywalking.oap.server.core.analysis.manual.endpoint.EndpointTraffic;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.ENDPOINT;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.ENDPOINT_CATALOG_NAME;
......@@ -32,14 +33,14 @@ public class Endpoint extends Source {
return DefaultScopeDefine.ENDPOINT;
}
/**
* @since 7.1.0 SkyWalking doesn't do endpoint register. Use name directly.
*/
@Override
public String getEntityId() {
return String.valueOf(id);
return EndpointTraffic.buildId(serviceId, name, DetectPoint.SERVER);
}
@Getter
@Setter
private int id;
@Getter
@Setter
@ScopeDefaultColumn.DefinedByField(columnName = "name", requireDynamicActive = true)
......
......@@ -20,7 +20,7 @@ package org.apache.skywalking.oap.server.core.source;
import lombok.Getter;
import lombok.Setter;
import org.apache.skywalking.oap.server.core.Const;
import org.apache.skywalking.oap.server.core.analysis.manual.RelationDefineUtil;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.ENDPOINT_RELATION;
......@@ -33,17 +33,19 @@ public class EndpointRelation extends Source {
return DefaultScopeDefine.ENDPOINT_RELATION;
}
/**
* @since 7.1.0 SkyWalking doesn't do endpoint register. Use name directly.
*/
@Override
public String getEntityId() {
return String.valueOf(endpointId) + Const.ID_SPLIT + String.valueOf(childEndpointId);
return RelationDefineUtil.buildEndpointRelationEntityId(new RelationDefineUtil.EndpointRelationDefine(
serviceId, endpoint, childServiceId, childEndpoint, componentId
));
}
@Getter
@Setter
private int endpointId;
@Getter
@Setter
@ScopeDefaultColumn.DefinedByField(columnName = "source_endpoint_name", requireDynamicActive = true)
@ScopeDefaultColumn.DefinedByField(columnName = "source_endpoint_name")
private String endpoint;
@Getter
@Setter
......@@ -62,10 +64,7 @@ public class EndpointRelation extends Source {
@Getter
@Setter
private int childEndpointId;
@Getter
@Setter
@ScopeDefaultColumn.DefinedByField(columnName = "child_endpoint_name", requireDynamicActive = true)
@ScopeDefaultColumn.DefinedByField(columnName = "child_endpoint_name")
private String childEndpoint;
@Getter
@Setter
......
......@@ -53,7 +53,7 @@ public class Segment extends Source {
private String endpointName;
@Setter
@Getter
private int endpointId;
private String endpointId;
@Setter
@Getter
private long startTime;
......
......@@ -18,7 +18,6 @@
package org.apache.skywalking.oap.server.core.storage;
import org.apache.skywalking.oap.server.core.storage.cache.IEndpointInventoryCacheDAO;
import org.apache.skywalking.oap.server.core.storage.cache.INetworkAddressInventoryCacheDAO;
import org.apache.skywalking.oap.server.core.storage.cache.IServiceInstanceInventoryCacheDAO;
import org.apache.skywalking.oap.server.core.storage.cache.IServiceInventoryCacheDAO;
......@@ -56,7 +55,6 @@ public class StorageModule extends ModuleDefine {
IHistoryDeleteDAO.class,
IServiceInventoryCacheDAO.class,
IServiceInstanceInventoryCacheDAO.class,
IEndpointInventoryCacheDAO.class,
INetworkAddressInventoryCacheDAO.class,
ITopologyQueryDAO.class,
IMetricsQueryDAO.class,
......
......@@ -25,7 +25,7 @@ import org.apache.skywalking.oap.server.core.query.entity.Pagination;
import org.apache.skywalking.oap.server.library.module.Service;
public interface ILogQueryDAO extends Service {
Logs queryLogs(final String metricName, int serviceId, int serviceInstanceId, int endpointId, String traceId,
Logs queryLogs(final String metricName, int serviceId, int serviceInstanceId, String endpointId, String traceId,
LogState state, String stateCode, Pagination paging, int from, int limit, final long startTB,
final long endTB) throws IOException;
}
......@@ -45,7 +45,7 @@ public interface IMetadataQueryDAO extends DAO {
Service searchService(final String serviceCode) throws IOException;
List<Endpoint> searchEndpoint(final String keyword, final String serviceId, final int limit) throws IOException;
List<Endpoint> searchEndpoint(final String keyword, final int serviceId, final int limit) throws IOException;
List<ServiceInstance> getServiceInstances(final long startTimestamp, final long endTimestamp,
final String serviceId) throws IOException;
......
......@@ -79,5 +79,5 @@ public interface ITopologyQueryDAO extends Service {
List<Call.CallDetail> loadSpecifiedDestOfServerSideEndpointRelations(Downsampling downsampling,
long startTB,
long endTB,
int destEndpointId) throws IOException;
String destEndpointId) throws IOException;
}
......@@ -30,7 +30,7 @@ import org.apache.skywalking.oap.server.library.module.Service;
public interface ITraceQueryDAO extends Service {
TraceBrief queryBasicTraces(long startSecondTB, long endSecondTB, long minDuration, long maxDuration,
String endpointName, int serviceId, int serviceInstanceId, int endpointId, String traceId, int limit, int from,
String endpointName, int serviceId, int serviceInstanceId, String endpointId, String traceId, int limit, int from,
TraceState traceState, QueryOrder queryOrder) throws IOException;
List<SegmentRecord> queryByTraceId(String traceId) throws IOException;
......
......@@ -16,14 +16,30 @@
*
*/
package org.apache.skywalking.oap.server.core.storage.cache;
package org.apache.skywalking.oap.server.core.analysis.manual;
import org.apache.skywalking.oap.server.core.register.EndpointInventory;
import org.apache.skywalking.oap.server.core.storage.DAO;
import org.junit.Assert;
import org.junit.Test;
public interface IEndpointInventoryCacheDAO extends DAO {
public class RelationDefineUtilTest {
@Test
public void testRelationID() {
RelationDefineUtil.RelationDefine define = new RelationDefineUtil.RelationDefine(1, 2, 0);
final RelationDefineUtil.RelationDefine relationDefine = RelationDefineUtil.splitEntityId(
RelationDefineUtil.buildEntityId(define));
Assert.assertEquals(define, relationDefine);
}
int getEndpointId(int serviceId, String endpointName, int detectPoint);
@Test
public void testEndpointRelationID() {
final RelationDefineUtil.EndpointRelationDefine endpointRelationDefine = new RelationDefineUtil.EndpointRelationDefine(
1, "/source/endpoint",
2, "/dest/endpoint",
0
);
final RelationDefineUtil.EndpointRelationDefine anotherRelation = RelationDefineUtil.splitEndpointRelationEntityId(
RelationDefineUtil.buildEndpointRelationEntityId(endpointRelationDefine));
Assert.assertEquals(endpointRelationDefine, anotherRelation);
EndpointInventory get(int endpointId);
}
}
/*
* 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.server.core.analysis.manual.endpoint;
import org.apache.skywalking.oap.server.core.source.DetectPoint;
import org.junit.Assert;
import org.junit.Test;
public class EndpointTrafficTest {
@Test
public void testBuildID() {
int serviceId = 4;
String endpointName = "/endpoint-123";
DetectPoint detectPoint = DetectPoint.SERVER;
EndpointTraffic endpointTraffic = new EndpointTraffic();
endpointTraffic.setServiceId(serviceId);
endpointTraffic.setName(endpointName);
endpointTraffic.setDetectPoint(detectPoint.value());
Assert.assertEquals(
EndpointTraffic.buildId(serviceId, endpointName, detectPoint), EndpointTraffic.buildId(endpointTraffic));
final EndpointTraffic.EndpointID endpointID = EndpointTraffic.splitID(EndpointTraffic.buildId(endpointTraffic));
Assert.assertEquals(endpointName, endpointID.getEndpointName());
}
@Test
public void testSerialization() {
int serviceId = 4;
String endpointName = "/endpoint-123";
DetectPoint detectPoint = DetectPoint.SERVER;
EndpointTraffic endpointTraffic = new EndpointTraffic();
endpointTraffic.setTimeBucket(202003281420L);
endpointTraffic.setServiceId(serviceId);
endpointTraffic.setName(endpointName);
endpointTraffic.setDetectPoint(detectPoint.value());
EndpointTraffic another = new EndpointTraffic();
another.deserialize(endpointTraffic.serialize().build());
Assert.assertEquals(endpointTraffic, another);
}
@Test
public void testPersistence() {
int serviceId = 4;
String endpointName = "/endpoint-123";
DetectPoint detectPoint = DetectPoint.SERVER;
EndpointTraffic endpointTraffic = new EndpointTraffic();
endpointTraffic.setTimeBucket(202003281420L);
endpointTraffic.setServiceId(serviceId);
endpointTraffic.setName(endpointName);
endpointTraffic.setDetectPoint(detectPoint.value());
final EndpointTraffic.Builder builder = new EndpointTraffic.Builder();
final EndpointTraffic another = builder.map2Data(builder.data2Map(endpointTraffic));
Assert.assertEquals(endpointTraffic, another);
}
}
......@@ -77,7 +77,7 @@ public class MetadataQuery implements GraphQLQueryResolver {
}
public List<Service> searchServices(final Duration duration,
final String keyword) throws IOException, ParseException {
final String keyword) throws IOException, ParseException {
long startTimestamp = DurationUtils.INSTANCE.startTimeToTimestamp(duration.getStep(), duration.getStart());
long endTimestamp = DurationUtils.INSTANCE.endTimeToTimestamp(duration.getStep(), duration.getEnd());
......@@ -89,19 +89,19 @@ public class MetadataQuery implements GraphQLQueryResolver {
}
public List<ServiceInstance> getServiceInstances(final Duration duration,
final String serviceId) throws IOException, ParseException {
final String serviceId) throws IOException, ParseException {
long startTimestamp = DurationUtils.INSTANCE.startTimeToTimestamp(duration.getStep(), duration.getStart());
long endTimestamp = DurationUtils.INSTANCE.endTimeToTimestamp(duration.getStep(), duration.getEnd());
return getMetadataQueryService().getServiceInstances(startTimestamp, endTimestamp, serviceId);
}
public List<Endpoint> searchEndpoint(final String keyword, final String serviceId,
final int limit) throws IOException {
public List<Endpoint> searchEndpoint(final String keyword, final int serviceId,
final int limit) throws IOException {
return getMetadataQueryService().searchEndpoint(keyword, serviceId, limit);
}
public EndpointInfo getEndpointInfo(final int endpointId) throws IOException {
public EndpointInfo getEndpointInfo(final String endpointId) throws IOException {
return getMetadataQueryService().getEndpointInfo(endpointId);
}
......
......@@ -81,7 +81,7 @@ public class TopologyQuery implements GraphQLQueryResolver {
);
}
public Topology getEndpointTopology(final int endpointId, final Duration duration) throws IOException {
public Topology getEndpointTopology(final String endpointId, final Duration duration) throws IOException {
long startTimeBucket = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getStart());
long endTimeBucket = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getEnd());
......
......@@ -75,7 +75,7 @@ public class TraceQuery implements GraphQLQueryResolver {
int maxDuration = condition.getMaxTraceDuration();
String endpointName = condition.getEndpointName();
int serviceId = StringUtils.isEmpty(condition.getServiceId()) ? 0 : Integer.parseInt(condition.getServiceId());
int endpointId = StringUtils.isEmpty(condition.getEndpointId()) ? 0 : Integer.parseInt(condition.getEndpointId());
String endpointId = condition.getEndpointId();
int serviceInstanceId = StringUtils.isEmpty(condition.getServiceInstanceId()) ? 0 : Integer.parseInt(condition.getServiceInstanceId());
TraceState traceState = condition.getTraceState();
QueryOrder queryOrder = condition.getQueryOrder();
......
......@@ -29,7 +29,7 @@ public class LogQueryCondition {
private String metricName;
private int serviceId;
private int serviceInstanceId;
private int endpointId;
private String endpointId;
private String traceId;
private LogState state;
private String stateCode;
......
Subproject commit 28f18ae8dab49e60eb3d2e5cfd1a5c884a897ad0
Subproject commit 3bd7111b9363033752d38982551ca7324a8dd74c
......@@ -29,6 +29,7 @@ import java.util.Base64;
import org.apache.skywalking.apm.util.StringUtil;
import org.apache.skywalking.oap.server.core.Const;
import org.apache.skywalking.oap.server.core.analysis.TimeBucket;
import org.apache.skywalking.oap.server.core.analysis.manual.endpoint.EndpointTraffic;
import org.apache.skywalking.oap.server.core.source.DetectPoint;
import org.apache.skywalking.oap.server.core.source.SourceReceiver;
import org.apache.skywalking.oap.server.library.util.BooleanUtils;
......@@ -49,7 +50,7 @@ public class JaegerGRPCHandler extends CollectorServiceGrpc.CollectorServiceImpl
}
public void postSpans(Collector.PostSpansRequest request,
StreamObserver<Collector.PostSpansResponse> responseObserver) {
StreamObserver<Collector.PostSpansResponse> responseObserver) {
request.getBatch().getSpansList().forEach(span -> {
try {
......@@ -119,13 +120,8 @@ public class JaegerGRPCHandler extends CollectorServiceGrpc.CollectorServiceImpl
if ("server".equals(kind) || "consumer".equals(kind)) {
String endpointName = span.getOperationName();
jaegerSpan.setEndpointName(endpointName);
int endpointId = CoreRegisterLinker.getEndpointInventoryCache()
.getEndpointId(finalServiceId, endpointName, DetectPoint.SERVER
.ordinal());
if (endpointId != Const.NONE) {
CoreRegisterLinker.getEndpointInventoryRegister()
.getOrCreate(finalServiceId, endpointName, DetectPoint.SERVER);
}
jaegerSpan.setEndpointId(
EndpointTraffic.buildId(finalServiceId, endpointName, DetectPoint.SERVER));
}
}
});
......
......@@ -19,7 +19,6 @@
package org.apache.skywalking.aop.server.receiver.mesh;
import com.google.gson.JsonObject;
import org.apache.skywalking.apm.network.common.DetectPoint;
import org.apache.skywalking.apm.network.servicemesh.ServiceMeshMetric;
import org.apache.skywalking.apm.util.StringUtil;
import org.apache.skywalking.oap.server.core.Const;
......@@ -30,7 +29,6 @@ public class ServiceMeshMetricDataDecorator {
private ServiceMeshMetric origin;
private ServiceMeshMetric rebuiltData;
private ServiceMeshMetric.Builder newDataBuilder;
private int endpointId;
public ServiceMeshMetricDataDecorator(ServiceMeshMetric origin) {
this.origin = origin;
......@@ -60,9 +58,12 @@ public class ServiceMeshMetricDataDecorator {
sourceServiceInstanceId = origin.getSourceServiceInstanceId();
if (sourceServiceId != Const.NONE && sourceServiceInstanceId == Const.NONE) {
sourceServiceInstanceId = CoreRegisterLinker.getServiceInstanceInventoryRegister()
.getOrCreate(sourceServiceId, origin.getSourceServiceInstance(), origin
.getSourceServiceInstance(), origin.getEndTime(), getOSInfoForMesh(origin
.getSourceServiceInstance()));
.getOrCreate(
sourceServiceId, origin.getSourceServiceInstance(), origin
.getSourceServiceInstance(), origin.getEndTime(),
getOSInfoForMesh(origin
.getSourceServiceInstance())
);
if (sourceServiceInstanceId != Const.NONE) {
getNewDataBuilder().setSourceServiceInstanceId(sourceServiceInstanceId);
} else {
......@@ -82,26 +83,18 @@ public class ServiceMeshMetricDataDecorator {
destServiceInstanceId = origin.getDestServiceInstanceId();
if (destServiceId != Const.NONE && destServiceInstanceId == Const.NONE) {
destServiceInstanceId = CoreRegisterLinker.getServiceInstanceInventoryRegister()
.getOrCreate(destServiceId, origin.getDestServiceInstance(), origin
.getDestServiceInstance(), origin.getEndTime(), getOSInfoForMesh(origin
.getDestServiceInstance()));
.getOrCreate(
destServiceId, origin.getDestServiceInstance(), origin
.getDestServiceInstance(), origin.getEndTime(),
getOSInfoForMesh(origin
.getDestServiceInstance())
);
if (destServiceInstanceId != Const.NONE) {
getNewDataBuilder().setDestServiceInstanceId(destServiceInstanceId);
} else {
isRegistered = false;
}
}
String endpoint = origin.getEndpoint();
// Service mesh doesn't register client side endpoint.
DetectPoint point = origin.getDetectPoint();
if (DetectPoint.server.equals(point)) {
if (destServiceId != Const.NONE) {
endpointId = CoreRegisterLinker.getEndpointInventoryRegister()
.getOrCreate(destServiceId, endpoint, org.apache.skywalking.oap.server.core.source.DetectPoint
.fromNetworkProtocolDetectPoint(point));
}
}
return isRegistered;
}
......@@ -117,10 +110,6 @@ public class ServiceMeshMetricDataDecorator {
}
}
public int getEndpointId() {
return endpointId;
}
private ServiceMeshMetric.Builder getNewDataBuilder() {
if (newDataBuilder == null) {
newDataBuilder = origin.toBuilder();
......
......@@ -78,7 +78,8 @@ public class TelemetryDataDispatcher {
}
public static void preProcess(ServiceMeshMetric data) {
String service = data.getDestServiceId() == Const.NONE ? data.getDestServiceName() : SERVICE_CACHE.get(data.getDestServiceId())
String service = data.getDestServiceId() == Const.NONE ? data.getDestServiceName() : SERVICE_CACHE.get(
data.getDestServiceId())
.getName();
String endpointName = data.getEndpoint();
StringFormatGroup.FormatResult formatResult = EndpointNameFormater.format(service, endpointName);
......@@ -134,11 +135,13 @@ public class TelemetryDataDispatcher {
if (Objects.nonNull(serviceInstanceInventory)) {
if (metrics.getEndTime() - serviceInstanceInventory.getHeartbeatTime() > heartbeatCycle) {
// trigger heartbeat every 10s.
SERVICE_INSTANCE_INVENTORY_REGISTER.heartbeat(metrics.getSourceServiceInstanceId(), metrics.getEndTime());
SERVICE_INSTANCE_INVENTORY_REGISTER.heartbeat(
metrics.getSourceServiceInstanceId(), metrics.getEndTime());
SERVICE_INVENTORY_REGISTER.heartbeat(serviceInstanceInventory.getServiceId(), metrics.getEndTime());
}
} else {
logger.warn("Can't found service by service instance id from cache, service instance id is: {}", instanceId);
logger.warn(
"Can't found service by service instance id from cache, service instance id is: {}", instanceId);
}
}
......@@ -152,7 +155,8 @@ public class TelemetryDataDispatcher {
SERVICE_INVENTORY_REGISTER.heartbeat(serviceInstanceInventory.getServiceId(), metrics.getEndTime());
}
} else {
logger.warn("Can't found service by service instance id from cache, service instance id is: {}", instanceId);
logger.warn(
"Can't found service by service instance id from cache, service instance id is: {}", instanceId);
}
}
......@@ -161,7 +165,8 @@ public class TelemetryDataDispatcher {
All all = new All();
all.setTimeBucket(minuteTimeBucket);
all.setName(getServiceName(metrics.getDestServiceId(), metrics.getDestServiceName()));
all.setServiceInstanceName(getServiceInstanceName(metrics.getDestServiceInstanceId(), metrics.getDestServiceInstance()));
all.setServiceInstanceName(
getServiceInstanceName(metrics.getDestServiceInstanceId(), metrics.getDestServiceInstance()));
all.setEndpointName(metrics.getEndpoint());
all.setLatency(metrics.getLatency());
all.setStatus(metrics.getStatus());
......@@ -177,7 +182,8 @@ public class TelemetryDataDispatcher {
service.setTimeBucket(minuteTimeBucket);
service.setId(metrics.getDestServiceId());
service.setName(getServiceName(metrics.getDestServiceId(), metrics.getDestServiceName()));
service.setServiceInstanceName(getServiceInstanceName(metrics.getDestServiceInstanceId(), metrics.getDestServiceInstance()));
service.setServiceInstanceName(
getServiceInstanceName(metrics.getDestServiceInstanceId(), metrics.getDestServiceInstance()));
service.setEndpointName(metrics.getEndpoint());
service.setLatency(metrics.getLatency());
service.setStatus(metrics.getStatus());
......@@ -192,13 +198,16 @@ public class TelemetryDataDispatcher {
ServiceRelation serviceRelation = new ServiceRelation();
serviceRelation.setTimeBucket(minuteTimeBucket);
serviceRelation.setSourceServiceId(metrics.getSourceServiceId());
serviceRelation.setSourceServiceName(getServiceName(metrics.getSourceServiceId(), metrics.getSourceServiceName()));
serviceRelation.setSourceServiceInstanceName(getServiceInstanceName(metrics.getSourceServiceInstanceId(), metrics
.getSourceServiceInstance()));
serviceRelation.setSourceServiceName(
getServiceName(metrics.getSourceServiceId(), metrics.getSourceServiceName()));
serviceRelation.setSourceServiceInstanceName(
getServiceInstanceName(metrics.getSourceServiceInstanceId(), metrics
.getSourceServiceInstance()));
serviceRelation.setDestServiceId(metrics.getDestServiceId());
serviceRelation.setDestServiceName(getServiceName(metrics.getDestServiceId(), metrics.getDestServiceName()));
serviceRelation.setDestServiceInstanceName(getServiceInstanceName(metrics.getDestServiceInstanceId(), metrics.getDestServiceInstance()));
serviceRelation.setDestServiceInstanceName(
getServiceInstanceName(metrics.getDestServiceInstanceId(), metrics.getDestServiceInstance()));
serviceRelation.setEndpoint(metrics.getEndpoint());
serviceRelation.setLatency(metrics.getLatency());
......@@ -216,7 +225,8 @@ public class TelemetryDataDispatcher {
ServiceInstance serviceInstance = new ServiceInstance();
serviceInstance.setTimeBucket(minuteTimeBucket);
serviceInstance.setId(metrics.getDestServiceInstanceId());
serviceInstance.setName(getServiceInstanceName(metrics.getDestServiceInstanceId(), metrics.getDestServiceInstance()));
serviceInstance.setName(
getServiceInstanceName(metrics.getDestServiceInstanceId(), metrics.getDestServiceInstance()));
serviceInstance.setServiceId(metrics.getDestServiceId());
serviceInstance.setServiceName(getServiceName(metrics.getDestServiceId(), metrics.getDestServiceName()));
serviceInstance.setEndpointName(metrics.getEndpoint());
......@@ -233,13 +243,16 @@ public class TelemetryDataDispatcher {
ServiceInstanceRelation serviceRelation = new ServiceInstanceRelation();
serviceRelation.setTimeBucket(minuteTimeBucket);
serviceRelation.setSourceServiceInstanceId(metrics.getSourceServiceInstanceId());
serviceRelation.setSourceServiceInstanceName(getServiceInstanceName(metrics.getSourceServiceInstanceId(), metrics
.getSourceServiceInstance()));
serviceRelation.setSourceServiceInstanceName(
getServiceInstanceName(metrics.getSourceServiceInstanceId(), metrics
.getSourceServiceInstance()));
serviceRelation.setSourceServiceId(metrics.getSourceServiceId());
serviceRelation.setSourceServiceName(getServiceName(metrics.getSourceServiceId(), metrics.getSourceServiceName()));
serviceRelation.setSourceServiceName(
getServiceName(metrics.getSourceServiceId(), metrics.getSourceServiceName()));
serviceRelation.setDestServiceInstanceId(metrics.getDestServiceInstanceId());
serviceRelation.setDestServiceInstanceName(getServiceInstanceName(metrics.getDestServiceInstanceId(), metrics.getDestServiceInstance()));
serviceRelation.setDestServiceInstanceName(
getServiceInstanceName(metrics.getDestServiceInstanceId(), metrics.getDestServiceInstance()));
serviceRelation.setDestServiceId(metrics.getDestServiceId());
serviceRelation.setDestServiceName(getServiceName(metrics.getDestServiceId(), metrics.getDestServiceName()));
......@@ -255,19 +268,15 @@ public class TelemetryDataDispatcher {
}
private static void toEndpoint(ServiceMeshMetricDataDecorator decorator, long minuteTimeBucket) {
if (decorator.getEndpointId() == Const.NONE) {
logger.warn("Received service mesh data {} with an id == 0", decorator);
return;
}
ServiceMeshMetric metrics = decorator.getMetric();
Endpoint endpoint = new Endpoint();
endpoint.setTimeBucket(minuteTimeBucket);
endpoint.setId(decorator.getEndpointId());
endpoint.setName(metrics.getEndpoint());
endpoint.setServiceId(metrics.getDestServiceId());
endpoint.setServiceName(getServiceName(metrics.getDestServiceId(), metrics.getDestServiceName()));
endpoint.setServiceInstanceId(metrics.getDestServiceInstanceId());
endpoint.setServiceInstanceName(getServiceInstanceName(metrics.getDestServiceInstanceId(), metrics.getDestServiceInstance()));
endpoint.setServiceInstanceName(
getServiceInstanceName(metrics.getDestServiceInstanceId(), metrics.getDestServiceInstance()));
endpoint.setLatency(metrics.getLatency());
endpoint.setStatus(metrics.getStatus());
......
......@@ -27,7 +27,6 @@ import org.apache.skywalking.apm.network.common.KeyIntValuePair;
import org.apache.skywalking.apm.network.common.KeyStringValuePair;
import org.apache.skywalking.apm.network.common.ServiceType;
import org.apache.skywalking.apm.network.register.v2.EndpointMapping;
import org.apache.skywalking.apm.network.register.v2.EndpointMappingElement;
import org.apache.skywalking.apm.network.register.v2.Endpoints;
import org.apache.skywalking.apm.network.register.v2.NetAddressMapping;
import org.apache.skywalking.apm.network.register.v2.NetAddresses;
......@@ -45,11 +44,9 @@ import org.apache.skywalking.oap.server.core.cache.ServiceInventoryCache;
import org.apache.skywalking.oap.server.core.register.NodeType;
import org.apache.skywalking.oap.server.core.register.ServiceInstanceInventory;
import org.apache.skywalking.oap.server.core.register.ServiceInventory;
import org.apache.skywalking.oap.server.core.register.service.IEndpointInventoryRegister;
import org.apache.skywalking.oap.server.core.register.service.INetworkAddressInventoryRegister;
import org.apache.skywalking.oap.server.core.register.service.IServiceInstanceInventoryRegister;
import org.apache.skywalking.oap.server.core.register.service.IServiceInventoryRegister;
import org.apache.skywalking.oap.server.core.source.DetectPoint;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
import org.apache.skywalking.oap.server.library.server.grpc.GRPCHandler;
import org.slf4j.Logger;
......@@ -76,7 +73,6 @@ public class RegisterServiceHandler extends RegisterGrpc.RegisterImplBase implem
private final ServiceInstanceInventoryCache serviceInstanceInventoryCache;
private final IServiceInventoryRegister serviceInventoryRegister;
private final IServiceInstanceInventoryRegister serviceInstanceInventoryRegister;
private final IEndpointInventoryRegister inventoryService;
private final INetworkAddressInventoryRegister networkAddressInventoryRegister;
public RegisterServiceHandler(ModuleManager moduleManager) {
......@@ -92,9 +88,6 @@ public class RegisterServiceHandler extends RegisterGrpc.RegisterImplBase implem
this.serviceInstanceInventoryRegister = moduleManager.find(CoreModule.NAME)
.provider()
.getService(IServiceInstanceInventoryRegister.class);
this.inventoryService = moduleManager.find(CoreModule.NAME)
.provider()
.getService(IEndpointInventoryRegister.class);
this.networkAddressInventoryRegister = moduleManager.find(CoreModule.NAME)
.provider()
.getService(INetworkAddressInventoryRegister.class);
......@@ -199,31 +192,13 @@ public class RegisterServiceHandler extends RegisterGrpc.RegisterImplBase implem
responseObserver.onCompleted();
}
/**
* @since 7.1.0 There is no endpoint / operation name register anymore.
*/
@Deprecated
@Override
public void doEndpointRegister(Endpoints request, StreamObserver<EndpointMapping> responseObserver) {
EndpointMapping.Builder builder = EndpointMapping.newBuilder();
request.getEndpointsList().forEach(endpoint -> {
int serviceId = endpoint.getServiceId();
String endpointName = endpoint.getEndpointName();
DetectPoint detectPoint = DetectPoint.fromNetworkProtocolDetectPoint(endpoint.getFrom());
if (DetectPoint.SERVER.equals(detectPoint)) {
int endpointId = inventoryService.getOrCreate(serviceId, endpointName, detectPoint);
if (endpointId != Const.NONE) {
builder.addElements(EndpointMappingElement.newBuilder()
.setServiceId(serviceId)
.setEndpointName(endpointName)
.setEndpointId(endpointId)
.setFrom(endpoint.getFrom()));
}
} else {
logger.warn("Unexpected endpoint register, endpoint isn't detected from server side. {}", request);
}
});
responseObserver.onNext(builder.build());
responseObserver.onNext(EndpointMapping.newBuilder().build());
responseObserver.onCompleted();
}
......
......@@ -19,9 +19,7 @@
package org.apache.skywalking.oap.server.receiver.sharing.server;
import org.apache.skywalking.oap.server.core.CoreModule;
import org.apache.skywalking.oap.server.core.cache.EndpointInventoryCache;
import org.apache.skywalking.oap.server.core.cache.ServiceInventoryCache;
import org.apache.skywalking.oap.server.core.register.service.IEndpointInventoryRegister;
import org.apache.skywalking.oap.server.core.register.service.IServiceInstanceInventoryRegister;
import org.apache.skywalking.oap.server.core.register.service.IServiceInventoryRegister;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
......@@ -30,9 +28,7 @@ public class CoreRegisterLinker {
private static volatile ModuleManager MODULE_MANAGER;
private static volatile IServiceInventoryRegister SERVICE_INVENTORY_REGISTER;
private static volatile IServiceInstanceInventoryRegister SERVICE_INSTANCE_INVENTORY_REGISTER;
private static volatile IEndpointInventoryRegister ENDPOINT_INVENTORY_REGISTER;
private static volatile ServiceInventoryCache SERVICE_INVENTORY_CACHE;
private static volatile EndpointInventoryCache ENDPOINT_INVENTORY_CACHE;
public static void setModuleManager(ModuleManager moduleManager) {
CoreRegisterLinker.MODULE_MANAGER = moduleManager;
......@@ -56,15 +52,6 @@ public class CoreRegisterLinker {
return SERVICE_INSTANCE_INVENTORY_REGISTER;
}
public static IEndpointInventoryRegister getEndpointInventoryRegister() {
if (ENDPOINT_INVENTORY_REGISTER == null) {
ENDPOINT_INVENTORY_REGISTER = MODULE_MANAGER.find(CoreModule.NAME)
.provider()
.getService(IEndpointInventoryRegister.class);
}
return ENDPOINT_INVENTORY_REGISTER;
}
public static ServiceInventoryCache getServiceInventoryCache() {
if (SERVICE_INVENTORY_CACHE == null) {
SERVICE_INVENTORY_CACHE = MODULE_MANAGER.find(CoreModule.NAME)
......@@ -73,13 +60,4 @@ public class CoreRegisterLinker {
}
return SERVICE_INVENTORY_CACHE;
}
public static EndpointInventoryCache getEndpointInventoryCache() {
if (ENDPOINT_INVENTORY_CACHE == null) {
ENDPOINT_INVENTORY_CACHE = MODULE_MANAGER.find(CoreModule.NAME)
.provider()
.getService(EndpointInventoryCache.class);
}
return ENDPOINT_INVENTORY_CACHE;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册