-
Notifications
You must be signed in to change notification settings - Fork 544
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(detector-alibaba)!: change implementation to DetectorSync interface #2328
Merged
david-luna
merged 14 commits into
open-telemetry:main
from
david-luna:dluna/aibaba-ecs-detector-sync
Aug 2, 2024
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
3389dcc
refactor(detector-alibaba): change implementation to DetectorSync int…
david-luna 0fd9ba3
refactor(detector-alibaba): fix return type
david-luna 3ded77a
Update detectors/node/opentelemetry-resource-detector-alibaba-cloud/t…
david-luna 2b50ea1
chore(detector-alibaba): remove unused fixture file
david-luna 72663b9
chore(detector-alibaba): sync changes
david-luna 873b9a5
chore(detector-alibaba): update dependencies
david-luna e672c53
Merge branch 'main' into dluna/aibaba-ecs-detector-sync
david-luna 42862a8
refactor(detector-alibaba): avoid breaking change in API
david-luna baaa6ee
chore(detector-alibaba): fix lint issue
david-luna 25bcb8d
chore(detector-alibaba): move constants to a separate file
david-luna fdd6524
chore(detector-alibaba): remove async detector
david-luna 57bf61a
chore(detector-alibaba): reset test name
david-luna ac92a5c
Merge branch 'main' into dluna/aibaba-ecs-detector-sync
david-luna fe26750
Merge branch 'main' into dluna/aibaba-ecs-detector-sync
david-luna File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -18,11 +18,11 @@ import * as nock from 'nock'; | |
import * as assert from 'assert'; | ||
import { Resource } from '@opentelemetry/resources'; | ||
import { CLOUDPROVIDERVALUES_ALIBABA_CLOUD } from '@opentelemetry/semantic-conventions'; | ||
import { alibabaCloudEcsDetector } from '../../src'; | ||
import { | ||
assertCloudResource, | ||
assertHostResource, | ||
} from '@opentelemetry/contrib-test-utils'; | ||
import { alibabaCloudEcsDetector } from '../../src'; | ||
|
||
const ALIYUN_HOST = | ||
'http://' + alibabaCloudEcsDetector.ALIBABA_CLOUD_IDMS_ENDPOINT; | ||
|
@@ -64,6 +64,7 @@ describe('alibabaCloudEcsDetector', () => { | |
.reply(200, () => mockedHostResponse); | ||
|
||
const resource: Resource = await alibabaCloudEcsDetector.detect(); | ||
await resource.waitForAsyncAttributes?.(); | ||
|
||
scope.done(); | ||
|
||
|
@@ -84,56 +85,47 @@ describe('alibabaCloudEcsDetector', () => { | |
}); | ||
|
||
describe('with unsuccessful request', () => { | ||
it('should throw when receiving error response code', async () => { | ||
const expectedError = new Error('Failed to load page, status code: 404'); | ||
it('should return empty resource when receiving error response code', async () => { | ||
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. note to reviewer: the detector does not throw but rather returns a resource with no attribs. |
||
const scope = nock(ALIYUN_HOST) | ||
.persist() | ||
.get(ALIYUN_IDENTITY_PATH) | ||
.reply(200, () => mockedIdentityResponse) | ||
.get(ALIYUN_HOST_PATH) | ||
.reply(404, () => new Error()); | ||
|
||
try { | ||
await alibabaCloudEcsDetector.detect(); | ||
assert.ok(false, 'Expected to throw'); | ||
} catch (err) { | ||
assert.deepStrictEqual(err, expectedError); | ||
} | ||
const resource = await alibabaCloudEcsDetector.detect(); | ||
await resource.waitForAsyncAttributes?.(); | ||
|
||
assert.deepStrictEqual(resource.attributes, {}); | ||
|
||
scope.done(); | ||
}); | ||
|
||
it('should throw when timed out', async () => { | ||
const expectedError = new Error('ECS metadata api request timed out.'); | ||
it('should return empty resource when timed out', async () => { | ||
const scope = nock(ALIYUN_HOST) | ||
.get(ALIYUN_IDENTITY_PATH) | ||
.reply(200, () => mockedIdentityResponse) | ||
.get(ALIYUN_HOST_PATH) | ||
.delayConnection(2000) | ||
.reply(200, () => mockedHostResponse); | ||
|
||
try { | ||
await alibabaCloudEcsDetector.detect(); | ||
assert.ok(false, 'Expected to throw'); | ||
} catch (err) { | ||
assert.deepStrictEqual(err, expectedError); | ||
} | ||
const resource = await alibabaCloudEcsDetector.detect(); | ||
await resource.waitForAsyncAttributes?.(); | ||
|
||
assert.deepStrictEqual(resource.attributes, {}); | ||
|
||
scope.done(); | ||
}); | ||
|
||
it('should throw when replied with an Error', async () => { | ||
const expectedError = new Error('NOT FOUND'); | ||
it('should return empty resource when replied with an Error', async () => { | ||
const scope = nock(ALIYUN_HOST) | ||
.get(ALIYUN_IDENTITY_PATH) | ||
.replyWithError(expectedError.message); | ||
|
||
try { | ||
await alibabaCloudEcsDetector.detect(); | ||
assert.ok(false, 'Expected to throw'); | ||
} catch (err) { | ||
assert.deepStrictEqual(err, expectedError); | ||
} | ||
.replyWithError('NOT FOUND'); | ||
|
||
const resource = await alibabaCloudEcsDetector.detect(); | ||
await resource.waitForAsyncAttributes?.(); | ||
|
||
assert.deepStrictEqual(resource.attributes, {}); | ||
|
||
scope.done(); | ||
}); | ||
|
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
note to reviewer: little step forward to resolve open-telemetry/opentelemetry-js#4186