Ignore no upstream real address agent (#4454)
* ignore no upstream real address agent * fix bug * follow review * fix checkstyle * follow review * follow review * follow review * follow review * follow review * fix language trans * lower case
This commit is contained in:
parent
238007d3a5
commit
7a302d4ff3
|
|
@ -20,7 +20,7 @@ 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 lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.skywalking.oap.server.core.Const;
|
||||
import org.apache.skywalking.oap.server.core.CoreModuleConfig;
|
||||
import org.apache.skywalking.oap.server.core.register.ServiceInstanceInventory;
|
||||
|
|
@ -29,15 +29,14 @@ import org.apache.skywalking.oap.server.core.storage.cache.IServiceInstanceInven
|
|||
import org.apache.skywalking.oap.server.library.module.ModuleManager;
|
||||
import org.apache.skywalking.oap.server.library.module.Service;
|
||||
import org.apache.skywalking.oap.server.library.util.BooleanUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import static java.util.Objects.isNull;
|
||||
|
||||
@Slf4j
|
||||
public class ServiceInstanceInventoryCache implements Service {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ServiceInstanceInventoryCache.class);
|
||||
|
||||
private final ServiceInstanceInventory userServiceInstance;
|
||||
private final Cache<Integer, ServiceInstanceInventory> serviceInstanceIdCache;
|
||||
private final Cache<String, Integer> serviceInstanceNameCache;
|
||||
|
|
@ -58,24 +57,24 @@ public class ServiceInstanceInventoryCache implements Service {
|
|||
int initialCapacitySize = (int) (initialSize > Integer.MAX_VALUE ? Integer.MAX_VALUE : initialSize);
|
||||
|
||||
serviceInstanceIdCache = CacheBuilder.newBuilder()
|
||||
.initialCapacity(initialCapacitySize)
|
||||
.maximumSize(moduleConfig.getMaxSizeOfServiceInstanceInventory())
|
||||
.build();
|
||||
.initialCapacity(initialCapacitySize)
|
||||
.maximumSize(moduleConfig.getMaxSizeOfServiceInstanceInventory())
|
||||
.build();
|
||||
serviceInstanceNameCache = CacheBuilder.newBuilder()
|
||||
.initialCapacity(initialCapacitySize)
|
||||
.maximumSize(moduleConfig.getMaxSizeOfServiceInstanceInventory())
|
||||
.build();
|
||||
.initialCapacity(initialCapacitySize)
|
||||
.maximumSize(moduleConfig.getMaxSizeOfServiceInstanceInventory())
|
||||
.build();
|
||||
addressIdCache = CacheBuilder.newBuilder()
|
||||
.initialCapacity(initialCapacitySize)
|
||||
.maximumSize(moduleConfig.getMaxSizeOfServiceInstanceInventory())
|
||||
.build();
|
||||
.initialCapacity(initialCapacitySize)
|
||||
.maximumSize(moduleConfig.getMaxSizeOfServiceInstanceInventory())
|
||||
.build();
|
||||
}
|
||||
|
||||
private IServiceInstanceInventoryCacheDAO getCacheDAO() {
|
||||
if (isNull(cacheDAO)) {
|
||||
this.cacheDAO = moduleManager.find(StorageModule.NAME)
|
||||
.provider()
|
||||
.getService(IServiceInstanceInventoryCacheDAO.class);
|
||||
.provider()
|
||||
.getService(IServiceInstanceInventoryCacheDAO.class);
|
||||
}
|
||||
return this.cacheDAO;
|
||||
}
|
||||
|
|
@ -119,4 +118,12 @@ public class ServiceInstanceInventoryCache implements Service {
|
|||
}
|
||||
return serviceInstanceId;
|
||||
}
|
||||
|
||||
public String getServiceInstanceLanguage(int serviceInstanceId) {
|
||||
ServiceInstanceInventory inventory = get(serviceInstanceId);
|
||||
if (isNull(inventory)) {
|
||||
return Const.EMPTY_STRING;
|
||||
}
|
||||
return inventory.getLanguage();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,5 +19,5 @@
|
|||
package org.apache.skywalking.oap.server.core.query.entity;
|
||||
|
||||
public enum Language {
|
||||
UNKNOWN, JAVA, DOTNET, NODEJS, PYTHON, RUBY
|
||||
UNKNOWN, JAVA, DOTNET, NODEJS, PYTHON, RUBY, GO, LUA
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,10 @@ public enum LanguageTrans {
|
|||
return Language.PYTHON;
|
||||
case "ruby":
|
||||
return Language.RUBY;
|
||||
case "go":
|
||||
return Language.GO;
|
||||
case "lua":
|
||||
return Language.LUA;
|
||||
default:
|
||||
return Language.UNKNOWN;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ import org.apache.skywalking.oap.server.core.storage.StorageBuilder;
|
|||
import org.apache.skywalking.oap.server.core.storage.annotation.Column;
|
||||
import org.apache.skywalking.oap.server.library.util.BooleanUtils;
|
||||
|
||||
import static java.util.Objects.nonNull;
|
||||
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SERVICE_INSTANCE_INVENTORY;
|
||||
|
||||
@ScopeDeclaration(id = SERVICE_INSTANCE_INVENTORY, name = "ServiceInstanceInventory")
|
||||
|
|
@ -94,6 +95,9 @@ public class ServiceInstanceInventory extends RegisterSource {
|
|||
@Getter
|
||||
private boolean resetServiceInstanceMapping = false;
|
||||
|
||||
@Getter
|
||||
private String language;
|
||||
|
||||
public static String buildId(int serviceId, String uuid) {
|
||||
return serviceId + Const.ID_SPLIT + uuid + Const.ID_SPLIT + BooleanUtils.FALSE + Const.ID_SPLIT + Const.NONE;
|
||||
}
|
||||
|
|
@ -134,6 +138,7 @@ public class ServiceInstanceInventory extends RegisterSource {
|
|||
if (properties != null && properties.keySet().size() > 0) {
|
||||
this.prop = properties.toString();
|
||||
}
|
||||
setLanguage(properties);
|
||||
}
|
||||
|
||||
private void setProp(String prop) {
|
||||
|
|
@ -141,6 +146,19 @@ public class ServiceInstanceInventory extends RegisterSource {
|
|||
if (!Strings.isNullOrEmpty(prop)) {
|
||||
this.properties = GSON.fromJson(prop, JsonObject.class);
|
||||
}
|
||||
setLanguage(properties);
|
||||
}
|
||||
|
||||
private void setLanguage(JsonObject properties) {
|
||||
if (nonNull(properties)) {
|
||||
for (String key : properties.keySet()) {
|
||||
if (key.equals(ServiceInstanceInventory.PropertyUtil.LANGUAGE)) {
|
||||
language = properties.get(key).getAsString();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
language = Const.UNKNOWN;
|
||||
}
|
||||
|
||||
public boolean hasProperties() {
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit 8c9a8c45b9dbe954efa6de50202d05b1ef8e6be2
|
||||
Subproject commit 06373bf0d1204b6d3f410c0daf4c7f72529f28a0
|
||||
|
|
@ -156,7 +156,7 @@ public class RegisterServiceHandler extends RegisterGrpc.RegisterImplBase implem
|
|||
instanceProperties.addProperty(OS_NAME, property.getValue());
|
||||
break;
|
||||
case LANGUAGE:
|
||||
instanceProperties.addProperty(LANGUAGE, property.getValue());
|
||||
instanceProperties.addProperty(LANGUAGE, property.getValue().toLowerCase());
|
||||
break;
|
||||
case "ipv4":
|
||||
ipv4s.add(property.getValue());
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@
|
|||
|
||||
package org.apache.skywalking.oap.server.receiver.trace.provider;
|
||||
|
||||
import java.io.IOException;
|
||||
import org.apache.skywalking.oap.server.configuration.api.ConfigurationModule;
|
||||
import org.apache.skywalking.oap.server.configuration.api.DynamicConfigurationService;
|
||||
import org.apache.skywalking.oap.server.core.CoreModule;
|
||||
|
|
@ -44,6 +43,8 @@ import org.apache.skywalking.oap.server.receiver.trace.provider.parser.listener.
|
|||
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.standardization.SegmentStandardizationWorker;
|
||||
import org.apache.skywalking.oap.server.telemetry.TelemetryModule;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class TraceModuleProvider extends ModuleProvider {
|
||||
|
||||
private final TraceServiceModuleConfig moduleConfig;
|
||||
|
|
|
|||
|
|
@ -22,6 +22,9 @@ import lombok.Getter;
|
|||
import lombok.Setter;
|
||||
import org.apache.skywalking.oap.server.library.module.ModuleConfig;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class TraceServiceModuleConfig extends ModuleConfig {
|
||||
@Setter
|
||||
@Getter
|
||||
|
|
@ -41,7 +44,12 @@ public class TraceServiceModuleConfig extends ModuleConfig {
|
|||
@Setter
|
||||
@Getter
|
||||
private int sampleRate = 10000;
|
||||
|
||||
/**
|
||||
* Some of the agent can not have the upstream real network address, such as https://github.com/apache/skywalking-nginx-lua.
|
||||
* service instance mapping and service instance client side relation are ignored.
|
||||
*/
|
||||
@Getter
|
||||
private final List<String> noUpstreamRealAddressAgents = Collections.singletonList("Lua");
|
||||
/**
|
||||
* The threshold used to check the slow database access. Unit, millisecond.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ import java.util.ArrayList;
|
|||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.skywalking.apm.network.common.KeyStringValuePair;
|
||||
import org.apache.skywalking.apm.network.language.agent.SpanLayer;
|
||||
import org.apache.skywalking.apm.network.language.agent.UniqueId;
|
||||
|
|
@ -58,6 +60,7 @@ import static java.util.Objects.nonNull;
|
|||
*
|
||||
* This listener traverses the whole segment.
|
||||
*/
|
||||
@Slf4j
|
||||
public class MultiScopesSpanListener implements EntrySpanListener, ExitSpanListener, GlobalTraceIdsListener {
|
||||
|
||||
private final SourceReceiver sourceReceiver;
|
||||
|
|
@ -306,7 +309,14 @@ public class MultiScopesSpanListener implements EntrySpanListener, ExitSpanListe
|
|||
|
||||
exitSourceBuilder.setTimeBucket(minuteTimeBucket);
|
||||
sourceReceiver.receive(exitSourceBuilder.toServiceRelation());
|
||||
sourceReceiver.receive(exitSourceBuilder.toServiceInstanceRelation());
|
||||
|
||||
/*
|
||||
* Some of the agent can not have the upstream real network address, such as https://github.com/apache/skywalking-nginx-lua.
|
||||
*/
|
||||
String sourceLanguage = instanceInventoryCache.getServiceInstanceLanguage(exitSourceBuilder.getSourceServiceInstanceId());
|
||||
if (!config.getNoUpstreamRealAddressAgents().contains(sourceLanguage)) {
|
||||
sourceReceiver.receive(exitSourceBuilder.toServiceInstanceRelation());
|
||||
}
|
||||
if (RequestType.DATABASE.equals(exitSourceBuilder.getType())) {
|
||||
sourceReceiver.receive(exitSourceBuilder.toDatabaseAccess());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,8 +18,6 @@
|
|||
|
||||
package org.apache.skywalking.oap.server.receiver.trace.provider.parser.listener.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
|
@ -33,16 +31,20 @@ import org.apache.skywalking.oap.server.core.register.ServiceInstanceInventory;
|
|||
import org.apache.skywalking.oap.server.core.register.service.IServiceInstanceInventoryRegister;
|
||||
import org.apache.skywalking.oap.server.library.module.ModuleManager;
|
||||
import org.apache.skywalking.oap.server.receiver.trace.provider.TraceServiceModuleConfig;
|
||||
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.decorator.ReferenceDecorator;
|
||||
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.decorator.SegmentCoreInfo;
|
||||
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.decorator.SpanDecorator;
|
||||
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.listener.EntrySpanListener;
|
||||
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.listener.SpanListener;
|
||||
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.listener.SpanListenerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Service Instance mapping basically is as same as the service mapping. The network address fetched from the propagated
|
||||
* context is the alias for the specific service instance. This is just more detailed mapping setup.
|
||||
*
|
||||
* <p>
|
||||
* Read {@link ServiceMappingSpanListener}.
|
||||
*/
|
||||
@Slf4j
|
||||
|
|
@ -57,17 +59,17 @@ public class ServiceInstanceMappingSpanListener implements EntrySpanListener {
|
|||
|
||||
public ServiceInstanceMappingSpanListener(ModuleManager moduleManager, TraceServiceModuleConfig config) {
|
||||
this.serviceInstanceInventoryCache = moduleManager.find(CoreModule.NAME)
|
||||
.provider()
|
||||
.getService(ServiceInstanceInventoryCache.class);
|
||||
.provider()
|
||||
.getService(ServiceInstanceInventoryCache.class);
|
||||
this.serviceInventoryCache = moduleManager.find(CoreModule.NAME)
|
||||
.provider()
|
||||
.getService(ServiceInventoryCache.class);
|
||||
.provider()
|
||||
.getService(ServiceInventoryCache.class);
|
||||
this.serviceInstanceInventoryRegister = moduleManager.find(CoreModule.NAME)
|
||||
.provider()
|
||||
.getService(IServiceInstanceInventoryRegister.class);
|
||||
.provider()
|
||||
.getService(IServiceInstanceInventoryRegister.class);
|
||||
this.networkAddressInventoryCache = moduleManager.find(CoreModule.NAME)
|
||||
.provider()
|
||||
.getService(NetworkAddressInventoryCache.class);
|
||||
.provider()
|
||||
.getService(NetworkAddressInventoryCache.class);
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
|
|
@ -79,6 +81,14 @@ public class ServiceInstanceMappingSpanListener implements EntrySpanListener {
|
|||
if (!spanDecorator.getSpanLayer().equals(SpanLayer.MQ)) {
|
||||
if (spanDecorator.getRefsCount() > 0) {
|
||||
for (int i = 0; i < spanDecorator.getRefsCount(); i++) {
|
||||
ReferenceDecorator referenceDecorator = spanDecorator.getRefs(i);
|
||||
String parentLanguage = serviceInstanceInventoryCache.getServiceInstanceLanguage(referenceDecorator.getParentServiceInstanceId());
|
||||
if (config.getNoUpstreamRealAddressAgents().contains(parentLanguage)) {
|
||||
/*
|
||||
* Some of the agent can not have the upstream real network address, such as https://github.com/apache/skywalking-nginx-lua.
|
||||
*/
|
||||
continue;
|
||||
}
|
||||
int networkAddressId = spanDecorator.getRefs(i).getNetworkAddressId();
|
||||
String address = networkAddressInventoryCache.get(networkAddressId).getName();
|
||||
int serviceInstanceId = serviceInstanceInventoryCache.getServiceInstanceId(
|
||||
|
|
@ -113,7 +123,7 @@ public class ServiceInstanceMappingSpanListener implements EntrySpanListener {
|
|||
serviceInstanceMappings.forEach(instanceMapping -> {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(
|
||||
"service instance mapping listener build, service id: {}, mapping service id: {}", instanceMapping
|
||||
"service instance mapping listener build, service instance id: {}, mapping service instance id: {}", instanceMapping
|
||||
.getServiceInstanceId(), instanceMapping.getMappingServiceInstanceId());
|
||||
}
|
||||
serviceInstanceInventoryRegister.updateMapping(
|
||||
|
|
@ -121,7 +131,7 @@ public class ServiceInstanceMappingSpanListener implements EntrySpanListener {
|
|||
});
|
||||
serviceInstancesToResetMapping.forEach(instanceId -> {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("service instance mapping listener build, reset mapping of service id: {}", instanceId);
|
||||
log.debug("service instance mapping listener build, reset mapping of service instance id: {}", instanceId);
|
||||
}
|
||||
serviceInstanceInventoryRegister.resetMapping(instanceId);
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue