-
Notifications
You must be signed in to change notification settings - Fork 1k
Add support for PowerJob #12086
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for PowerJob #12086
Conversation
.../io/opentelemetry/javaagent/instrumentation/powerjob/v4_0/BasicProcessorInstrumentation.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Steve Rao <[email protected]>
Co-authored-by: Helen <[email protected]>
...in/java/io/opentelemetry/javaagent/instrumentation/powerjob/v4_0/PowerJobProcessRequest.java
Outdated
Show resolved
Hide resolved
|
@laurit Please take a look. |
| @Override | ||
| public void transform(TypeTransformer transformer) { | ||
| transformer.applyAdviceToMethod( | ||
| named("process").and(isPublic()).and(takesArguments(1)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
usually we verify here that the argument type is what is expected in the advice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
...elemetry/javaagent/instrumentation/powerjob/v4_0/PowerJobExperimentalAttributeExtractor.java
Outdated
Show resolved
Hide resolved
.../io/opentelemetry/javaagent/instrumentation/powerjob/v4_0/PowerJobInstrumentationModule.java
Outdated
Show resolved
Hide resolved
| import io.opentelemetry.instrumentation.api.incubator.semconv.code.CodeSpanNameExtractor; | ||
| import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; | ||
|
|
||
| class PowerJobSpanNameExtractor implements SpanNameExtractor<PowerJobProcessRequest> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might as well delete this and just use CodeSpanNameExtractor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; | ||
| import io.opentelemetry.javaagent.bootstrap.internal.AgentInstrumentationConfig; | ||
|
|
||
| public final class PowerJobInstrumenterFactory { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd merge the code from this class into PowerJobSingletons
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
.../io/opentelemetry/javaagent/instrumentation/powerjob/v4_0/BasicProcessorInstrumentation.java
Outdated
Show resolved
Hide resolved
...in/java/io/opentelemetry/javaagent/instrumentation/powerjob/v4_0/PowerJobProcessRequest.java
Outdated
Show resolved
Hide resolved
| span.hasName(String.format("%s.process", TestBasicProcessor.class.getSimpleName())); | ||
| span.hasKind(SpanKind.INTERNAL); | ||
| span.hasStatus(StatusData.unset()); | ||
| span.hasAttributesSatisfying( | ||
| attributeAssertions( | ||
| TestBasicProcessor.class.getName(), jobId, jobParam, BASIC_PROCESSOR)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertions can be chained span.hasName().hasKind()...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| span.hasName(String.format("%s.process", TestBasicProcessor.class.getSimpleName())); | ||
| span.hasKind(SpanKind.INTERNAL); | ||
| span.hasStatus(StatusData.unset()); | ||
| span.hasAttributesSatisfying( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
usually we use hasAttributesSatisfyingExactly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
...st/java/io/opentelemetry/javaagent/instrumentation/powerjob/v4_0/TestBroadcastProcessor.java
Show resolved
Hide resolved
| public static final String BROADCAST_PROCESSOR = "BroadcastProcessor"; | ||
| public static final String MAP_PROCESSOR = "MapProcessor"; | ||
| public static final String MAP_REDUCE_PROCESSOR = "MapReduceProcessor"; | ||
|
|
||
| // Official processors | ||
| public static final String SHELL_PROCESSOR = "ShellProcessor"; | ||
| public static final String PYTHON_PROCESSOR = "PythonProcessor"; | ||
| public static final String HTTP_PROCESSOR = "HttpProcessor"; | ||
| public static final String FILE_CLEANUP_PROCESSOR = "FileCleanupProcessor"; | ||
| public static final String SPRING_DATASOURCE_SQL_PROCESSOR = "SpringDatasourceSqlProcessor"; | ||
| public static final String DYNAMIC_DATASOURCE_SQL_PROCESSOR = "DynamicDatasourceSqlProcessor"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are only used in the tests, you could move them there or inline them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
|
|
||
| private PowerJobConstants() {} | ||
|
|
||
| public static final String BASIC_PROCESSOR = "BasicProcessor"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps move it to the class that uses it, imo no need to have a separate class for 1 constant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| if (failedStatusPredicate.test(result)) { | ||
| request.setFailed(); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually we'd just pass the result as response to the instrumenter then in the span status extractor you could just use result.isSuccess() without the need to pass failedStatusPredicate around.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| import java.util.function.Predicate; | ||
| import tech.powerjob.worker.core.processor.ProcessResult; | ||
|
|
||
| public final class PowerJobHelper { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd just inline the startSpan and endSpan methods. The instrumentations that use a similar helper class are usually more complicated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your suggestion, I will streamline the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
...in/java/io/opentelemetry/javaagent/instrumentation/powerjob/v4_0/PowerJobProcessRequest.java
Outdated
Show resolved
Hide resolved
...in/java/io/opentelemetry/javaagent/instrumentation/powerjob/v4_0/PowerJobProcessRequest.java
Outdated
Show resolved
Hide resolved
| private String methodName; | ||
| private final Long jobId; | ||
| private String jobType; | ||
| private Class<?> declaringClass; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you could make all of these final
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| .addAttributesExtractor(CodeAttributesExtractor.create(codeAttributesGetter)) | ||
| .setSpanStatusExtractor( | ||
| (spanStatusBuilder, powerJobProcessRequest, response, error) -> { | ||
| if (error != null || response == null || !response.isSuccess()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think your original code did not set the status to error when response == null, could you verify whether this is the intended behavior. Perhaps you meant response != null && !response.isSuccess().
Most of the status extractors follow a pattern where they delegate to the default status extractor. Currently it doesn't change anything because the default extractor also just checks error != null, but still I think it would be nice to follow the same pattern
if (response != null && !response.isSuccess()) {
spanStatusBuilder.setStatus(StatusCode.ERROR);
} else {
SpanStatusExtractor.getDefault().extract(spanStatusBuilder, powerJobProcessRequest, response, error);
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you for your suggestion
Resolves #11921