-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reuse contrib resource providers + add existing ones (#4)
* add aws resource provider * add gcp resource provider * add app server resource providers * re-add aws resource providers + server ones * add gcp resource providers * restore otel version + small refactor * first step in shadowing resource providers * use shadowed variant as dependency in agent * keep the 'all' for shaded jar for clarity * use intermediate module for repacking * fix minor things and make it compile in IDE * make spotless happy * add test for ec2 resource provider * slightly refactor ec2 tests * bootstrap eks, but fails due to certificates * mark the eks test as disabled for now * add few extra aws providers * add failing test for lambda & ecs * add lambda + ecs tests * working test with tomcat service name * reformat * add a few comments for later improvements * reformat
- Loading branch information
1 parent
fa913fc
commit aafac43
Showing
17 changed files
with
1,096 additions
and
228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
plugins { | ||
java | ||
alias(gradlePlugins.plugins.shadow) | ||
alias(gradlePlugins.plugins.taskinfo) | ||
} | ||
|
||
dependencies { | ||
|
||
implementation(project("repackaged")) { | ||
attributes { | ||
attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.SHADOWED)) | ||
} | ||
dependencies { | ||
// AWS cloud resource providers transitive dependencies | ||
// TODO remove the static version dependencies, either by automatically getting the | ||
// transitive dependencies of the shaded artifacts, or by reusing the common versions that | ||
// are very likely provided through transitive dependencies | ||
implementation("com.fasterxml.jackson.core:jackson-core:2.15.2") | ||
implementation("com.squareup.okhttp3:okhttp:4.11.0") | ||
|
||
// required to make the IDE compile our own resource provider, won't be included as dependency | ||
compileOnly("io.opentelemetry.contrib:opentelemetry-aws-resources:" + libraries.versions.opentelemetryContribAlpha.get()) | ||
compileOnly("io.opentelemetry.contrib:opentelemetry-resource-providers:" + libraries.versions.opentelemetryContribAlpha.get()) | ||
} | ||
} | ||
|
||
compileOnly("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
plugins { | ||
java | ||
alias(gradlePlugins.plugins.shadow) | ||
alias(gradlePlugins.plugins.taskinfo) | ||
} | ||
|
||
val shadowedImplementation by configurations.creating { | ||
// do not shadow transitive dependencies | ||
isTransitive = false | ||
} | ||
|
||
dependencies { | ||
|
||
// AWS cloud resource providers | ||
shadowedImplementation("io.opentelemetry.contrib:opentelemetry-aws-resources:" + libraries.versions.opentelemetryContribAlpha.get()) | ||
|
||
// TODO : GCP resource providers | ||
// "com.google.cloud.opentelemetry:detector-resources:0.25.2-alpha" | ||
|
||
// application servers resource providers | ||
shadowedImplementation("io.opentelemetry.contrib:opentelemetry-resource-providers:" + libraries.versions.opentelemetryContribAlpha.get()) | ||
} | ||
|
||
tasks { | ||
assemble { | ||
dependsOn(shadowJar) | ||
} | ||
jar { | ||
// jar not needed as the shadowed jar replaces it | ||
enabled = false | ||
} | ||
shadowJar { | ||
configurations = listOf(shadowedImplementation) | ||
|
||
// skip service provider definitions as providers should not be initialized by SDK. | ||
exclude("META-INF/services/**") | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
resources/src/main/java/co/elastic/otel/resources/ElasticResourceProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package co.elastic.otel.resources; | ||
|
||
import io.opentelemetry.contrib.aws.resource.BeanstalkResource; | ||
import io.opentelemetry.contrib.aws.resource.Ec2Resource; | ||
import io.opentelemetry.contrib.aws.resource.EcsResource; | ||
import io.opentelemetry.contrib.aws.resource.EksResource; | ||
import io.opentelemetry.contrib.aws.resource.LambdaResource; | ||
import io.opentelemetry.contrib.resourceproviders.AppServerServiceNameProvider; | ||
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; | ||
import io.opentelemetry.sdk.autoconfigure.spi.ResourceProvider; | ||
import io.opentelemetry.sdk.resources.Resource; | ||
|
||
public class ElasticResourceProvider implements ResourceProvider { | ||
|
||
@Override | ||
public Resource createResource(ConfigProperties config) { | ||
Resource resource = Resource.empty(); | ||
|
||
// TODO : find a way to make the resource providers async, and then retrieve it | ||
// maybe using a "magic value" for the config properties could be relevant here | ||
|
||
resource = | ||
resource | ||
// ec2 relies on http calls without pre-checks | ||
.merge(Ec2Resource.get()) | ||
// beanstalk relies on json config file parsing | ||
.merge(BeanstalkResource.get()) | ||
// relies on https call without pre-checks + TLS setup (thus quite expensive) | ||
.merge(EksResource.get()) | ||
// relies on http call with url provided through env var used as pre-check | ||
.merge(EcsResource.get()) | ||
// relies on env variables only | ||
.merge(LambdaResource.get()); | ||
|
||
// application server providers | ||
resource = resource.merge(new AppServerServiceNameProvider().createResource(config)); | ||
|
||
return resource; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
.../main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.ResourceProvider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
co.elastic.otel.resources.ElasticResourceProvider |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.