Skip to content

Commit

Permalink
Merge pull request #4313 from DataDog/jpbempel/evaluate-at
Browse files Browse the repository at this point in the history
Introduced evaluateAt attribute in probe configs
  • Loading branch information
jpbempel authored Nov 25, 2022
2 parents 83548e9 + 983381c commit 5118bde
Show file tree
Hide file tree
Showing 14 changed files with 183 additions and 291 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public String toString() {
// no-arg constructor is required by Moshi to avoid creating instance with unsafe and by-passing
// constructors, including field initializers.
public LogProbe() {
this(LANGUAGE, null, true, null, null, null, new ArrayList<>());
this(LANGUAGE, null, true, null, null, MethodLocation.NONE, null, new ArrayList<>());
}

public LogProbe(
Expand All @@ -94,9 +94,10 @@ public LogProbe(
boolean active,
String[] tagStrs,
Where where,
MethodLocation evaluateAt,
String template,
List<Segment> segments) {
super(language, id, active, tagStrs, where);
super(language, id, active, tagStrs, where, evaluateAt);
this.template = template;
this.segments = segments;
}
Expand Down Expand Up @@ -130,14 +131,15 @@ public boolean equals(Object o) {
&& Arrays.equals(tags, that.tags)
&& Objects.equals(tagMap, that.tagMap)
&& Objects.equals(where, that.where)
&& Objects.equals(evaluateAt, that.evaluateAt)
&& Objects.equals(template, that.template)
&& Objects.equals(segments, that.segments);
}

@Generated
@Override
public int hashCode() {
int result = Objects.hash(language, id, active, tagMap, where, template, segments);
int result = Objects.hash(language, id, active, tagMap, where, evaluateAt, template, segments);
result = 31 * result + Arrays.hashCode(tags);
return result;
}
Expand All @@ -160,6 +162,8 @@ public String toString() {
+ tagMap
+ ", where="
+ where
+ ", evaluateAt="
+ evaluateAt
+ ", template='"
+ template
+ '\''
Expand All @@ -169,93 +173,24 @@ public String toString() {
}

public static LogProbe.Builder builder() {
return new LogProbe.Builder();
return new Builder();
}

public static class Builder {
private String language = LANGUAGE;
private String logId;
private boolean active = true;
private String[] tagStrs;
private Where where;
public static class Builder extends ProbeDefinition.Builder<Builder> {
private String template;
private List<Segment> segments;

public LogProbe.Builder language(String language) {
this.language = language;
return this;
}

public LogProbe.Builder logId(String logId) {
this.logId = logId;
return this;
}

public LogProbe.Builder active(boolean active) {
this.active = active;
return this;
}

public LogProbe.Builder tags(String... tagStrs) {
this.tagStrs = tagStrs;
return this;
}

public LogProbe.Builder where(Where where) {
this.where = where;
return this;
}

public LogProbe.Builder where(String typeName, String methodName) {
return where(new Where(typeName, methodName, null, (Where.SourceLine[]) null, null));
}

public LogProbe.Builder where(String typeName, String methodName, String signature) {
return where(new Where(typeName, methodName, signature, (Where.SourceLine[]) null, null));
}

public LogProbe.Builder where(
String typeName, String methodName, String signature, String... lines) {
return where(new Where(typeName, methodName, signature, Where.sourceLines(lines), null));
}

public LogProbe.Builder where(String sourceFile, String... lines) {
return where(new Where(null, null, null, lines, sourceFile));
}

public LogProbe.Builder where(
String typeName, String methodName, String signature, int codeLine, String source) {
return where(
new Where(
typeName,
methodName,
signature,
new Where.SourceLine[] {new Where.SourceLine(codeLine)},
source));
}

public LogProbe.Builder where(
String typeName,
String methodName,
String signature,
int codeLineFrom,
int codeLineTill,
String source) {
return where(
new Where(
typeName,
methodName,
signature,
new Where.SourceLine[] {new Where.SourceLine(codeLineFrom, codeLineTill)},
source));
}

public LogProbe.Builder template(String template) {
this.template = template;
this.segments = parseTemplate(template);
return this;
}

public LogProbe build() {
return new LogProbe(
language, probeId, active, tagStrs, where, evaluateAt, template, segments);
}

private static List<Segment> parseTemplate(String template) {
if (template == null) {
return Collections.emptyList();
Expand Down Expand Up @@ -296,9 +231,5 @@ private static void addStrSegment(List<Segment> segments, String str) {
str = Strings.replace(str, "}}", "}");
segments.add(new Segment(str));
}

public LogProbe build() {
return new LogProbe(language, logId, active, tagStrs, where, template, segments);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public enum MetricKind {
// no-arg constructor is required by Moshi to avoid creating instance with unsafe and by-passing
// constructors, including field initializers.
public MetricProbe() {
this(LANGUAGE, null, true, null, null, MetricKind.COUNT, null, null);
this(LANGUAGE, null, true, null, null, MethodLocation.NONE, MetricKind.COUNT, null, null);
}

public MetricProbe(
Expand All @@ -35,10 +35,11 @@ public MetricProbe(
boolean active,
String[] tagStrs,
Where where,
MethodLocation evaluateAt,
MetricKind kind,
String metricName,
ValueScript value) {
super(language, probeId, active, tagStrs, where);
super(language, probeId, active, tagStrs, where, evaluateAt);
this.kind = kind;
this.metricName = metricName;
this.value = value;
Expand Down Expand Up @@ -69,84 +70,11 @@ public static Builder builder() {
return new Builder();
}

public static class Builder {
private String language = LANGUAGE;
private String metricId;
private boolean active = true;
private String[] tagStrs;
private Where where;
public static class Builder extends ProbeDefinition.Builder<Builder> {
private MetricKind kind;
private String metricName;
private ValueScript valueScript;

public Builder language(String language) {
this.language = language;
return this;
}

public Builder metricId(String metricId) {
this.metricId = metricId;
return this;
}

public Builder active(boolean active) {
this.active = active;
return this;
}

public Builder tags(String... tagStrs) {
this.tagStrs = tagStrs;
return this;
}

public Builder where(Where where) {
this.where = where;
return this;
}

public Builder where(String typeName, String methodName) {
return where(new Where(typeName, methodName, null, (Where.SourceLine[]) null, null));
}

public Builder where(String typeName, String methodName, String signature) {
return where(new Where(typeName, methodName, signature, (Where.SourceLine[]) null, null));
}

public Builder where(String typeName, String methodName, String signature, String... lines) {
return where(new Where(typeName, methodName, signature, Where.sourceLines(lines), null));
}

public Builder where(String sourceFile, String... lines) {
return where(new Where(null, null, null, lines, sourceFile));
}

public Builder where(
String typeName, String methodName, String signature, int codeLine, String source) {
return where(
new Where(
typeName,
methodName,
signature,
new Where.SourceLine[] {new Where.SourceLine(codeLine)},
source));
}

public Builder where(
String typeName,
String methodName,
String signature,
int codeLineFrom,
int codeLineTill,
String source) {
return where(
new Where(
typeName,
methodName,
signature,
new Where.SourceLine[] {new Where.SourceLine(codeLineFrom, codeLineTill)},
source));
}

public Builder kind(MetricKind kind) {
this.kind = kind;
return this;
Expand All @@ -164,7 +92,7 @@ public Builder valueScript(ValueScript valueScript) {

public MetricProbe build() {
return new MetricProbe(
language, metricId, active, tagStrs, where, kind, metricName, valueScript);
language, probeId, active, tagStrs, where, evaluateAt, kind, metricName, valueScript);
}
}

Expand All @@ -180,6 +108,7 @@ public boolean equals(Object o) {
&& Arrays.equals(tags, that.tags)
&& Objects.equals(tagMap, that.tagMap)
&& Objects.equals(where, that.where)
&& Objects.equals(evaluateAt, that.evaluateAt)
&& kind == that.kind
&& Objects.equals(metricName, that.metricName)
&& Objects.equals(value, that.value);
Expand All @@ -188,7 +117,8 @@ public boolean equals(Object o) {
@Generated
@Override
public int hashCode() {
int result = Objects.hash(language, id, active, tagMap, where, kind, metricName, value);
int result =
Objects.hash(language, id, active, tagMap, where, evaluateAt, kind, metricName, value);
result = 31 * result + Arrays.hashCode(tags);
return result;
}
Expand All @@ -211,6 +141,8 @@ public String toString() {
+ tagMap
+ ", where="
+ where
+ ", evaluateAt="
+ evaluateAt
+ ", kind="
+ kind
+ ", metricName='"
Expand Down
Loading

0 comments on commit 5118bde

Please sign in to comment.