Skip to content
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

rename the DebuggerProbe to TriggerProbe #7737

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.datadog.debugger.agent;

import com.datadog.debugger.probe.DebuggerProbe;
import com.datadog.debugger.probe.ExceptionProbe;
import com.datadog.debugger.probe.LogProbe;
import com.datadog.debugger.probe.MetricProbe;
import com.datadog.debugger.probe.ProbeDefinition;
import com.datadog.debugger.probe.SpanDecorationProbe;
import com.datadog.debugger.probe.SpanProbe;
import com.datadog.debugger.probe.TriggerProbe;
import com.squareup.moshi.Json;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -66,7 +66,7 @@ public int hashCode() {
private final Collection<MetricProbe> metricProbes;
private final Collection<LogProbe> logProbes;
private final Collection<SpanProbe> spanProbes;
private final Collection<DebuggerProbe> debuggerProbes;
private final Collection<TriggerProbe> triggerProbes;
private final Collection<SpanDecorationProbe> spanDecorationProbes;
private final FilterList allowList;
private final FilterList denyList;
Expand All @@ -89,7 +89,7 @@ public Configuration(
Collection<MetricProbe> metricProbes,
Collection<LogProbe> logProbes,
Collection<SpanProbe> spanProbes,
Collection<DebuggerProbe> debuggerProbes,
Collection<TriggerProbe> triggerProbes,
Collection<SpanDecorationProbe> spanDecorationProbes,
FilterList allowList,
FilterList denyList,
Expand All @@ -98,7 +98,7 @@ public Configuration(
this.metricProbes = metricProbes;
this.logProbes = logProbes;
this.spanProbes = spanProbes;
this.debuggerProbes = debuggerProbes;
this.triggerProbes = triggerProbes;
this.spanDecorationProbes = spanDecorationProbes;
this.allowList = allowList;
this.denyList = denyList;
Expand All @@ -121,8 +121,8 @@ public Collection<SpanProbe> getSpanProbes() {
return spanProbes;
}

public Collection<DebuggerProbe> getDebuggerProbes() {
return debuggerProbes;
public Collection<TriggerProbe> getTriggerProbes() {
return triggerProbes;
}

public Collection<SpanDecorationProbe> getSpanDecorationProbes() {
Expand All @@ -143,8 +143,8 @@ public LogProbe.Sampling getSampling() {

public Collection<ProbeDefinition> getDefinitions() {
Collection<ProbeDefinition> result = new ArrayList<>();
if (debuggerProbes != null) {
result.addAll(debuggerProbes);
if (triggerProbes != null) {
result.addAll(triggerProbes);
}
if (metricProbes != null) {
result.addAll(metricProbes);
Expand Down Expand Up @@ -209,7 +209,7 @@ public static class Builder {
private List<MetricProbe> metricProbes = null;
private List<LogProbe> logProbes = null;
private List<SpanProbe> spanProbes = null;
private List<DebuggerProbe> debuggerProbes = null;
private List<TriggerProbe> triggerProbes = null;
private List<SpanDecorationProbe> spanDecorationProbes = null;
private FilterList allowList = null;
private FilterList denyList = null;
Expand All @@ -226,7 +226,7 @@ public Configuration.Builder add(Collection<? extends ProbeDefinition> definitio
}
for (ProbeDefinition definition : definitions) {
if (definition instanceof MetricProbe) add((MetricProbe) definition);
if (definition instanceof DebuggerProbe) add((DebuggerProbe) definition);
if (definition instanceof TriggerProbe) add((TriggerProbe) definition);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Quality Violation

Suggested change
if (definition instanceof TriggerProbe) add((TriggerProbe) definition);
if (definition instanceof TriggerProbe) {add((TriggerProbe) definition)};
single if statement should be wrapped in a brace (...read more)

Omitting braces {} is valid in multiple statements, such as, for loops, if statements, and while loops. However, enforcing the use of control braces throughout your codebase will make the code more consistent and can make it easier to add statements in the future.

View in Datadog  Leave us feedback  Documentation

if (definition instanceof LogProbe) add((LogProbe) definition);
if (definition instanceof SpanProbe) add((SpanProbe) definition);
if (definition instanceof SpanDecorationProbe) add((SpanDecorationProbe) definition);
Expand Down Expand Up @@ -258,11 +258,11 @@ public Configuration.Builder add(SpanProbe probe) {
return this;
}

public Configuration.Builder add(DebuggerProbe probe) {
if (debuggerProbes == null) {
debuggerProbes = new ArrayList<>();
public Configuration.Builder add(TriggerProbe probe) {
if (triggerProbes == null) {
triggerProbes = new ArrayList<>();
}
debuggerProbes.add(probe);
triggerProbes.add(probe);
return this;
}

Expand Down Expand Up @@ -321,11 +321,11 @@ public Configuration.Builder addSpanProbes(Collection<SpanProbe> probes) {
return this;
}

public Configuration.Builder addDebuggerProbes(Collection<DebuggerProbe> probes) {
public Configuration.Builder addTriggerProbes(Collection<TriggerProbe> probes) {
if (probes == null) {
return this;
}
for (DebuggerProbe probe : probes) {
for (TriggerProbe probe : probes) {
add(probe);
}
return this;
Expand Down Expand Up @@ -377,7 +377,7 @@ public Configuration.Builder add(Configuration other) {
addMetricProbes(other.getMetricProbes());
addLogProbes(other.getLogProbes());
addSpanProbes(other.getSpanProbes());
addDebuggerProbes(other.getDebuggerProbes());
addTriggerProbes(other.getTriggerProbes());
addSpanDecorationProbes(other.getSpanDecorationProbes());
addAllowList(other.getAllowList());
addDenyList(other.getDenyList());
Expand All @@ -391,7 +391,7 @@ public Configuration build() {
metricProbes,
logProbes,
spanProbes,
debuggerProbes,
triggerProbes,
spanDecorationProbes,
allowList,
denyList,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import static com.datadog.debugger.agent.ConfigurationAcceptor.Source.REMOTE_CONFIG;

import com.datadog.debugger.probe.DebuggerProbe;
import com.datadog.debugger.probe.LogProbe;
import com.datadog.debugger.probe.MetricProbe;
import com.datadog.debugger.probe.ProbeDefinition;
import com.datadog.debugger.probe.SpanDecorationProbe;
import com.datadog.debugger.probe.SpanProbe;
import com.datadog.debugger.probe.TriggerProbe;
import com.datadog.debugger.util.MoshiHelper;
import com.squareup.moshi.JsonAdapter;
import datadog.remoteconfig.PollingRateHinter;
Expand All @@ -29,15 +29,15 @@
import org.slf4j.LoggerFactory;

public class DebuggerProductChangesListener implements ProductListener {
public static final int MAX_ALLOWED_DEBUGGER_PROBES = 100;
public static final int MAX_ALLOWED_TRIGGER_PROBES = 100;
public static final int MAX_ALLOWED_METRIC_PROBES = 100;
public static final int MAX_ALLOWED_LOG_PROBES = 100;
public static final int MAX_ALLOWED_SPAN_PROBES = 100;
public static final int MAX_ALLOWED_SPAN_DECORATION_PROBES = 100;
public static final String LOG_PROBE_PREFIX = "logProbe_";
public static final String METRIC_PROBE_PREFIX = "metricProbe_";
public static final String SPAN_PROBE_PREFIX = "spanProbe_";
public static final String DEBUGGER_PROBE_PREFIX = "debuggerProbe_";
public static final String TRIGGER_PROBE_PREFIX = "triggerProbe_";
public static final String SPAN_DECORATION_PROBE_PREFIX = "spanDecorationProbe_";
private static final Logger LOGGER =
LoggerFactory.getLogger(DebuggerProductChangesListener.class);
Expand All @@ -55,8 +55,8 @@ static class Adapter {
static final JsonAdapter<SpanProbe> SPAN_PROBE_JSON_ADAPTER =
MoshiHelper.createMoshiConfig().adapter(SpanProbe.class);

static final JsonAdapter<DebuggerProbe> DEBUGGER_PROBE_JSON_ADAPTER =
MoshiHelper.createMoshiConfig().adapter(DebuggerProbe.class);
static final JsonAdapter<TriggerProbe> TRIGGER_PROBE_JSON_ADAPTER =
MoshiHelper.createMoshiConfig().adapter(TriggerProbe.class);

static final JsonAdapter<SpanDecorationProbe> SPAN_DECORATION_PROBE_JSON_ADAPTER =
MoshiHelper.createMoshiConfig().adapter(SpanDecorationProbe.class);
Expand All @@ -77,8 +77,8 @@ static SpanProbe deserializeSpanProbe(byte[] content) throws IOException {
return deserialize(SPAN_PROBE_JSON_ADAPTER, content);
}

static DebuggerProbe deserializeDebuggerProbe(byte[] content) throws IOException {
return deserialize(DEBUGGER_PROBE_JSON_ADAPTER, content);
static TriggerProbe deserializeTriggerProbe(byte[] content) throws IOException {
return deserialize(TRIGGER_PROBE_JSON_ADAPTER, content);
}

static SpanDecorationProbe deserializeSpanDecorationProbe(byte[] content) throws IOException {
Expand Down Expand Up @@ -118,9 +118,9 @@ public void accept(ConfigKey configKey, byte[] content, PollingRateHinter pollin
} else if (configId.startsWith(SPAN_PROBE_PREFIX)) {
SpanProbe spanProbe = Adapter.deserializeSpanProbe(content);
configChunks.put(configId, definitions -> definitions.add(spanProbe));
} else if (configId.startsWith(DEBUGGER_PROBE_PREFIX)) {
DebuggerProbe debuggerProbe = Adapter.deserializeDebuggerProbe(content);
configChunks.put(configId, definitions -> definitions.add(debuggerProbe));
} else if (configId.startsWith(TRIGGER_PROBE_PREFIX)) {
TriggerProbe triggerProbe = Adapter.deserializeTriggerProbe(content);
configChunks.put(configId, definitions -> definitions.add(triggerProbe));
} else if (configId.startsWith(SPAN_DECORATION_PROBE_PREFIX)) {
SpanDecorationProbe spanDecorationProbe = Adapter.deserializeSpanDecorationProbe(content);
configChunks.put(configId, definitions -> definitions.add(spanDecorationProbe));
Expand Down Expand Up @@ -161,7 +161,7 @@ public void commit(PollingRateHinter pollingRateHinter) {

static class DefinitionBuilder {
private final Collection<ProbeDefinition> definitions = new ArrayList<>();
private int debuggerProbeCount = 0;
private int triggerProbeCount = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 Code Quality Violation

Suggested change
private int triggerProbeCount = 0;
private int triggerProbeCount;
Remove initialization, this is already the default value. (...read more)

When initializing fields, prevent initializing fields to the default value. Any additional initialization means more bytecode instructions, and allocating many of these objects may impact your application performance.

If you initialize to a default value, remove the initialization.

View in Datadog  Leave us feedback  Documentation

private int metricProbeCount = 0;
private int logProbeCount = 0;
private int spanProbeCount = 0;
Expand Down Expand Up @@ -194,13 +194,13 @@ void add(SpanProbe probe) {
spanProbeCount++;
}

void add(DebuggerProbe probe) {
if (debuggerProbeCount >= MAX_ALLOWED_DEBUGGER_PROBES) {
LOGGER.debug("Max allowed debugger probes reached, ignoring new probe: {}", probe);
void add(TriggerProbe probe) {
if (triggerProbeCount >= MAX_ALLOWED_TRIGGER_PROBES) {
LOGGER.debug("Max allowed trigger probes reached, ignoring new probe: {}", probe);
return;
}
definitions.add(probe);
debuggerProbeCount++;
triggerProbeCount++;
}

void add(SpanDecorationProbe probe) {
Expand All @@ -220,8 +220,8 @@ void addAll(Collection<ProbeDefinition> newDefinitions) {
add((LogProbe) definition);
} else if (definition instanceof SpanProbe) {
add((SpanProbe) definition);
} else if (definition instanceof DebuggerProbe) {
add((DebuggerProbe) definition);
} else if (definition instanceof TriggerProbe) {
add((TriggerProbe) definition);
} else if (definition instanceof SpanDecorationProbe) {
add((SpanDecorationProbe) definition);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
import com.datadog.debugger.instrumentation.DiagnosticMessage;
import com.datadog.debugger.instrumentation.InstrumentationResult;
import com.datadog.debugger.instrumentation.MethodInfo;
import com.datadog.debugger.probe.DebuggerProbe;
import com.datadog.debugger.probe.ExceptionProbe;
import com.datadog.debugger.probe.ForceMethodInstrumentation;
import com.datadog.debugger.probe.LogProbe;
import com.datadog.debugger.probe.MetricProbe;
import com.datadog.debugger.probe.ProbeDefinition;
import com.datadog.debugger.probe.SpanDecorationProbe;
import com.datadog.debugger.probe.SpanProbe;
import com.datadog.debugger.probe.TriggerProbe;
import com.datadog.debugger.probe.Where;
import com.datadog.debugger.sink.DebuggerSink;
import com.datadog.debugger.sink.ProbeStatusSink;
Expand Down Expand Up @@ -79,7 +79,7 @@ public class DebuggerTransformer implements ClassFileTransformer {
private static final Pattern COMMA_PATTERN = Pattern.compile(",");
private static final List<Class<?>> PROBE_ORDER =
Arrays.asList(
DebuggerProbe.class,
TriggerProbe.class,
MetricProbe.class,
LogProbe.class,
SpanDecorationProbe.class,
Expand Down Expand Up @@ -571,7 +571,7 @@ private List<ToInstrumentInfo> filterAndSortDefinitions(
// note: exception probes are log probes and are handled the same way
if (definition instanceof LogProbe
|| definition instanceof SpanDecorationProbe
|| definition instanceof DebuggerProbe) {
|| definition instanceof TriggerProbe) {
if (definition instanceof ExceptionProbe) {
if (addedExceptionProbe) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DebuggerProbe extends ProbeDefinition {
private static final Logger LOGGER = LoggerFactory.getLogger(DebuggerProbe.class);
public class TriggerProbe extends ProbeDefinition {
private static final Logger LOGGER = LoggerFactory.getLogger(TriggerProbe.class);

// no-arg constructor is required by Moshi to avoid creating instance with unsafe and by-passing
// constructors, including field initializers.
public DebuggerProbe() {
public TriggerProbe() {
this(LANGUAGE, null, null);
}

public DebuggerProbe(String language, ProbeId probeId, Where where) {
public TriggerProbe(String language, ProbeId probeId, Where where) {
super(language, probeId, (Tag[]) null, where, MethodLocation.ENTRY);
}

Expand Down Expand Up @@ -63,7 +63,7 @@ public CapturedContext.Status createStatus() {
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
DebuggerProbe that = (DebuggerProbe) o;
TriggerProbe that = (TriggerProbe) o;
return Objects.equals(language, that.language)
&& Objects.equals(id, that.id)
&& version == that.version
Expand Down Expand Up @@ -106,8 +106,8 @@ public static Builder builder() {
}

public static class Builder extends ProbeDefinition.Builder<Builder> {
public DebuggerProbe build() {
return new DebuggerProbe(language, probeId, where);
public TriggerProbe build() {
return new TriggerProbe(language, probeId, where);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
import com.datadog.debugger.el.ProbeCondition;
import com.datadog.debugger.el.values.StringValue;
import com.datadog.debugger.instrumentation.InstrumentationResult;
import com.datadog.debugger.probe.DebuggerProbe;
import com.datadog.debugger.probe.LogProbe;
import com.datadog.debugger.probe.MetricProbe;
import com.datadog.debugger.probe.ProbeDefinition;
import com.datadog.debugger.probe.SpanDecorationProbe;
import com.datadog.debugger.probe.SpanProbe;
import com.datadog.debugger.probe.TriggerProbe;
import com.datadog.debugger.probe.Where;
import com.datadog.debugger.sink.DebuggerSink;
import com.datadog.debugger.sink.ProbeStatusSink;
Expand Down Expand Up @@ -2385,7 +2385,7 @@ public void allProbesSameMethod() throws IOException, URISyntaxException {
.where(where)
.build())
.add(LogProbe.builder().probeId(PROBE_ID3).where(where).build())
.add(DebuggerProbe.builder().probeId(PROBE_ID4).where(where).build())
.add(TriggerProbe.builder().probeId(PROBE_ID4).where(where).build())
.build();

CoreTracer tracer = CoreTracer.builder().build();
Expand Down Expand Up @@ -2532,7 +2532,7 @@ private TestSnapshotListener installProbes(
encodedId,
logProbes,
configuration.getSpanDecorationProbes(),
configuration.getDebuggerProbes()));
configuration.getTriggerProbes()));
DebuggerContext.initClassFilter(new DenyListHelper(null));
DebuggerContext.initValueSerializer(new JsonSnapshotSerializer());
if (logProbes != null) {
Expand All @@ -2555,7 +2555,7 @@ private ProbeImplementation resolver(
String encodedId,
Collection<LogProbe> logProbes,
Collection<SpanDecorationProbe> spanDecorationProbes,
Collection<DebuggerProbe> debuggerProbes) {
Collection<TriggerProbe> triggerProbes) {
for (LogProbe probe : logProbes) {
if (probe.getProbeId().getEncodedId().equals(encodedId)) {
return probe;
Expand All @@ -2566,7 +2566,7 @@ private ProbeImplementation resolver(
return probe;
}
}
for (DebuggerProbe probe : debuggerProbes) {
for (TriggerProbe probe : triggerProbes) {
if (probe.getProbeId().getEncodedId().equals(encodedId)) {
return probe;
}
Expand Down
Loading