-
Notifications
You must be signed in to change notification settings - Fork 836
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
refactor: separate resource detector packages #1420
refactor: separate resource detector packages #1420
Conversation
@@ -0,0 +1,63 @@ | |||
{ | |||
"name": "@opentelemetry/resource-detector-aws", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I split them based on cloud vendor, so ec2, beanstalk, etc would all live here.
Codecov Report
@@ Coverage Diff @@
## master #1420 +/- ##
==========================================
- Coverage 94.31% 93.53% -0.78%
==========================================
Files 146 146
Lines 4396 4009 -387
Branches 893 774 -119
==========================================
- Hits 4146 3750 -396
- Misses 250 259 +9
|
…nto refactor/separate-resource-detectors
@@ -128,4 +169,233 @@ describe('Node SDK', () => { | |||
assert.ok(metrics.getMeterProvider() instanceof MeterProvider); | |||
}); | |||
}); | |||
|
|||
describe('detectResources', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of the old detect-resources.test.ts
tests required the actual detectors, so I moved these tests from @opentelemetry/resources
tests to sdk.test.ts
. This move affects codecov, so eventually new tests with test-stub detectors should be added to the resources package
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. We should add a couple stub detectors like one that fails and one that succeeds.
const detectorName = DETECTORS[index].constructor | ||
? DETECTORS[index].constructor.name | ||
: 'Unknown detector'; | ||
const detectorName = resource.detectedBy; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've modified the Resource
ctor to keep this functionality, but I don't think my change is ideal... /cc @mwear
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The detectors have access to the logger (via the config) and log info during a failure. You could consider moving the logging for successful detections into the detector as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, but I think you could go one step further, and have the Detector log the detected resources as they're found, rather than finding them all first and logging afterwards. Specifically, you could move this logging into the detector: https://github.com/open-telemetry/opentelemetry-js/pull/1420/files#diff-1328771aa7fff461aee162025e488e55R67-R79.
Do this only if you think it's an improvement though.
public async detectResources(config?: ResourceDetectionConfig) { | ||
const internalConfig: ResourceDetectionConfig = { | ||
...config, | ||
detectors: [awsEc2Detector, gcpDetector, envDetector], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now provide detectors via sdk config
What do we think about keeping the env detector in the resources package? It is simple and has no external dependencies, and is required by the spec. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a couple of non-blocking questions / comments, but otherwise LGTM!
const detectorName = DETECTORS[index].constructor | ||
? DETECTORS[index].constructor.name | ||
: 'Unknown detector'; | ||
const detectorName = resource.detectedBy; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The detectors have access to the logger (via the config) and log info during a failure. You could consider moving the logging for successful detections into the detector as well.
…nto refactor/separate-resource-detectors
packages/opentelemetry-resource-detector-aws/src/detectors/AwsEc2Detector.ts
Outdated
Show resolved
Hide resolved
[HOST_RESOURCE.TYPE]: instanceType, | ||
}, | ||
); | ||
config.logger.debug(`${this.constructor.name} found resource.`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Success and failure could be logged by the caller, which would make it consistent across detectors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -62,7 +63,10 @@ class GcpDetector implements Detector { | |||
if (process.env.KUBERNETES_SERVICE_HOST) | |||
this._addK8sLabels(labels, clusterName); | |||
|
|||
return new Resource(labels); | |||
const resource = new Resource(labels); | |||
config.logger.debug(`${this.constructor.name} found resource.`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment wrt logging by the caller
packages/opentelemetry-resources/src/platform/node/detect-resources.ts
Outdated
Show resolved
Hide resolved
@@ -61,7 +64,9 @@ class EnvDetector implements Detector { | |||
const labels = this._parseResourceLabels( | |||
process.env.OTEL_RESOURCE_LABELS | |||
); | |||
return new Resource(labels); | |||
const resource = new Resource(labels); | |||
config.logger.debug(`${this.constructor.name} found resource.`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same :)
@@ -128,4 +169,233 @@ describe('Node SDK', () => { | |||
assert.ok(metrics.getMeterProvider() instanceof MeterProvider); | |||
}); | |||
}); | |||
|
|||
describe('detectResources', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. We should add a couple stub detectors like one that fails and one that succeeds.
@@ -44,10 +40,13 @@ export const detectResources = async ( | |||
); | |||
|
|||
const resources: Array<Resource> = await Promise.all( | |||
DETECTORS.map(d => { | |||
(internalConfig.detectors || []).map(async d => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick but this ||
could be ??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
…nto refactor/separate-resource-detectors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm very fond of this PR as AWS/GCP detectors are slow in my environment most time. 👍
Please resolve the conflicts and this can be merged |
|
||
## Usage | ||
|
||
> TODO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
…nto refactor/separate-resource-detectors
…nto refactor/separate-resource-detectors
Which problem is this PR solving?
Short description of the changes
detectors[]
config todetect-resources.ts
.node-sdk
will fill these in with all of the "default" resource detectors./cc @mwear @dyladan