未验证 提交 494d2a5b 编写于 作者: 于玉桔 提交者: GitHub

Elastic job plugin use wrong span type (#5347)

上级 7ceb3bc8
......@@ -87,6 +87,8 @@ public final class Tags {
public static final StringTag LOGIC_ENDPOINT = new StringTag(12, "x-le");
public static final String VAL_LOCAL_SPAN_AS_LOGIC_ENDPOINT = "{\"logic-span\":true}";
/**
* Creates a {@code StringTag} with the given key and cache it, if it's created before, simply return it without
* creating a new one.
......
......@@ -19,8 +19,8 @@
package org.apache.skywalking.apm.plugin.elasticjob;
import org.apache.shardingsphere.elasticjob.api.listener.ShardingContexts;
import org.apache.skywalking.apm.agent.core.context.ContextCarrier;
import org.apache.skywalking.apm.agent.core.context.ContextManager;
import org.apache.skywalking.apm.agent.core.context.tag.Tags;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
......@@ -36,8 +36,9 @@ public class ElasticJobExecutorInterceptor implements InstanceMethodsAroundInter
ShardingContexts shardingContexts = (ShardingContexts) allArguments[0];
Integer item = (Integer) allArguments[1];
String operateName = ComponentsDefine.ELASTIC_JOB.getName() + "/" + shardingContexts.getJobName();
AbstractSpan span = ContextManager.createEntrySpan(operateName, new ContextCarrier());
AbstractSpan span = ContextManager.createLocalSpan(operateName);
span.setComponent(ComponentsDefine.ELASTIC_JOB);
Tags.LOGIC_ENDPOINT.set(span, Tags.VAL_LOCAL_SPAN_AS_LOGIC_ENDPOINT);
span.tag("item", item == null ? "" : String.valueOf(item));
span.tag("shardingTotalCount", Integer.toString(shardingContexts.getShardingTotalCount()));
span.tag("taskId", shardingContexts.getTaskId());
......
......@@ -39,7 +39,7 @@ public class GraphqlInterceptor implements InstanceMethodsAroundInterceptor {
return;
}
AbstractSpan span = ContextManager.createLocalSpan(parameters.getField().getSingleField().getName());
Tags.LOGIC_ENDPOINT.set(span, buildLogicEndpointSpan());
Tags.LOGIC_ENDPOINT.set(span, Tags.VAL_LOCAL_SPAN_AS_LOGIC_ENDPOINT);
span.setComponent(ComponentsDefine.GRAPHQL);
}
......@@ -67,8 +67,4 @@ public class GraphqlInterceptor implements InstanceMethodsAroundInterceptor {
span.errorOccurred();
span.log(throwable);
}
private String buildLogicEndpointSpan() {
return "{\"logic-span\":true}";
}
}
......@@ -48,7 +48,7 @@ public class GraphqlInterceptor implements InstanceMethodsAroundInterceptor {
return;
}
AbstractSpan span = ContextManager.createLocalSpan(parameters.getField().get(0).getName());
Tags.LOGIC_ENDPOINT.set(span, buildLogicEndpointSpan());
Tags.LOGIC_ENDPOINT.set(span, Tags.VAL_LOCAL_SPAN_AS_LOGIC_ENDPOINT);
span.setComponent(ComponentsDefine.GRAPHQL);
} catch (NoSuchFieldException | IllegalAccessException e) {
}
......@@ -98,8 +98,4 @@ public class GraphqlInterceptor implements InstanceMethodsAroundInterceptor {
span.errorOccurred();
span.log(throwable);
}
private String buildLogicEndpointSpan() {
return "{\"logic-span\":true}";
}
}
......@@ -39,7 +39,7 @@ public class GraphqlInterceptor implements InstanceMethodsAroundInterceptor {
return;
}
AbstractSpan span = ContextManager.createLocalSpan(parameters.getField().get(0).getName());
Tags.LOGIC_ENDPOINT.set(span, buildLogicEndpointSpan());
Tags.LOGIC_ENDPOINT.set(span, Tags.VAL_LOCAL_SPAN_AS_LOGIC_ENDPOINT);
span.setComponent(ComponentsDefine.GRAPHQL);
}
......@@ -67,8 +67,4 @@ public class GraphqlInterceptor implements InstanceMethodsAroundInterceptor {
span.errorOccurred();
span.log(throwable);
}
private String buildLogicEndpointSpan() {
return "{\"logic-span\":true}";
}
}
......@@ -43,10 +43,11 @@ segmentItems:
endTime: not null
componentId: 24
isError: false
spanType: Entry
spanType: Local
peer: ''
skipAnalysis: false
tags:
- {key: x-le, value: '{"logic-span":true}'}
- {key: item, value: '0'}
- {key: shardingTotalCount, value: '1'}
- {key: taskId, value: not null}
......
......@@ -18,8 +18,8 @@
package org.apache.skywalking.apm.testcase.elasticjob.controller;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.skywalking.apm.testcase.elasticjob.job.DemoSimpleJob;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
......@@ -28,13 +28,15 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/case")
public class CaseController {
private static final Logger logger = LogManager.getLogger(CaseController.class);
@Autowired
private DemoSimpleJob demoSimpleJob;
private static final String SUCCESS = "Success";
@RequestMapping("/healthCheck")
@ResponseBody
public String healthCheck() throws Exception {
demoSimpleJob.getLatchAwait();
return SUCCESS;
}
......
......@@ -30,19 +30,31 @@ import org.springframework.stereotype.Component;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.CountDownLatch;
@Component
public class DemoSimpleJob implements SimpleJob {
private final Logger logger = LoggerFactory.getLogger(DemoSimpleJob.class);
OkHttpClient client = new OkHttpClient.Builder().build();
private CountDownLatch latch = new CountDownLatch(1);
public void getLatchAwait() throws InterruptedException {
try {
latch.await();
} catch (InterruptedException e) {
throw e;
}
}
@Override
public void execute(ShardingContext shardingContext) {
logger.info("Elastic Job Item: {} | Time: {} | Thread: {} | {}",
shardingContext.getShardingItem(), new SimpleDateFormat("HH:mm:ss").format(new Date()), Thread.currentThread().getId(), "SIMPLE");
Request request = new Request.Builder().url("http://localhost:8080/elasticjob-3.x-scenario/case/ping").build();
Response response = null;
latch.countDown();
try {
response = client.newCall(request).execute();
} catch (IOException e) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册