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

Metering API Implementation #99723

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a47afbc
Sketch of metering API
stu-elastic Sep 19, 2023
d73297c
rename, extract Meter interface, compiling
pgomulka Sep 19, 2023
92edce8
security not working
pgomulka Sep 19, 2023
65bfb4d
fix startup order
pgomulka Sep 19, 2023
3422c75
update apm agent
pgomulka Sep 20, 2023
bd3b9b3
metric sent
pgomulka Sep 20, 2023
cfdf63c
Merge branch 'stu-elastic-otel-meter-api' of github.com:pgomulka/elas…
stu-elastic Sep 20, 2023
227df6e
telemetry provider instead of tracer for components
stu-elastic Sep 20, 2023
2057be4
spotless
stu-elastic Sep 20, 2023
8b90b04
Add long and double instruments
stu-elastic Sep 20, 2023
a1674dc
Replace Tracer with TelemetryProvider
stu-elastic Sep 20, 2023
aeed9b4
sm
pgomulka Sep 21, 2023
4bda06b
Merge branch 'otel-meter-api-integ' of github.com:stu-elastic/elastic…
pgomulka Sep 21, 2023
4f2d8c3
Merge remote-tracking branch 'upstream/main' into stu-elastic-otel-me…
pgomulka Sep 21, 2023
2dbac8c
metric package
pgomulka Sep 21, 2023
d2f2c59
introduce telemetry provider interface
pgomulka Sep 21, 2023
7b3f3b6
Rename TracerPlugin to TelemetryPlugin
pgomulka Sep 21, 2023
74dffd4
create components
pgomulka Sep 21, 2023
ad70756
compile fix in test
pgomulka Sep 21, 2023
4fd5978
Merge branch 'telemetry_provider' into create_components_telemetry_pr…
pgomulka Sep 21, 2023
15fd6d1
use telemetryplugin.noop
pgomulka Sep 21, 2023
1dcb599
update branch
pgomulka Sep 21, 2023
6f3f458
Merge pull request #9 from pgomulka/stu-elastic-otel-meter-api
pgomulka Sep 21, 2023
7c3c13a
Merge remote-tracking branch 'upstream/main' into stu-elastic-otel-me…
pgomulka Sep 22, 2023
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
2 changes: 1 addition & 1 deletion TRACING.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,6 @@ explicitly opening a scope via the `Tracer`.
[otel]: https://opentelemetry.io/
[thread-context]: ./server/src/main/java/org/elasticsearch/common/util/concurrent/ThreadContext.java
[w3c]: https://www.w3.org/TR/trace-context/
[tracing]: ./server/src/main/java/org/elasticsearch/tracing
[tracing]: ./server/src/main/java/org/elasticsearch/telemetry
[agent-config]: https://www.elastic.co/guide/en/apm/agent/java/master/configuration.html
[agent]: https://www.elastic.co/guide/en/apm/agent/java/current/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ class APMJvmOptions {
// by the agent. Don't disable writing to a log file, as the agent will then
// require extra Security Manager permissions when it tries to do something
// else, and it's just painful.
"log_file", "_AGENT_HOME_/../../logs/apm.log",

"log_file", "/Users/przemyslawgomulka/workspace/pgomulka/apm.log",
Copy link
Member

Choose a reason for hiding this comment

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

The log file and level need to be reset back to their original levels.

"log_level", "debug",
// ES does not use auto-instrumentation.
"instrument", "false"
"instrument", "false",
"experimental", "true",
"enable_experimental_instrumentations", "true"
);

