Skip to content

Commit

Permalink
Move metrics and log reporting to ReportingTracer, and remove obsolet…
Browse files Browse the repository at this point in the history
…e dependencies on core module.
  • Loading branch information
raphw committed Sep 28, 2023
1 parent bd6bf29 commit b37db58
Show file tree
Hide file tree
Showing 56 changed files with 176 additions and 146 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,7 @@ public ConfigurationOption<String> getServiceNameConfig() {
}

@Nullable
@Override
public String getServiceNodeName() {
String nodeName = serviceNodeName.get();
if (nodeName == null || nodeName.trim().isEmpty()) {
Expand All @@ -889,6 +890,7 @@ public long getDelayTracerStartMs() {
}

@Nullable
@Override
public String getServiceVersion() {
return serviceVersion.get();
}
Expand All @@ -899,6 +901,7 @@ public String getHostname() {
}

@Nullable
@Override
public String getEnvironment() {
return environment.get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@
import org.stagemonitor.configuration.ConfigurationOption;
import org.stagemonitor.configuration.ConfigurationOptionProvider;

import javax.annotation.Nullable;

public class ServerlessConfiguration extends ConfigurationOptionProvider implements co.elastic.apm.agent.tracer.configuration.ServerlessConfiguration {
public static final String SERVERLESS_CATEGORY = "Serverless";

private final boolean runsOnAwsLambda;

@Nullable
private final String awsLambdaLogStreamName = PrivilegedActionUtils.getEnv("AWS_LAMBDA_LOG_STREAM_NAME");

public ServerlessConfiguration() {
String lambdaName = PrivilegedActionUtils.getEnv("AWS_LAMBDA_FUNCTION_NAME");
this.runsOnAwsLambda = null != lambdaName && !lambdaName.isEmpty();
Expand Down Expand Up @@ -65,4 +70,9 @@ public boolean runsOnAwsLambda() {
return runsOnAwsLambda;
}

@Override
@Nullable
public String awsLambdaLogStreamName() {
return awsLambdaLogStreamName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import co.elastic.apm.agent.configuration.MetricsConfiguration;
import co.elastic.apm.agent.configuration.ServerlessConfiguration;
import co.elastic.apm.agent.context.InitializableLifecycleListener;
import co.elastic.apm.agent.tracer.reporting.DoubleSupplier;
import co.elastic.apm.agent.tracer.reporting.Labels;
import co.elastic.apm.agent.tracer.service.ServiceInfo;
import co.elastic.apm.agent.configuration.SpanConfiguration;
import co.elastic.apm.agent.context.ClosableLifecycleListenerAdapter;
Expand Down Expand Up @@ -947,11 +949,32 @@ public MetaDataFuture getMetaDataFuture() {
return metaDataFuture;
}

@Override
public void addMetric(String name, Labels labels, DoubleSupplier metric) {
metricRegistry.add(name, labels, metric);
}

@Override
public void removeMetric(String name, Labels labels) {
metricRegistry.removeGauge(name, labels);
}

@Override
public void reportLog(String log) {
reporter.reportLog(log);
}

@Override
public void reportLog(byte[] log) {
reporter.reportLog(log);
}

@Override
public ScheduledThreadPoolExecutor getSharedSingleThreadedPool() {
return sharedPool;
}

@Override
public void addShutdownHook(Closeable closeable) {
lifecycleListeners.add(ClosableLifecycleListenerAdapter.of(closeable));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import co.elastic.apm.agent.impl.context.Response;
import co.elastic.apm.agent.impl.context.TransactionContext;
import co.elastic.apm.agent.impl.sampling.Sampler;
import co.elastic.apm.agent.metrics.Labels;
import co.elastic.apm.agent.tracer.reporting.Labels;
import co.elastic.apm.agent.metrics.MetricRegistry;
import co.elastic.apm.agent.metrics.Timer;
import co.elastic.apm.agent.tracer.Outcome;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package co.elastic.apm.agent.metrics;

import co.elastic.apm.agent.tracer.reporting.Labels;

public interface MetricCollector {

void addMetricValue(String metric, Labels labels, double value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import co.elastic.apm.agent.report.ReporterConfiguration;
import co.elastic.apm.agent.sdk.logging.Logger;
import co.elastic.apm.agent.sdk.logging.LoggerFactory;
import co.elastic.apm.agent.tracer.reporting.DoubleSupplier;
import co.elastic.apm.agent.tracer.reporting.Labels;
import org.HdrHistogram.WriterReaderPhaser;

import javax.annotation.Nonnull;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
package co.elastic.apm.agent.metrics;

import co.elastic.apm.agent.tracer.pooling.Recyclable;
import co.elastic.apm.agent.tracer.reporting.DoubleSupplier;
import co.elastic.apm.agent.tracer.reporting.Labels;

import javax.annotation.Nullable;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import co.elastic.apm.agent.configuration.MetricsConfiguration;
import co.elastic.apm.agent.tracer.AbstractLifecycleListener;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.metrics.Labels;
import co.elastic.apm.agent.tracer.reporting.Labels;
import co.elastic.apm.agent.metrics.MetricCollector;
import co.elastic.apm.agent.metrics.MetricRegistry;
import co.elastic.apm.agent.metrics.MetricsProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package co.elastic.apm.agent.metrics.builtin;

import co.elastic.apm.agent.configuration.MetricsConfiguration;
import co.elastic.apm.agent.metrics.Labels;
import co.elastic.apm.agent.tracer.reporting.Labels;
import co.elastic.apm.agent.metrics.MetricCollector;
import co.elastic.apm.agent.metrics.MetricRegistry;
import co.elastic.apm.agent.metrics.MetricsProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

import co.elastic.apm.agent.tracer.AbstractLifecycleListener;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.metrics.DoubleSupplier;
import co.elastic.apm.agent.metrics.Labels;
import co.elastic.apm.agent.tracer.reporting.DoubleSupplier;
import co.elastic.apm.agent.tracer.reporting.Labels;
import co.elastic.apm.agent.metrics.MetricRegistry;
import co.elastic.apm.agent.sdk.logging.Logger;
import co.elastic.apm.agent.sdk.logging.LoggerFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

import co.elastic.apm.agent.tracer.AbstractLifecycleListener;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.metrics.DoubleSupplier;
import co.elastic.apm.agent.metrics.Labels;
import co.elastic.apm.agent.tracer.reporting.DoubleSupplier;
import co.elastic.apm.agent.tracer.reporting.Labels;
import co.elastic.apm.agent.metrics.MetricRegistry;

import javax.annotation.Nullable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

import co.elastic.apm.agent.tracer.AbstractLifecycleListener;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.metrics.DoubleSupplier;
import co.elastic.apm.agent.metrics.Labels;
import co.elastic.apm.agent.tracer.reporting.DoubleSupplier;
import co.elastic.apm.agent.tracer.reporting.Labels;
import co.elastic.apm.agent.metrics.MetricRegistry;
import com.sun.management.ThreadMXBean;
import org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

import co.elastic.apm.agent.tracer.AbstractLifecycleListener;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.metrics.DoubleSupplier;
import co.elastic.apm.agent.metrics.Labels;
import co.elastic.apm.agent.tracer.reporting.DoubleSupplier;
import co.elastic.apm.agent.tracer.reporting.Labels;
import co.elastic.apm.agent.metrics.MetricRegistry;
import co.elastic.apm.agent.sdk.logging.Logger;
import co.elastic.apm.agent.sdk.logging.LoggerFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import co.elastic.apm.agent.tracer.AbstractLifecycleListener;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.common.util.WildcardMatcher;
import co.elastic.apm.agent.metrics.DoubleSupplier;
import co.elastic.apm.agent.metrics.Labels;
import co.elastic.apm.agent.tracer.reporting.DoubleSupplier;
import co.elastic.apm.agent.tracer.reporting.Labels;
import co.elastic.apm.agent.metrics.MetricRegistry;
import co.elastic.apm.agent.tracer.GlobalTracer;
import co.elastic.apm.agent.util.JmxUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

import co.elastic.apm.agent.tracer.AbstractLifecycleListener;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.metrics.DoubleSupplier;
import co.elastic.apm.agent.metrics.Labels;
import co.elastic.apm.agent.tracer.reporting.DoubleSupplier;
import co.elastic.apm.agent.tracer.reporting.Labels;
import co.elastic.apm.agent.metrics.MetricRegistry;

import java.lang.management.ManagementFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
import co.elastic.apm.agent.impl.transaction.StackFrame;
import co.elastic.apm.agent.impl.transaction.TraceContext;
import co.elastic.apm.agent.impl.transaction.Transaction;
import co.elastic.apm.agent.metrics.Labels;
import co.elastic.apm.agent.tracer.reporting.Labels;
import co.elastic.apm.agent.report.ApmServerClient;
import co.elastic.apm.agent.sdk.internal.collections.LongList;
import co.elastic.apm.agent.sdk.logging.Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import co.elastic.apm.agent.tracer.service.ServiceInfo;
import co.elastic.apm.agent.tracer.AbstractLifecycleListener;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.metrics.Labels;
import co.elastic.apm.agent.tracer.reporting.Labels;
import co.elastic.apm.agent.metrics.MetricRegistry;
import co.elastic.apm.agent.metrics.MetricSet;
import co.elastic.apm.agent.report.Reporter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package co.elastic.apm.agent.report.serialize;

import co.elastic.apm.agent.tracer.service.ServiceInfo;
import co.elastic.apm.agent.metrics.DoubleSupplier;
import co.elastic.apm.agent.tracer.reporting.DoubleSupplier;
import co.elastic.apm.agent.metrics.MetricSet;
import co.elastic.apm.agent.metrics.Timer;
import com.dslplatform.json.DslJson;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import co.elastic.apm.agent.impl.transaction.Span;
import co.elastic.apm.agent.impl.transaction.TraceContext;
import co.elastic.apm.agent.impl.transaction.Transaction;
import co.elastic.apm.agent.metrics.Labels;
import co.elastic.apm.agent.tracer.reporting.Labels;
import co.elastic.apm.agent.objectpool.TestObjectPoolFactory;
import co.elastic.apm.agent.report.ApmServerClient;
import co.elastic.apm.agent.tracer.Outcome;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import co.elastic.apm.agent.impl.transaction.AbstractSpan;
import co.elastic.apm.agent.impl.transaction.Span;
import co.elastic.apm.agent.impl.transaction.Transaction;
import co.elastic.apm.agent.metrics.Labels;
import co.elastic.apm.agent.tracer.reporting.Labels;
import co.elastic.apm.agent.metrics.MetricSet;
import co.elastic.apm.agent.metrics.Timer;
import org.junit.jupiter.api.AfterEach;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import co.elastic.apm.agent.configuration.MetricsConfiguration;
import co.elastic.apm.agent.common.util.WildcardMatcher;
import co.elastic.apm.agent.report.ReporterConfiguration;
import co.elastic.apm.agent.tracer.reporting.DoubleSupplier;
import co.elastic.apm.agent.tracer.reporting.Labels;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import co.elastic.apm.agent.configuration.MetricsConfiguration;
import co.elastic.apm.agent.common.util.WildcardMatcher;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.metrics.Labels;
import co.elastic.apm.agent.tracer.reporting.Labels;
import co.elastic.apm.agent.metrics.MetricRegistry;
import co.elastic.apm.agent.metrics.MetricSet;
import co.elastic.apm.agent.report.ReporterConfiguration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import co.elastic.apm.agent.configuration.MetricsConfiguration;
import co.elastic.apm.agent.common.util.WildcardMatcher;
import co.elastic.apm.agent.metrics.Labels;
import co.elastic.apm.agent.tracer.reporting.Labels;
import co.elastic.apm.agent.metrics.MetricRegistry;
import co.elastic.apm.agent.metrics.MetricSet;
import co.elastic.apm.agent.report.ReporterConfiguration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import co.elastic.apm.agent.configuration.MetricsConfiguration;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.metrics.Labels;
import co.elastic.apm.agent.tracer.reporting.Labels;
import co.elastic.apm.agent.metrics.MetricRegistry;
import co.elastic.apm.agent.report.ReporterConfiguration;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import co.elastic.apm.agent.configuration.MetricsConfiguration;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.metrics.Labels;
import co.elastic.apm.agent.tracer.reporting.Labels;
import co.elastic.apm.agent.metrics.MetricRegistry;
import co.elastic.apm.agent.report.ReporterConfiguration;
import org.junit.jupiter.api.condition.DisabledOnOs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import co.elastic.apm.agent.configuration.MetricsConfiguration;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.metrics.Labels;
import co.elastic.apm.agent.tracer.reporting.Labels;
import co.elastic.apm.agent.metrics.MetricRegistry;
import co.elastic.apm.agent.report.ReporterConfiguration;
import org.assertj.core.api.AbstractDoubleAssert;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import co.elastic.apm.agent.configuration.MetricsConfiguration;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.metrics.Labels;
import co.elastic.apm.agent.tracer.reporting.Labels;
import co.elastic.apm.agent.metrics.MetricRegistry;
import co.elastic.apm.agent.report.ReporterConfiguration;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import co.elastic.apm.agent.configuration.MetricsConfiguration;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.metrics.Labels;
import co.elastic.apm.agent.tracer.reporting.Labels;
import co.elastic.apm.agent.metrics.MetricRegistry;
import co.elastic.apm.agent.report.ReporterConfiguration;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import co.elastic.apm.agent.configuration.MetricsConfiguration;
import co.elastic.apm.agent.tracer.service.ServiceInfo;
import co.elastic.apm.agent.metrics.Labels;
import co.elastic.apm.agent.tracer.reporting.Labels;
import co.elastic.apm.agent.metrics.MetricCollector;
import co.elastic.apm.agent.metrics.MetricRegistry;
import co.elastic.apm.agent.metrics.MetricsProvider;
Expand Down
7 changes: 0 additions & 7 deletions apm-agent-plugins/apm-ecs-logging-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,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>

<!-- log4j 1.x -->
<dependency>
<groupId>co.elastic.logging</groupId>
Expand Down
9 changes: 0 additions & 9 deletions apm-agent-plugins/apm-jmx-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,4 @@
<apm-agent-parent.base.dir>${project.basedir}/../..</apm-agent-parent.base.dir>
</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>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@
*/
package co.elastic.apm.agent.jmx;

import co.elastic.apm.agent.metrics.Labels;
import co.elastic.apm.agent.tracer.reporting.Labels;
import org.stagemonitor.configuration.converter.AbstractValueConverter;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import java.util.ArrayList;
Expand Down
Loading

0 comments on commit b37db58

Please sign in to comment.