Skip to content

Commit

Permalink
Remove ASCII method as it can be replaced by more convenient calls.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Sep 28, 2023
1 parent 2d6e4ac commit fa6181b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,8 @@ public void serialize(double value) {
}

@Override
public void writeAscii(String value) {
jw.writeAscii(value);
}

@Override
public void writeString(CharSequence replaceBuilder) {
jw.writeString(replaceBuilder);
public void writeString(CharSequence value) {
jw.writeString(value);
}

@Override
Expand Down
6 changes: 0 additions & 6 deletions apm-agent-plugins/apm-micrometer-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@
</properties>

<dependencies>
<!-- This plugin requires further refactoring to avoid agent dependencies. -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>apm-agent-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package co.elastic.apm.agent.micrometer;

import co.elastic.apm.agent.report.serialize.DslJsonDataWriter;
import co.elastic.apm.agent.sdk.internal.util.PrivilegedActionUtils;
import co.elastic.apm.agent.sdk.logging.Logger;
import co.elastic.apm.agent.sdk.logging.LoggerFactory;
Expand All @@ -26,6 +27,8 @@
import co.elastic.apm.agent.tracer.configuration.MetricsConfiguration;
import co.elastic.apm.agent.tracer.reporting.DataWriter;
import co.elastic.apm.agent.tracer.reporting.ReportingTracer;
import com.dslplatform.json.DslJson;
import com.dslplatform.json.JsonWriter;
import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.DistributionSummary;
import io.micrometer.core.instrument.FunctionCounter;
Expand Down Expand Up @@ -256,9 +259,7 @@ private static void serializeHistogram(Meter.Id id, HistogramSnapshot histogramS
}
writer.write(ARRAY_END);
writer.write(COMMA);
writer.write(QUOTE);
writer.writeAscii("counts");
writer.write(QUOTE);
writer.writeString("counts");
writer.write(SEMI);
writer.write(ARRAY_START);
// Micrometer bucket counts are cumulative: E.g. the count at bucket with upper
Expand All @@ -277,7 +278,8 @@ private static void serializeHistogram(Meter.Id id, HistogramSnapshot histogramS
writer.write(ARRAY_END);

writer.write(COMMA);
writer.writeAscii("\"type\":\"histogram\"");
writer.writeFieldName("type");
writer.writeString("histogram");

writer.write(OBJECT_END);
}
Expand Down Expand Up @@ -335,13 +337,20 @@ private static void serializeObjectStart(String key, String objectName, String s

writer.write(SEMI);
writer.write(OBJECT_START);
writer.write(QUOTE);
writer.writeAscii(objectName);
writer.write(QUOTE);
writer.write(SEMI);
writer.writeFieldName(objectName);
}

private static boolean isValidValue(double value) {
return !Double.isNaN(value) && !Double.isInfinite(value);
}

public static void main(String[] args) {
DslJson<Object> dslJson = new DslJson<>(new DslJson.Settings<>());
JsonWriter jw = dslJson.newWriter(512);
jw.writeAscii("\"foo\"");
//jw.writeString("foo");
String string = jw.toString();
System.out.println(string);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ public void addExplicitBucketHistogram(CharSequence metricName, List<Double> bou
serializeFieldKeyAscii("counts");
convertAndSerializeHistogramBucketCounts(counts);
writer.write(COMMA);
writer.writeAscii("\"type\":\"histogram\"");
writer.writeFieldName("type");
writer.writeString("histogram");
}
writer.write(OBJECT_END);
anySamplesWritten = true;
Expand Down Expand Up @@ -172,10 +173,7 @@ private void serializeFieldKey(CharSequence fieldName) {
}

private void serializeFieldKeyAscii(String fieldName) {
writer.write(QUOTE);
writer.writeAscii(fieldName);
writer.write(QUOTE);
writer.write(SEMI);
writer.writeFieldName(fieldName);
}

private void serializeAttributes(CharSequence instrumentationScopeName, Attributes attributes) {
Expand All @@ -187,7 +185,7 @@ private void serializeAttributes(CharSequence instrumentationScopeName, Attribut
writer.write(OBJECT_START);
boolean anyWritten = false;
if (instrumentationScopeName.length() > 0) {
writer.writeAscii("\"otel_instrumentation_scope_name\":");
writer.writeFieldName("otel_instrumentation_scope_name");
writer.writeString(instrumentationScopeName);
anyWritten = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ public interface DataWriter {

void serialize(double value);

void writeAscii(String value);

void writeString(CharSequence replaceBuilder);
void writeString(CharSequence value);

void writeStringValue(CharSequence value, StringBuilder replaceBuilder);

Expand Down

0 comments on commit fa6181b

Please sign in to comment.