/**
Expand Down Expand Up @@ -82,7 +84,7 @@ class APMJvmOptions {
// is doing, leave this value alone.
"log_level", "error",
"application_packages", "org.elasticsearch,org.apache.lucene",
"metrics_interval", "120s",
"metrics_interval", "5s",
Copy link
Member

Choose a reason for hiding this comment

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

5 seconds seems pretty aggressive. Do we really need metric resolution at that granularity?

"breakdown_metrics", "false",
"central_config", "false"
);
Expand Down Expand Up @@ -316,9 +318,7 @@ static Path findAgentJar(String installDir) throws IOException, UserException {
}

try (var apmStream = Files.list(apmModule)) {
final List<Path> paths = apmStream.filter(
path -> path.getFileName().toString().matches("elastic-apm-agent-\\d+\\.\\d+\\.\\d+\\.jar")
).toList();
final List<Path> paths = apmStream.filter(path -> path.getFileName().toString().matches("elastic-apm-agent-.*.jar")).toList();

if (paths.size() > 1) {
throw new UserException(
Expand Down
5 changes: 5 additions & 0 deletions gradle/verification-metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@
<sha256 value="3be90268557494f88fe252caf6358d4107aa9349852b8704b1e0ff4831cb74d6" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="co.elastic.apm" name="elastic-apm-agent" version="1.37.0">
<artifact name="elastic-apm-agent-1.37.0.jar">
<sha256 value="10496390d1dcc7c558ae63e115beff9477157e3d219fce686ef5ca59c744dfea" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="co.elastic.logging" name="ecs-logging-core" version="1.2.0">
<artifact name="ecs-logging-core-1.2.0.jar">
<sha256 value="0d6318af29848ea588b1c244834e3e762315c68de2bcfc9f1adf3f0633d22d37" origin="Generated by Gradle"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
import org.elasticsearch.script.ScriptContext;
import org.elasticsearch.script.ScriptService;
import org.elasticsearch.synonyms.SynonymsManagementAPIService;
import org.elasticsearch.telemetry.tracing.Tracer;
import org.elasticsearch.telemetry.TelemetryProvider;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.watcher.ResourceWatcherService;
import org.elasticsearch.xcontent.NamedXContentRegistry;
Expand Down Expand Up @@ -168,7 +168,7 @@ public Collection<Object> createComponents(
NamedWriteableRegistry namedWriteableRegistry,
IndexNameExpressionResolver expressionResolver,
Supplier<RepositoriesService> repositoriesServiceSupplier,
Tracer tracer,
TelemetryProvider telemetryProvider,
AllocationService allocationService,
IndicesService indicesService
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptContext;
import org.elasticsearch.script.ScriptService;
import org.elasticsearch.telemetry.tracing.Tracer;
import org.elasticsearch.telemetry.TelemetryProvider;
import org.elasticsearch.test.ESTokenStreamTestCase;
import org.elasticsearch.test.IndexSettingsModule;
import org.elasticsearch.threadpool.ThreadPool;
Expand Down Expand Up @@ -68,7 +68,22 @@ public <FactoryType> FactoryType compile(Script script, ScriptContext<FactoryTyp
};
Client client = new MockClient(Settings.EMPTY, null);
CommonAnalysisPlugin plugin = new CommonAnalysisPlugin();
plugin.createComponents(client, null, null, null, scriptService, null, null, null, null, null, null, Tracer.NOOP, null, null);
plugin.createComponents(
client,
null,
null,
null,
scriptService,
null,
null,
null,
null,
null,
null,
TelemetryProvider.NOOP,
null,
null
);
AnalysisModule module = new AnalysisModule(
TestEnvironment.newEnvironment(settings),
Collections.singletonList(plugin),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptContext;
import org.elasticsearch.script.ScriptService;
import org.elasticsearch.telemetry.tracing.Tracer;
import org.elasticsearch.telemetry.TelemetryProvider;
import org.elasticsearch.test.ESTokenStreamTestCase;
import org.elasticsearch.test.IndexSettingsModule;
import org.elasticsearch.threadpool.ThreadPool;
Expand Down Expand Up @@ -68,7 +68,22 @@ public <FactoryType> FactoryType compile(Script script, ScriptContext<FactoryTyp
};
Client client = new MockClient(Settings.EMPTY, null);
CommonAnalysisPlugin plugin = new CommonAnalysisPlugin();
plugin.createComponents(client, null, null, null, scriptService, null, null, null, null, null, null, Tracer.NOOP, null, null);
plugin.createComponents(
client,
null,
null,
null,
scriptService,
null,
null,
null,
null,
null,
null,
TelemetryProvider.NOOP,
null,
null
);
AnalysisModule module = new AnalysisModule(
TestEnvironment.newEnvironment(settings),
Collections.singletonList(plugin),
Expand Down
8 changes: 7 additions & 1 deletion modules/apm/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@ esplugin {

def otelVersion = '1.17.0'

repositories {
maven {
name "sonatype-nexus-snapshots"
url "https://oss.sonatype.org/content/repositories/snapshots"
}
}
dependencies {
implementation "io.opentelemetry:opentelemetry-api:${otelVersion}"
implementation "io.opentelemetry:opentelemetry-context:${otelVersion}"
implementation "io.opentelemetry:opentelemetry-semconv:${otelVersion}-alpha"
runtimeOnly "co.elastic.apm:elastic-apm-agent:1.36.0"
implementation "co.elastic.apm:elastic-apm-agent:1.42.1-SNAPSHOT"
Copy link
Member

Choose a reason for hiding this comment

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

We should not commit a snapshot dependency, we'll need to wait until this is released.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good.

}

tasks.named("dependencyLicenses").configure {
Expand Down
26 changes: 14 additions & 12 deletions modules/apm/src/main/java/org/elasticsearch/telemetry/apm/APM.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.plugins.NetworkPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.plugins.TracerPlugin;
import org.elasticsearch.plugins.TelemetryPlugin;
import org.elasticsearch.repositories.RepositoriesService;
import org.elasticsearch.script.ScriptService;
import org.elasticsearch.telemetry.TelemetryProvider;
import org.elasticsearch.telemetry.apm.settings.APMAgentSettings;
import org.elasticsearch.telemetry.apm.tracing.APMTracer;
import org.elasticsearch.telemetry.tracing.Tracer;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.watcher.ResourceWatcherService;
import org.elasticsearch.xcontent.NamedXContentRegistry;
Expand Down Expand Up @@ -55,19 +55,19 @@
* be passed via system properties to the Java agent, which periodically checks for changes
* and applies the new settings values, provided those settings can be dynamically updated.
*/
public class APM extends Plugin implements NetworkPlugin, TracerPlugin {
private final SetOnce<APMTracer> tracer = new SetOnce<>();
public class APM extends Plugin implements NetworkPlugin, TelemetryPlugin {
private final SetOnce<APMTelemetryProvider> telemetryProvider = new SetOnce<>();
private final Settings settings;

public APM(Settings settings) {
this.settings = settings;
}

@Override
public Tracer getTracer(Settings settings) {
final APMTracer apmTracer = new APMTracer(settings);
tracer.set(apmTracer);
return apmTracer;
public TelemetryProvider getTelemetryProvider(Settings settings) {
final APMTelemetryProvider apmTelemetryProvider = new APMTelemetryProvider(settings);
telemetryProvider.set(apmTelemetryProvider);
return apmTelemetryProvider;
}

@Override
Expand All @@ -83,20 +83,22 @@ public Collection<Object> createComponents(
NamedWriteableRegistry namedWriteableRegistry,
IndexNameExpressionResolver indexNameExpressionResolver,
Supplier<RepositoriesService> repositoriesServiceSupplier,
Tracer unused,
TelemetryProvider unused,
AllocationService allocationService,
IndicesService indicesService
) {
final APMTracer apmTracer = tracer.get();
final APMTracer apmTracer = telemetryProvider.get().getTracer();
Copy link
Member

Choose a reason for hiding this comment

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

Why is the provider captured, when it is already passed in? It should be the exact same, so we could avoid the SetOnce?


apmTracer.setClusterName(clusterService.getClusterName().value());
apmTracer.setNodeName(clusterService.getNodeName());

final APMAgentSettings apmAgentSettings = new APMAgentSettings();
apmAgentSettings.syncAgentSystemProperties(settings);
apmAgentSettings.addClusterSettingsListeners(clusterService, apmTracer);
apmAgentSettings.addClusterSettingsListeners(clusterService, telemetryProvider.get());

return List.of(apmTracer);
final APMMetric apmMetric = telemetryProvider.get().getMetric();

return List.of(apmTracer, apmMetric);
}

@Override
Expand Down
Loading