Provide rest protocol for register and trace receiver. (#1774)
This commit is contained in:
parent
c467e5c723
commit
72f2b1cd78
|
|
@ -19,10 +19,11 @@
|
|||
package org.apache.skywalking.oap.server.receiver.register.provider;
|
||||
|
||||
import org.apache.skywalking.oap.server.core.CoreModule;
|
||||
import org.apache.skywalking.oap.server.core.server.GRPCHandlerRegister;
|
||||
import org.apache.skywalking.oap.server.core.server.*;
|
||||
import org.apache.skywalking.oap.server.library.module.*;
|
||||
import org.apache.skywalking.oap.server.receiver.register.module.RegisterModule;
|
||||
import org.apache.skywalking.oap.server.receiver.register.provider.handler.v5.*;
|
||||
import org.apache.skywalking.oap.server.receiver.register.provider.handler.v5.grpc.*;
|
||||
import org.apache.skywalking.oap.server.receiver.register.provider.handler.v5.rest.*;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
|
|
@ -50,6 +51,13 @@ public class RegisterModuleProvider extends ModuleProvider {
|
|||
grpcHandlerRegister.addHandler(new InstanceDiscoveryServiceHandler(getManager()));
|
||||
grpcHandlerRegister.addHandler(new ServiceNameDiscoveryHandler(getManager()));
|
||||
grpcHandlerRegister.addHandler(new NetworkAddressRegisterServiceHandler(getManager()));
|
||||
|
||||
JettyHandlerRegister jettyHandlerRegister = getManager().find(CoreModule.NAME).getService(JettyHandlerRegister.class);
|
||||
jettyHandlerRegister.addHandler(new ApplicationRegisterServletHandler(getManager()));
|
||||
jettyHandlerRegister.addHandler(new InstanceDiscoveryServletHandler(getManager()));
|
||||
jettyHandlerRegister.addHandler(new InstanceHeartBeatServletHandler(getManager()));
|
||||
jettyHandlerRegister.addHandler(new NetworkAddressRegisterServletHandler(getManager()));
|
||||
jettyHandlerRegister.addHandler(new ServiceNameDiscoveryServiceHandler(getManager()));
|
||||
}
|
||||
|
||||
@Override public void notifyAfterCompleted() {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.oap.server.receiver.register.provider.handler.v5;
|
||||
package org.apache.skywalking.oap.server.receiver.register.provider.handler.v5.grpc;
|
||||
|
||||
import io.grpc.stub.StreamObserver;
|
||||
import org.apache.skywalking.apm.network.language.agent.*;
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.oap.server.receiver.register.provider.handler.v5;
|
||||
package org.apache.skywalking.oap.server.receiver.register.provider.handler.v5.grpc;
|
||||
|
||||
import io.grpc.stub.StreamObserver;
|
||||
import org.apache.skywalking.apm.network.language.agent.*;
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.oap.server.receiver.register.provider.handler.v5;
|
||||
package org.apache.skywalking.oap.server.receiver.register.provider.handler.v5.grpc;
|
||||
|
||||
import com.google.protobuf.ProtocolStringList;
|
||||
import io.grpc.stub.StreamObserver;
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.oap.server.receiver.register.provider.handler.v5;
|
||||
package org.apache.skywalking.oap.server.receiver.register.provider.handler.v5.grpc;
|
||||
|
||||
import io.grpc.stub.StreamObserver;
|
||||
import java.util.List;
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* 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.receiver.register.provider.handler.v5.rest;
|
||||
|
||||
import com.google.gson.*;
|
||||
import java.io.IOException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import org.apache.skywalking.oap.server.core.CoreModule;
|
||||
import org.apache.skywalking.oap.server.core.register.service.IServiceInventoryRegister;
|
||||
import org.apache.skywalking.oap.server.library.module.ModuleManager;
|
||||
import org.apache.skywalking.oap.server.library.server.jetty.*;
|
||||
import org.slf4j.*;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
public class ApplicationRegisterServletHandler extends JettyJsonHandler {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ApplicationRegisterServletHandler.class);
|
||||
|
||||
private final IServiceInventoryRegister serviceInventoryRegister;
|
||||
private Gson gson = new Gson();
|
||||
private static final String APPLICATION_CODE = "c";
|
||||
private static final String APPLICATION_ID = "i";
|
||||
|
||||
public ApplicationRegisterServletHandler(ModuleManager moduleManager) {
|
||||
serviceInventoryRegister = moduleManager.find(CoreModule.NAME).getService(IServiceInventoryRegister.class);
|
||||
}
|
||||
|
||||
@Override public String pathSpec() {
|
||||
return "/application/register";
|
||||
}
|
||||
|
||||
@Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException {
|
||||
JsonArray responseArray = new JsonArray();
|
||||
try {
|
||||
JsonArray applicationCodes = gson.fromJson(req.getReader(), JsonArray.class);
|
||||
for (int i = 0; i < applicationCodes.size(); i++) {
|
||||
String applicationCode = applicationCodes.get(i).getAsString();
|
||||
int applicationId = serviceInventoryRegister.getOrCreate(applicationCode);
|
||||
JsonObject mapping = new JsonObject();
|
||||
mapping.addProperty(APPLICATION_CODE, applicationCode);
|
||||
mapping.addProperty(APPLICATION_ID, applicationId);
|
||||
responseArray.add(mapping);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
return responseArray;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* 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.receiver.register.provider.handler.v5.rest;
|
||||
|
||||
import com.google.gson.*;
|
||||
import java.io.IOException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import org.apache.skywalking.oap.server.core.CoreModule;
|
||||
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.library.server.jetty.*;
|
||||
import org.slf4j.*;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
public class InstanceDiscoveryServletHandler extends JettyJsonHandler {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(InstanceDiscoveryServletHandler.class);
|
||||
|
||||
private final IServiceInstanceInventoryRegister serviceInstanceInventoryRegister;
|
||||
private final Gson gson = new Gson();
|
||||
|
||||
private static final String APPLICATION_ID = "ai";
|
||||
private static final String AGENT_UUID = "au";
|
||||
private static final String REGISTER_TIME = "rt";
|
||||
private static final String INSTANCE_ID = "ii";
|
||||
private static final String OS_INFO = "oi";
|
||||
|
||||
public InstanceDiscoveryServletHandler(ModuleManager moduleManager) {
|
||||
this.serviceInstanceInventoryRegister = moduleManager.find(CoreModule.NAME).getService(IServiceInstanceInventoryRegister.class);
|
||||
}
|
||||
|
||||
@Override public String pathSpec() {
|
||||
return "/instance/register";
|
||||
}
|
||||
|
||||
@Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException {
|
||||
JsonObject responseJson = new JsonObject();
|
||||
try {
|
||||
JsonObject instance = gson.fromJson(req.getReader(), JsonObject.class);
|
||||
int applicationId = instance.get(APPLICATION_ID).getAsInt();
|
||||
String agentUUID = instance.get(AGENT_UUID).getAsString();
|
||||
long registerTime = instance.get(REGISTER_TIME).getAsLong();
|
||||
JsonObject osInfoJson = instance.get(OS_INFO).getAsJsonObject();
|
||||
|
||||
ServiceInstanceInventory.AgentOsInfo agentOsInfo = new ServiceInstanceInventory.AgentOsInfo();
|
||||
agentOsInfo.setHostname(osInfoJson.get("osName").getAsString());
|
||||
agentOsInfo.setOsName(osInfoJson.get("hostName").getAsString());
|
||||
agentOsInfo.setProcessNo(osInfoJson.get("processId").getAsInt());
|
||||
|
||||
JsonArray ipv4s = osInfoJson.get("ipv4s").getAsJsonArray();
|
||||
ipv4s.forEach(ipv4 -> agentOsInfo.getIpv4s().add(ipv4.getAsString()));
|
||||
|
||||
int instanceId = serviceInstanceInventoryRegister.getOrCreate(applicationId, agentUUID, registerTime, agentOsInfo);
|
||||
responseJson.addProperty(APPLICATION_ID, applicationId);
|
||||
responseJson.addProperty(INSTANCE_ID, instanceId);
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
return responseJson;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* 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.receiver.register.provider.handler.v5.rest;
|
||||
|
||||
import com.google.gson.*;
|
||||
import java.io.IOException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import org.apache.skywalking.oap.server.core.CoreModule;
|
||||
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.library.server.jetty.*;
|
||||
import org.slf4j.*;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
public class InstanceHeartBeatServletHandler extends JettyJsonHandler {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(InstanceHeartBeatServletHandler.class);
|
||||
|
||||
private final IServiceInstanceInventoryRegister serviceInstanceInventoryRegister;
|
||||
private final Gson gson = new Gson();
|
||||
|
||||
private static final String INSTANCE_ID = "ii";
|
||||
private static final String HEARTBEAT_TIME = "ht";
|
||||
|
||||
public InstanceHeartBeatServletHandler(ModuleManager moduleManager) {
|
||||
this.serviceInstanceInventoryRegister = moduleManager.find(CoreModule.NAME).getService(IServiceInstanceInventoryRegister.class);
|
||||
}
|
||||
|
||||
@Override public String pathSpec() {
|
||||
return "/instance/heartbeat";
|
||||
}
|
||||
|
||||
@Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException, IOException {
|
||||
JsonObject responseJson = new JsonObject();
|
||||
try {
|
||||
JsonObject heartBeat = gson.fromJson(req.getReader(), JsonObject.class);
|
||||
int instanceId = heartBeat.get(INSTANCE_ID).getAsInt();
|
||||
long heartBeatTime = heartBeat.get(HEARTBEAT_TIME).getAsLong();
|
||||
|
||||
serviceInstanceInventoryRegister.heartbeat(instanceId, heartBeatTime);
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
return responseJson;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* 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.receiver.register.provider.handler.v5.rest;
|
||||
|
||||
import com.google.gson.*;
|
||||
import java.io.IOException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import org.apache.skywalking.oap.server.core.CoreModule;
|
||||
import org.apache.skywalking.oap.server.core.register.service.INetworkAddressInventoryRegister;
|
||||
import org.apache.skywalking.oap.server.library.module.ModuleManager;
|
||||
import org.apache.skywalking.oap.server.library.server.jetty.JettyJsonHandler;
|
||||
import org.slf4j.*;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
public class NetworkAddressRegisterServletHandler extends JettyJsonHandler {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(NetworkAddressRegisterServletHandler.class);
|
||||
|
||||
private final INetworkAddressInventoryRegister networkAddressInventoryRegister;
|
||||
private Gson gson = new Gson();
|
||||
private static final String NETWORK_ADDRESS = "n";
|
||||
private static final String ADDRESS_ID = "i";
|
||||
|
||||
public NetworkAddressRegisterServletHandler(ModuleManager moduleManager) {
|
||||
this.networkAddressInventoryRegister = moduleManager.find(CoreModule.NAME).getService(INetworkAddressInventoryRegister.class);
|
||||
}
|
||||
|
||||
@Override public String pathSpec() {
|
||||
return "/networkAddress/register";
|
||||
}
|
||||
|
||||
@Override protected JsonElement doGet(HttpServletRequest req) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override protected JsonElement doPost(HttpServletRequest req) {
|
||||
JsonArray responseArray = new JsonArray();
|
||||
try {
|
||||
JsonArray networkAddresses = gson.fromJson(req.getReader(), JsonArray.class);
|
||||
for (int i = 0; i < networkAddresses.size(); i++) {
|
||||
String networkAddress = networkAddresses.get(i).getAsString();
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("network address register, network address: {}", networkAddress);
|
||||
}
|
||||
|
||||
int addressId = networkAddressInventoryRegister.getOrCreate(networkAddress);
|
||||
JsonObject mapping = new JsonObject();
|
||||
mapping.addProperty(ADDRESS_ID, addressId);
|
||||
mapping.addProperty(NETWORK_ADDRESS, networkAddress);
|
||||
responseArray.add(mapping);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
return responseArray;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
* 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.receiver.register.provider.handler.v5.rest;
|
||||
|
||||
import com.google.gson.*;
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import org.apache.skywalking.apm.network.language.agent.SpanType;
|
||||
import org.apache.skywalking.oap.server.core.CoreModule;
|
||||
import org.apache.skywalking.oap.server.core.register.service.IEndpointInventoryRegister;
|
||||
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.jetty.*;
|
||||
import org.slf4j.*;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
public class ServiceNameDiscoveryServiceHandler extends JettyJsonHandler {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ServiceNameDiscoveryServiceHandler.class);
|
||||
|
||||
private final IEndpointInventoryRegister inventoryService;
|
||||
private final Gson gson = new Gson();
|
||||
|
||||
private static final String APPLICATION_ID = "ai";
|
||||
private static final String SERVICE_NAME = "sn";
|
||||
private static final String SRC_SPAN_TYPE = "st";
|
||||
private static final String SERVICE_ID = "si";
|
||||
private static final String ELEMENT = "el";
|
||||
|
||||
public ServiceNameDiscoveryServiceHandler(ModuleManager moduleManager) {
|
||||
this.inventoryService = moduleManager.find(CoreModule.NAME).getService(IEndpointInventoryRegister.class);
|
||||
}
|
||||
|
||||
@Override public String pathSpec() {
|
||||
return "/servicename/discovery";
|
||||
}
|
||||
|
||||
@Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException {
|
||||
JsonArray responseArray = new JsonArray();
|
||||
try {
|
||||
JsonArray services = gson.fromJson(req.getReader(), JsonArray.class);
|
||||
for (JsonElement service : services) {
|
||||
int applicationId = service.getAsJsonObject().get(APPLICATION_ID).getAsInt();
|
||||
String serviceName = service.getAsJsonObject().get(SERVICE_NAME).getAsString();
|
||||
int srcSpanType = service.getAsJsonObject().get(SRC_SPAN_TYPE).getAsInt();
|
||||
|
||||
SpanType spanType = SpanType.forNumber(srcSpanType);
|
||||
if (Objects.nonNull(spanType)) {
|
||||
int serviceId = inventoryService.getOrCreate(applicationId, serviceName, DetectPoint.fromSpanType(spanType));
|
||||
if (serviceId != 0) {
|
||||
JsonObject responseJson = new JsonObject();
|
||||
responseJson.addProperty(SERVICE_ID, serviceId);
|
||||
responseJson.add(ELEMENT, service);
|
||||
responseArray.add(responseJson);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
return responseArray;
|
||||
}
|
||||
}
|
||||
|
|
@ -20,10 +20,11 @@ package org.apache.skywalking.oap.server.receiver.trace.provider;
|
|||
|
||||
import java.io.IOException;
|
||||
import org.apache.skywalking.oap.server.core.CoreModule;
|
||||
import org.apache.skywalking.oap.server.core.server.GRPCHandlerRegister;
|
||||
import org.apache.skywalking.oap.server.core.server.*;
|
||||
import org.apache.skywalking.oap.server.library.module.*;
|
||||
import org.apache.skywalking.oap.server.receiver.trace.module.TraceModule;
|
||||
import org.apache.skywalking.oap.server.receiver.trace.provider.handler.TraceSegmentServiceHandler;
|
||||
import org.apache.skywalking.oap.server.receiver.trace.provider.handler.v5.grpc.TraceSegmentServiceHandler;
|
||||
import org.apache.skywalking.oap.server.receiver.trace.provider.handler.v5.rest.TraceSegmentServletHandler;
|
||||
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.*;
|
||||
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.listener.endpoint.MultiScopesSpanListener;
|
||||
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.listener.segment.SegmentSpanListener;
|
||||
|
|
@ -64,9 +65,11 @@ public class TraceModuleProvider extends ModuleProvider {
|
|||
listenerManager.add(new SegmentSpanListener.Factory());
|
||||
|
||||
GRPCHandlerRegister grpcHandlerRegister = getManager().find(CoreModule.NAME).getService(GRPCHandlerRegister.class);
|
||||
JettyHandlerRegister jettyHandlerRegister = getManager().find(CoreModule.NAME).getService(JettyHandlerRegister.class);
|
||||
try {
|
||||
SegmentParse segmentParse = new SegmentParse(getManager(), listenerManager);
|
||||
grpcHandlerRegister.addHandler(new TraceSegmentServiceHandler(segmentParse));
|
||||
jettyHandlerRegister.addHandler(new TraceSegmentServletHandler(segmentParse));
|
||||
|
||||
SegmentStandardizationWorker standardizationWorker = new SegmentStandardizationWorker(segmentParse, moduleConfig.getBufferPath(), moduleConfig.getBufferOffsetMaxFileSize(), moduleConfig.getBufferDataMaxFileSize(), moduleConfig.isBufferFileCleanWhenRestart());
|
||||
segmentParse.setStandardizationWorker(standardizationWorker);
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.oap.server.receiver.trace.provider.handler;
|
||||
package org.apache.skywalking.oap.server.receiver.trace.provider.handler.v5.grpc;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.oap.server.receiver.trace.provider.handler;
|
||||
package org.apache.skywalking.oap.server.receiver.trace.provider.handler.v5.grpc;
|
||||
|
||||
import io.grpc.stub.StreamObserver;
|
||||
import org.apache.skywalking.apm.network.language.agent.*;
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* 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.receiver.trace.provider.handler.v5.rest;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import java.io.*;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import org.apache.skywalking.oap.server.library.server.jetty.JettyJsonHandler;
|
||||
import org.apache.skywalking.oap.server.receiver.trace.provider.handler.v5.rest.reader.*;
|
||||
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.SegmentParse;
|
||||
import org.slf4j.*;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
public class TraceSegmentServletHandler extends JettyJsonHandler {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(TraceSegmentServletHandler.class);
|
||||
|
||||
private final SegmentParse segmentParse;
|
||||
|
||||
public TraceSegmentServletHandler(SegmentParse segmentParse) {
|
||||
this.segmentParse = segmentParse;
|
||||
}
|
||||
|
||||
@Override public String pathSpec() {
|
||||
return "/segments";
|
||||
}
|
||||
|
||||
@Override protected JsonElement doGet(HttpServletRequest req) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override protected JsonElement doPost(HttpServletRequest req) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("receive stream segment");
|
||||
}
|
||||
|
||||
try {
|
||||
BufferedReader bufferedReader = req.getReader();
|
||||
read(bufferedReader);
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private TraceSegmentJsonReader jsonReader = new TraceSegmentJsonReader();
|
||||
|
||||
private void read(BufferedReader bufferedReader) throws IOException {
|
||||
JsonReader reader = new JsonReader(bufferedReader);
|
||||
|
||||
reader.beginArray();
|
||||
while (reader.hasNext()) {
|
||||
TraceSegment traceSegment = jsonReader.read(reader);
|
||||
segmentParse.parse(traceSegment.getUpstreamSegment(), SegmentParse.Source.Agent);
|
||||
}
|
||||
reader.endArray();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* 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.receiver.trace.provider.handler.v5.rest.reader;
|
||||
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import java.io.IOException;
|
||||
import org.apache.skywalking.apm.network.language.agent.KeyWithStringValue;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
public class KeyWithStringValueJsonReader implements StreamJsonReader<KeyWithStringValue> {
|
||||
|
||||
private static final String KEY = "k";
|
||||
private static final String VALUE = "v";
|
||||
|
||||
@Override public KeyWithStringValue read(JsonReader reader) throws IOException {
|
||||
KeyWithStringValue.Builder builder = KeyWithStringValue.newBuilder();
|
||||
|
||||
reader.beginObject();
|
||||
while (reader.hasNext()) {
|
||||
switch (reader.nextName()) {
|
||||
case KEY:
|
||||
builder.setKey(reader.nextString());
|
||||
break;
|
||||
case VALUE:
|
||||
builder.setValue(reader.nextString());
|
||||
break;
|
||||
default:
|
||||
reader.skipValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
reader.endObject();
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* 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.receiver.trace.provider.handler.v5.rest.reader;
|
||||
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import java.io.IOException;
|
||||
import org.apache.skywalking.apm.network.language.agent.LogMessage;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
public class LogJsonReader implements StreamJsonReader<LogMessage> {
|
||||
|
||||
private KeyWithStringValueJsonReader keyWithStringValueJsonReader = new KeyWithStringValueJsonReader();
|
||||
|
||||
private static final String TIME = "ti";
|
||||
private static final String LOG_DATA = "ld";
|
||||
|
||||
@Override public LogMessage read(JsonReader reader) throws IOException {
|
||||
LogMessage.Builder builder = LogMessage.newBuilder();
|
||||
|
||||
reader.beginObject();
|
||||
while (reader.hasNext()) {
|
||||
switch (reader.nextName()) {
|
||||
case TIME:
|
||||
builder.setTime(reader.nextLong());
|
||||
break;
|
||||
case LOG_DATA:
|
||||
reader.beginArray();
|
||||
while (reader.hasNext()) {
|
||||
builder.addData(keyWithStringValueJsonReader.read(reader));
|
||||
}
|
||||
reader.endArray();
|
||||
break;
|
||||
default:
|
||||
reader.skipValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
reader.endObject();
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* 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.receiver.trace.provider.handler.v5.rest.reader;
|
||||
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import java.io.IOException;
|
||||
import org.apache.skywalking.apm.network.language.agent.TraceSegmentReference;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
public class ReferenceJsonReader implements StreamJsonReader<TraceSegmentReference> {
|
||||
|
||||
private UniqueIdJsonReader uniqueIdJsonReader = new UniqueIdJsonReader();
|
||||
|
||||
private static final String PARENT_TRACE_SEGMENT_ID = "pts";
|
||||
private static final String PARENT_APPLICATION_INSTANCE_ID = "pii";
|
||||
private static final String PARENT_SPAN_ID = "psp";
|
||||
private static final String PARENT_SERVICE_ID = "psi";
|
||||
private static final String PARENT_SERVICE_NAME = "psn";
|
||||
private static final String NETWORK_ADDRESS_ID = "ni";
|
||||
private static final String NETWORK_ADDRESS = "nn";
|
||||
private static final String ENTRY_APPLICATION_INSTANCE_ID = "eii";
|
||||
private static final String ENTRY_SERVICE_ID = "esi";
|
||||
private static final String ENTRY_SERVICE_NAME = "esn";
|
||||
private static final String REF_TYPE_VALUE = "rv";
|
||||
|
||||
@Override public TraceSegmentReference read(JsonReader reader) throws IOException {
|
||||
TraceSegmentReference.Builder builder = TraceSegmentReference.newBuilder();
|
||||
|
||||
reader.beginObject();
|
||||
while (reader.hasNext()) {
|
||||
switch (reader.nextName()) {
|
||||
case PARENT_TRACE_SEGMENT_ID:
|
||||
builder.setParentTraceSegmentId(uniqueIdJsonReader.read(reader));
|
||||
break;
|
||||
case PARENT_APPLICATION_INSTANCE_ID:
|
||||
builder.setParentApplicationInstanceId(reader.nextInt());
|
||||
break;
|
||||
case PARENT_SPAN_ID:
|
||||
builder.setParentSpanId(reader.nextInt());
|
||||
break;
|
||||
case PARENT_SERVICE_ID:
|
||||
builder.setParentServiceId(reader.nextInt());
|
||||
break;
|
||||
case PARENT_SERVICE_NAME:
|
||||
builder.setParentServiceName(reader.nextString());
|
||||
break;
|
||||
case NETWORK_ADDRESS_ID:
|
||||
builder.setNetworkAddressId(reader.nextInt());
|
||||
break;
|
||||
case NETWORK_ADDRESS:
|
||||
builder.setNetworkAddress(reader.nextString());
|
||||
break;
|
||||
case ENTRY_APPLICATION_INSTANCE_ID:
|
||||
builder.setEntryApplicationInstanceId(reader.nextInt());
|
||||
break;
|
||||
case ENTRY_SERVICE_ID:
|
||||
builder.setEntryServiceId(reader.nextInt());
|
||||
break;
|
||||
case ENTRY_SERVICE_NAME:
|
||||
builder.setEntryServiceName(reader.nextString());
|
||||
break;
|
||||
case REF_TYPE_VALUE:
|
||||
builder.setRefTypeValue(reader.nextInt());
|
||||
break;
|
||||
default:
|
||||
reader.skipValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
reader.endObject();
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* 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.receiver.trace.provider.handler.v5.rest.reader;
|
||||
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import java.io.IOException;
|
||||
import org.apache.skywalking.apm.network.language.agent.TraceSegmentObject;
|
||||
import org.slf4j.*;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
public class SegmentJsonReader implements StreamJsonReader<TraceSegmentObject.Builder> {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SegmentJsonReader.class);
|
||||
|
||||
private UniqueIdJsonReader uniqueIdJsonReader = new UniqueIdJsonReader();
|
||||
private SpanJsonReader spanJsonReader = new SpanJsonReader();
|
||||
|
||||
private static final String TRACE_SEGMENT_ID = "ts";
|
||||
private static final String APPLICATION_ID = "ai";
|
||||
private static final String APPLICATION_INSTANCE_ID = "ii";
|
||||
private static final String SPANS = "ss";
|
||||
|
||||
@Override public TraceSegmentObject.Builder read(JsonReader reader) throws IOException {
|
||||
TraceSegmentObject.Builder builder = TraceSegmentObject.newBuilder();
|
||||
|
||||
reader.beginObject();
|
||||
while (reader.hasNext()) {
|
||||
switch (reader.nextName()) {
|
||||
case TRACE_SEGMENT_ID:
|
||||
builder.setTraceSegmentId(uniqueIdJsonReader.read(reader));
|
||||
if (logger.isDebugEnabled()) {
|
||||
StringBuilder segmentId = new StringBuilder();
|
||||
builder.getTraceSegmentId().getIdPartsList().forEach(idPart -> segmentId.append(idPart));
|
||||
logger.debug("segment id: {}", segmentId);
|
||||
}
|
||||
break;
|
||||
case APPLICATION_ID:
|
||||
builder.setApplicationId(reader.nextInt());
|
||||
break;
|
||||
case APPLICATION_INSTANCE_ID:
|
||||
builder.setApplicationInstanceId(reader.nextInt());
|
||||
break;
|
||||
case SPANS:
|
||||
reader.beginArray();
|
||||
while (reader.hasNext()) {
|
||||
builder.addSpans(spanJsonReader.read(reader));
|
||||
}
|
||||
reader.endArray();
|
||||
break;
|
||||
default:
|
||||
reader.skipValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
reader.endObject();
|
||||
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,126 @@
|
|||
/*
|
||||
* 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.receiver.trace.provider.handler.v5.rest.reader;
|
||||
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import java.io.IOException;
|
||||
import org.apache.skywalking.apm.network.language.agent.SpanObject;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
public class SpanJsonReader implements StreamJsonReader<SpanObject> {
|
||||
|
||||
private KeyWithStringValueJsonReader keyWithStringValueJsonReader = new KeyWithStringValueJsonReader();
|
||||
private LogJsonReader logJsonReader = new LogJsonReader();
|
||||
private ReferenceJsonReader referenceJsonReader = new ReferenceJsonReader();
|
||||
|
||||
private static final String SPAN_ID = "si";
|
||||
private static final String SPAN_TYPE_VALUE = "tv";
|
||||
private static final String SPAN_LAYER_VALUE = "lv";
|
||||
private static final String PARENT_SPAN_ID = "ps";
|
||||
private static final String START_TIME = "st";
|
||||
private static final String END_TIME = "et";
|
||||
private static final String COMPONENT_ID = "ci";
|
||||
private static final String COMPONENT_NAME = "cn";
|
||||
private static final String OPERATION_NAME_ID = "oi";
|
||||
private static final String OPERATION_NAME = "on";
|
||||
private static final String PEER_ID = "pi";
|
||||
private static final String PEER = "pn";
|
||||
private static final String IS_ERROR = "ie";
|
||||
private static final String TRACE_SEGMENT_REFERENCE = "rs";
|
||||
private static final String TAGS = "to";
|
||||
private static final String LOGS = "lo";
|
||||
|
||||
@Override public SpanObject read(JsonReader reader) throws IOException {
|
||||
SpanObject.Builder builder = SpanObject.newBuilder();
|
||||
|
||||
reader.beginObject();
|
||||
while (reader.hasNext()) {
|
||||
switch (reader.nextName()) {
|
||||
case SPAN_ID:
|
||||
builder.setSpanId(reader.nextInt());
|
||||
break;
|
||||
case SPAN_TYPE_VALUE:
|
||||
builder.setSpanTypeValue(reader.nextInt());
|
||||
break;
|
||||
case SPAN_LAYER_VALUE:
|
||||
builder.setSpanLayerValue(reader.nextInt());
|
||||
break;
|
||||
case PARENT_SPAN_ID:
|
||||
builder.setParentSpanId(reader.nextInt());
|
||||
break;
|
||||
case START_TIME:
|
||||
builder.setStartTime(reader.nextLong());
|
||||
break;
|
||||
case END_TIME:
|
||||
builder.setEndTime(reader.nextLong());
|
||||
break;
|
||||
case COMPONENT_ID:
|
||||
builder.setComponentId(reader.nextInt());
|
||||
break;
|
||||
case COMPONENT_NAME:
|
||||
builder.setComponent(reader.nextString());
|
||||
break;
|
||||
case OPERATION_NAME_ID:
|
||||
builder.setOperationNameId(reader.nextInt());
|
||||
break;
|
||||
case OPERATION_NAME:
|
||||
builder.setOperationName(reader.nextString());
|
||||
break;
|
||||
case PEER_ID:
|
||||
builder.setPeerId(reader.nextInt());
|
||||
break;
|
||||
case PEER:
|
||||
builder.setPeer(reader.nextString());
|
||||
break;
|
||||
case IS_ERROR:
|
||||
builder.setIsError(reader.nextBoolean());
|
||||
break;
|
||||
case TRACE_SEGMENT_REFERENCE:
|
||||
reader.beginArray();
|
||||
while (reader.hasNext()) {
|
||||
builder.addRefs(referenceJsonReader.read(reader));
|
||||
}
|
||||
reader.endArray();
|
||||
break;
|
||||
case TAGS:
|
||||
reader.beginArray();
|
||||
while (reader.hasNext()) {
|
||||
builder.addTags(keyWithStringValueJsonReader.read(reader));
|
||||
}
|
||||
reader.endArray();
|
||||
break;
|
||||
case LOGS:
|
||||
reader.beginArray();
|
||||
while (reader.hasNext()) {
|
||||
builder.addLogs(logJsonReader.read(reader));
|
||||
}
|
||||
reader.endArray();
|
||||
break;
|
||||
default:
|
||||
reader.skipValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
reader.endObject();
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* 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.receiver.trace.provider.handler.v5.rest.reader;
|
||||
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
public interface StreamJsonReader<T> {
|
||||
T read(JsonReader reader) throws IOException;
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* 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.receiver.trace.provider.handler.v5.rest.reader;
|
||||
|
||||
import org.apache.skywalking.apm.network.language.agent.*;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
public class TraceSegment {
|
||||
|
||||
private UpstreamSegment.Builder builder;
|
||||
|
||||
public TraceSegment() {
|
||||
builder = UpstreamSegment.newBuilder();
|
||||
}
|
||||
|
||||
public void addGlobalTraceId(UniqueId.Builder globalTraceId) {
|
||||
builder.addGlobalTraceIds(globalTraceId);
|
||||
}
|
||||
|
||||
public void setTraceSegmentBuilder(TraceSegmentObject.Builder traceSegmentBuilder) {
|
||||
builder.setSegment(traceSegmentBuilder.build().toByteString());
|
||||
}
|
||||
|
||||
public UpstreamSegment getUpstreamSegment() {
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* 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.receiver.trace.provider.handler.v5.rest.reader;
|
||||
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import java.io.IOException;
|
||||
import org.slf4j.*;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
public class TraceSegmentJsonReader implements StreamJsonReader<TraceSegment> {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(TraceSegmentJsonReader.class);
|
||||
|
||||
private UniqueIdJsonReader uniqueIdJsonReader = new UniqueIdJsonReader();
|
||||
private SegmentJsonReader segmentJsonReader = new SegmentJsonReader();
|
||||
|
||||
private static final String GLOBAL_TRACE_IDS = "gt";
|
||||
private static final String SEGMENT = "sg";
|
||||
|
||||
@Override public TraceSegment read(JsonReader reader) throws IOException {
|
||||
TraceSegment traceSegment = new TraceSegment();
|
||||
|
||||
reader.beginObject();
|
||||
while (reader.hasNext()) {
|
||||
switch (reader.nextName()) {
|
||||
case GLOBAL_TRACE_IDS:
|
||||
reader.beginArray();
|
||||
while (reader.hasNext()) {
|
||||
traceSegment.addGlobalTraceId(uniqueIdJsonReader.read(reader));
|
||||
}
|
||||
reader.endArray();
|
||||
|
||||
break;
|
||||
case SEGMENT:
|
||||
traceSegment.setTraceSegmentBuilder(segmentJsonReader.read(reader));
|
||||
break;
|
||||
default:
|
||||
reader.skipValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
reader.endObject();
|
||||
|
||||
return traceSegment;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* 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.receiver.trace.provider.handler.v5.rest.reader;
|
||||
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import java.io.IOException;
|
||||
import org.apache.skywalking.apm.network.language.agent.UniqueId;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
public class UniqueIdJsonReader implements StreamJsonReader<UniqueId.Builder> {
|
||||
|
||||
@Override public UniqueId.Builder read(JsonReader reader) throws IOException {
|
||||
UniqueId.Builder builder = UniqueId.newBuilder();
|
||||
|
||||
reader.beginArray();
|
||||
while (reader.hasNext()) {
|
||||
builder.addIdParts(reader.nextLong());
|
||||
}
|
||||
reader.endArray();
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue