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

feat: resource auto-detection #899

Merged
merged 21 commits into from
Apr 15, 2020

Conversation

mwear
Copy link
Member

@mwear mwear commented Mar 25, 2020

Which problem is this PR solving?

Short description of the changes

The PR ports the existing resource auto-detection logic from OpenCensus. Some of the code has been reorganized and it uses the OpenTelemetry semantic conventions. For the most part, resource auto-detection is unspecified for OTel, so I've kept to the Census approach for the initial port.

The biggest change from the Census implementation is that I reorganized the detection logic for each Resource type into its own "detector" class. With the goal of making it easier to add detectors in the future.

For reference, here are links to the Census code this is based on:

Because there is potential latency involved in auto-detection, users need to manually call the detectResources method during setup, making this functionality opt-in. For example:

import { detectResources } from '@opentelemetry/resources'

const provider = new NodeTracerProvider({ resource: detectResources() });

@codecov-io
Copy link

codecov-io commented Mar 25, 2020

Codecov Report

Merging #899 into master will increase coverage by 0.04%.
The diff coverage is 96.39%.

@@            Coverage Diff             @@
##           master     #899      +/-   ##
==========================================
+ Coverage   94.75%   94.79%   +0.04%     
==========================================
  Files         248      259      +11     
  Lines       11288    11590     +302     
  Branches     1079     1094      +15     
==========================================
+ Hits        10696    10987     +291     
- Misses        592      603      +11     
Impacted Files Coverage Δ
...rces/src/platform/node/detectors/AwsEc2Detector.ts 87.09% <87.09%> (ø)
...sources/src/platform/node/detectors/EnvDetector.ts 88.09% <88.09%> (ø)
...sources/src/platform/node/detectors/GcpDetector.ts 95.12% <95.12%> (ø)
packages/opentelemetry-resources/src/Resource.ts 100.00% <100.00%> (ø)
...ages/opentelemetry-resources/src/platform/index.ts 100.00% <100.00%> (ø)
...ry-resources/src/platform/node/detect-resources.ts 100.00% <100.00%> (ø)
...try-resources/src/platform/node/detectors/index.ts 100.00% <100.00%> (ø)
...opentelemetry-resources/src/platform/node/index.ts 100.00% <100.00%> (ø)
...ages/opentelemetry-resources/test/Resource.test.ts 100.00% <100.00%> (ø)
...ntelemetry-resources/test/detect-resources.test.ts 100.00% <100.00%> (ø)
... and 15 more

Copy link
Member

@mayurkale22 mayurkale22 left a comment

Choose a reason for hiding this comment

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

Overall LGTM, added a few comments in the first pass.

* EnvDetector can be used to detect the presence of and create a Resource
* from the OTEL_RESOURCE_LABELS environment variable.
*/
export class EnvDetector {
Copy link
Member

Choose a reason for hiding this comment

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

I think specs is not yet defined for the env detector. Perhaps, we can open an issue in specs to start the discussion.

Copy link
Member Author

Choose a reason for hiding this comment

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

@mwear mwear force-pushed the resource_autodetection branch 2 times, most recently from d0e0cf5 to db0df52 Compare April 1, 2020 19:12
@@ -55,6 +60,7 @@
},
"dependencies": {
"@opentelemetry/api": "^0.5.2",
"@opentelemetry/base": "^0.5.2"
"@opentelemetry/base": "^0.5.2",
"gcp-metadata": "^3.5.0"
Copy link
Member

Choose a reason for hiding this comment

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

Minor: latest available version is 4.0.0.

Copy link
Member Author

Choose a reason for hiding this comment

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

It appears as though node 8 support was dropped in 4.0.0: https://github.com/googleapis/gcp-metadata/blob/master/CHANGELOG.md#-breaking-changes.

Copy link
Member

@mayurkale22 mayurkale22 left a comment

Choose a reason for hiding this comment

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

Overall LGTM, thanks for the PR.

try {
resolve(JSON.parse(rawData));
} catch (e) {
res.resume(); // consume response data to free up memory
Copy link
Member

Choose a reason for hiding this comment

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

There is no need to call resume after end event as far as I'm aware. Can you explain why you're calling it here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

From the node http docs:

if a 'response' event handler is added, then the data from the response object must be consumed, either by calling response.read() whenever there is a 'readable' event, or by adding a 'data' handler, or by calling the .resume() method. Until the data is consumed, the 'end' event will not fire.

To me, this implies that resume has nothing to consume when the 'end' event fires.

@mayurkale22 added that line to census so maybe he can weigh in?

Copy link
Member Author

Choose a reason for hiding this comment

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

I removed the res.resume() calls. I can add them back if we find they do have a benefit.

*/
export const detectResources = async (): Promise<Resource> => {
const resources: Array<Resource> = await Promise.all(
DETECTORS.map(d => d.detect())
Copy link
Member

Choose a reason for hiding this comment

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

What happens if a detector throws?

Copy link
Member Author

Choose a reason for hiding this comment

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

I added a try / catch.

@mwear mwear force-pushed the resource_autodetection branch 2 times, most recently from 1ebaab9 to a8486fc Compare April 4, 2020 03:29
@mayurkale22
Copy link
Member

I think this is good to go, please resolve the merge conflicts.

@dyladan dyladan added the enhancement New feature or request label Apr 9, 2020
Copy link
Member

@vmarchaud vmarchaud left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Member

@obecny obecny left a comment

Choose a reason for hiding this comment

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

lgtm, nice documentation!

@dyladan dyladan merged commit 182e9ee into open-telemetry:master Apr 15, 2020
pichlermarc pushed a commit to dynatrace-oss-contrib/opentelemetry-js that referenced this pull request Dec 15, 2023
…dCapacity is set to None (open-telemetry#899)

* DynamoDB metrics for BatchGetItem fails when ReturnConsumedCapacity is set to NONE

* fix(unit): add unit test and change if

* fix(formatting): wrong formatting

* fix(formatting): formatting

Co-authored-by: Amir Blum <amir@aspecto.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants