-
Notifications
You must be signed in to change notification settings - Fork 163
Declarative config: Cloud component providers #2014
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
Changes from all commits
2c7575b
9eb3634
641bffe
01c3488
73cdcf5
4ae3dec
9c2067f
ba4b4ed
cfa2f54
2084d65
90e574e
ea833b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.contrib.aws.resource.internal; | ||
|
||
import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; | ||
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.sdk.autoconfigure.spi.internal.ComponentProvider; | ||
import io.opentelemetry.sdk.resources.Resource; | ||
import io.opentelemetry.sdk.resources.ResourceBuilder; | ||
|
||
public class AwsResourceDetector implements ComponentProvider<Resource> { | ||
|
||
@Override | ||
public Class<Resource> getType() { | ||
return Resource.class; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "aws"; | ||
} | ||
|
||
@Override | ||
public Resource create(DeclarativeConfigProperties config) { | ||
ResourceBuilder builder = Resource.builder(); | ||
builder.putAll(BeanstalkResource.get()); | ||
builder.putAll(Ec2Resource.get()); | ||
builder.putAll(EcsResource.get()); | ||
builder.putAll(EksResource.get()); | ||
builder.putAll(LambdaResource.get()); | ||
return builder.build(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
io.opentelemetry.contrib.aws.resource.internal.AwsResourceDetector |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.contrib.aws.resource; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import io.opentelemetry.common.ComponentLoader; | ||
import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class ResourceComponentProviderTest { | ||
|
||
@Test | ||
@SuppressWarnings("rawtypes") | ||
void providerIsLoaded() { | ||
Iterable<ComponentProvider> providers = | ||
ComponentLoader.forClassLoader(ResourceComponentProviderTest.class.getClassLoader()) | ||
.load(ComponentProvider.class); | ||
assertThat(providers).extracting(ComponentProvider::getName).containsExactly("aws"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.contrib.azure.resource; | ||
|
||
import io.opentelemetry.api.common.Attributes; | ||
import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; | ||
import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; | ||
import io.opentelemetry.sdk.resources.Resource; | ||
import io.opentelemetry.sdk.resources.ResourceBuilder; | ||
|
||
public class AzureResourceDetector implements ComponentProvider<Resource> { | ||
|
||
@Override | ||
public Class<Resource> getType() { | ||
return Resource.class; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "azure"; | ||
} | ||
|
||
@Override | ||
public Resource create(DeclarativeConfigProperties config) { | ||
zeitlinger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Builder builder = new Builder(); | ||
builder.add(new AzureFunctionsResourceProvider()); | ||
builder.add(new AzureAppServiceResourceProvider()); | ||
builder.add(new AzureContainersResourceProvider()); | ||
builder.addIfEmpty(new AzureAksResourceProvider()); | ||
builder.addIfEmpty(new AzureVmResourceProvider()); | ||
return builder.builder.build(); | ||
} | ||
|
||
private static class Builder { | ||
final ResourceBuilder builder = Resource.builder(); | ||
int attributesCount = 0; | ||
|
||
private void add(CloudResourceProvider provider) { | ||
Attributes attributes = provider.createResource().getAttributes(); | ||
builder.putAll(attributes); | ||
attributesCount += attributes.size(); | ||
} | ||
|
||
private void addIfEmpty(CloudResourceProvider provider) { | ||
if (attributesCount == 0) { | ||
add(provider); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
io.opentelemetry.contrib.azure.resource.AzureResourceDetector |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.contrib.azure.resource; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import io.opentelemetry.common.ComponentLoader; | ||
import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class ResourceComponentProviderTest { | ||
|
||
@Test | ||
@SuppressWarnings("rawtypes") | ||
void providerIsLoaded() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if there's any good way to do an end-to-end style test for these resource detectors like I did here: https://github.com/open-telemetry/opentelemetry-java-contrib/blob/main/samplers/src/test/java/internal/RuleBasedRoutingSamplerComponentProviderTest.java#L39 I.e.:
This has the benefit of being able to act as a form of documentation for users. The assertions may be difficult though because OpenTelemetrySdk doesn't make it easy to access the resource. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. great idea - I'll create a follow-up PR for this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Created #2047 |
||
Iterable<ComponentProvider> providers = | ||
ComponentLoader.forClassLoader(ResourceComponentProviderTest.class.getClassLoader()) | ||
.load(ComponentProvider.class); | ||
assertThat(providers).extracting(ComponentProvider::getName).containsExactly("azure"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.contrib.cloudfoundry.resources; | ||
|
||
import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; | ||
import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; | ||
import io.opentelemetry.sdk.resources.Resource; | ||
|
||
public class CloudFoundryResourceDetector implements ComponentProvider<Resource> { | ||
|
||
@Override | ||
public Class<Resource> getType() { | ||
return Resource.class; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "cloud_foundry"; | ||
} | ||
|
||
@Override | ||
public Resource create(DeclarativeConfigProperties config) { | ||
return CloudFoundryResource.get(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
io.opentelemetry.contrib.cloudfoundry.resources.CloudFoundryResourceDetector |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.contrib.cloudfoundry.resources; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import io.opentelemetry.common.ComponentLoader; | ||
import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class ResourceComponentProviderTest { | ||
|
||
@Test | ||
@SuppressWarnings("rawtypes") | ||
void providerIsLoaded() { | ||
Iterable<ComponentProvider> providers = | ||
ComponentLoader.forClassLoader(ResourceComponentProviderTest.class.getClassLoader()) | ||
.load(ComponentProvider.class); | ||
assertThat(providers).extracting(ComponentProvider::getName).containsExactly("cloud_foundry"); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.