forked from open-telemetry/opentelemetry-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: container ID detector for cgroup v2 (open-telemetry#1181)
* added another block to test for v2 * feat: changing export name to reflect generic docker * feat: adding geenric naming and logic changes to support cgroup v2 * test: test file renamed * feat: adding hostname check * feat: adding hostname check- refactor * feat: fixed a test and fixed lint * feat: added another condition to check for length * test: added two more tests * feat: renamed docker to container and addressed pr comments * feat: renamed docker to container and addressed pr comments- 2 * feat: renamed docker to container and addressed pr comments-3 * feat: addressed pr comments-2 * feat: modified tests to take in multiple lines input * feat: merge resolution for manifest * feat: fixing release please manifest * feat: changing please-config to rename docker to container * feat: replaced >= check to == check
- Loading branch information
Showing
15 changed files
with
197 additions
and
121 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
{"detectors/node/opentelemetry-resource-detector-alibaba-cloud":"0.27.2","detectors/node/opentelemetry-resource-detector-aws":"1.1.2","detectors/node/opentelemetry-resource-detector-docker":"0.1.2","detectors/node/opentelemetry-resource-detector-gcp":"0.27.2","detectors/node/opentelemetry-resource-detector-github":"0.27.0","detectors/node/opentelemetry-resource-detector-instana":"0.3.0","metapackages/auto-instrumentations-node":"0.33.1","metapackages/auto-instrumentations-web":"0.30.0","packages/opentelemetry-host-metrics":"0.30.1","packages/opentelemetry-id-generator-aws-xray":"1.1.0","packages/opentelemetry-propagation-utils":"0.29.0","packages/opentelemetry-test-utils":"0.32.0","plugins/node/instrumentation-amqplib":"0.31.0","plugins/node/instrumentation-dataloader":"0.2.0","plugins/node/instrumentation-fs":"0.5.0","plugins/node/instrumentation-lru-memoizer":"0.31.0","plugins/node/instrumentation-mongoose":"0.31.0","plugins/node/instrumentation-tedious":"0.4.0","plugins/node/opentelemetry-instrumentation-aws-lambda":"0.33.0","plugins/node/opentelemetry-instrumentation-aws-sdk":"0.9.2","plugins/node/opentelemetry-instrumentation-bunyan":"0.30.0","plugins/node/opentelemetry-instrumentation-cassandra":"0.30.0","plugins/node/opentelemetry-instrumentation-connect":"0.30.0","plugins/node/opentelemetry-instrumentation-dns":"0.30.0","plugins/node/opentelemetry-instrumentation-express":"0.31.2","plugins/node/opentelemetry-instrumentation-fastify":"0.30.0","plugins/node/opentelemetry-instrumentation-generic-pool":"0.30.0","plugins/node/opentelemetry-instrumentation-graphql":"0.31.0","plugins/node/opentelemetry-instrumentation-hapi":"0.30.0","plugins/node/opentelemetry-instrumentation-ioredis":"0.32.1","plugins/node/opentelemetry-instrumentation-knex":"0.30.0","plugins/node/opentelemetry-instrumentation-koa":"0.32.0","plugins/node/opentelemetry-instrumentation-memcached":"0.30.0","plugins/node/opentelemetry-instrumentation-mongodb":"0.32.1","plugins/node/opentelemetry-instrumentation-mysql":"0.31.1","plugins/node/opentelemetry-instrumentation-mysql2":"0.32.0","plugins/node/opentelemetry-instrumentation-nestjs-core":"0.31.0","plugins/node/opentelemetry-instrumentation-net":"0.30.1","plugins/node/opentelemetry-instrumentation-pg":"0.31.1","plugins/node/opentelemetry-instrumentation-pino":"0.32.0","plugins/node/opentelemetry-instrumentation-redis":"0.33.0","plugins/node/opentelemetry-instrumentation-redis-4":"0.33.0","plugins/node/opentelemetry-instrumentation-restify":"0.30.0","plugins/node/opentelemetry-instrumentation-router":"0.30.0","plugins/node/opentelemetry-instrumentation-winston":"0.30.0","plugins/web/opentelemetry-instrumentation-document-load":"0.30.0","plugins/web/opentelemetry-instrumentation-long-task":"0.31.0","plugins/web/opentelemetry-instrumentation-user-interaction":"0.31.0","plugins/web/opentelemetry-plugin-react-load":"0.28.0","propagators/opentelemetry-propagator-aws-xray":"1.1.0","propagators/opentelemetry-propagator-grpc-census-binary":"0.26.0","propagators/opentelemetry-propagator-instana":"0.2.0","propagators/opentelemetry-propagator-ot-trace":"0.26.1"} | ||
{"detectors/node/opentelemetry-resource-detector-alibaba-cloud":"0.27.2","detectors/node/opentelemetry-resource-detector-aws":"1.1.2","detectors/node/opentelemetry-resource-detector-container":"0.1.2","detectors/node/opentelemetry-resource-detector-gcp":"0.27.2","detectors/node/opentelemetry-resource-detector-github":"0.27.0","detectors/node/opentelemetry-resource-detector-instana":"0.3.0","metapackages/auto-instrumentations-node":"0.33.1","metapackages/auto-instrumentations-web":"0.30.0","packages/opentelemetry-host-metrics":"0.30.1","packages/opentelemetry-id-generator-aws-xray":"1.1.0","packages/opentelemetry-propagation-utils":"0.29.0","packages/opentelemetry-test-utils":"0.32.0","plugins/node/instrumentation-amqplib":"0.31.0","plugins/node/instrumentation-dataloader":"0.2.0","plugins/node/instrumentation-fs":"0.5.0","plugins/node/instrumentation-lru-memoizer":"0.31.0","plugins/node/instrumentation-mongoose":"0.31.0","plugins/node/instrumentation-tedious":"0.4.0","plugins/node/opentelemetry-instrumentation-aws-lambda":"0.33.0","plugins/node/opentelemetry-instrumentation-aws-sdk":"0.9.2","plugins/node/opentelemetry-instrumentation-bunyan":"0.30.0","plugins/node/opentelemetry-instrumentation-cassandra":"0.30.0","plugins/node/opentelemetry-instrumentation-connect":"0.30.0","plugins/node/opentelemetry-instrumentation-dns":"0.30.0","plugins/node/opentelemetry-instrumentation-express":"0.31.2","plugins/node/opentelemetry-instrumentation-fastify":"0.30.0","plugins/node/opentelemetry-instrumentation-generic-pool":"0.30.0","plugins/node/opentelemetry-instrumentation-graphql":"0.31.0","plugins/node/opentelemetry-instrumentation-hapi":"0.30.0","plugins/node/opentelemetry-instrumentation-ioredis":"0.32.1","plugins/node/opentelemetry-instrumentation-knex":"0.30.0","plugins/node/opentelemetry-instrumentation-koa":"0.32.0","plugins/node/opentelemetry-instrumentation-memcached":"0.30.0","plugins/node/opentelemetry-instrumentation-mongodb":"0.32.1","plugins/node/opentelemetry-instrumentation-mysql":"0.31.1","plugins/node/opentelemetry-instrumentation-mysql2":"0.32.0","plugins/node/opentelemetry-instrumentation-nestjs-core":"0.31.0","plugins/node/opentelemetry-instrumentation-net":"0.30.1","plugins/node/opentelemetry-instrumentation-pg":"0.31.1","plugins/node/opentelemetry-instrumentation-pino":"0.32.0","plugins/node/opentelemetry-instrumentation-redis":"0.33.0","plugins/node/opentelemetry-instrumentation-redis-4":"0.33.0","plugins/node/opentelemetry-instrumentation-restify":"0.30.0","plugins/node/opentelemetry-instrumentation-router":"0.30.0","plugins/node/opentelemetry-instrumentation-winston":"0.30.0","plugins/web/opentelemetry-instrumentation-document-load":"0.30.0","plugins/web/opentelemetry-instrumentation-long-task":"0.31.0","plugins/web/opentelemetry-instrumentation-user-interaction":"0.31.0","plugins/web/opentelemetry-plugin-react-load":"0.28.0","propagators/opentelemetry-propagator-aws-xray":"1.1.0","propagators/opentelemetry-propagator-grpc-census-binary":"0.26.0","propagators/opentelemetry-propagator-instana":"0.2.0","propagators/opentelemetry-propagator-ot-trace":"0.26.1"} | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 6 additions & 9 deletions
15
...emetry-resource-detector-docker/README.md → ...try-resource-detector-container/README.md
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
File renamed without changes.
140 changes: 140 additions & 0 deletions
140
detectors/node/opentelemetry-resource-detector-container/test/ContainerDetector.test.ts
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,140 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* | ||
* Licensed 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 | ||
* | ||
* https://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. | ||
*/ | ||
|
||
import * as sinon from 'sinon'; | ||
import * as assert from 'assert'; | ||
import { Resource } from '@opentelemetry/resources'; | ||
import { containerDetector } from '../src'; | ||
import { | ||
assertContainerResource, | ||
assertEmptyResource, | ||
} from '@opentelemetry/contrib-test-utils'; | ||
|
||
import { ContainerDetector } from '../src'; | ||
|
||
describe('ContainerDetector', () => { | ||
let readStub; | ||
const correctCgroupV1Data = | ||
'bcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklm'; | ||
const correctCgroupV2Data = `tmhdefghijklmnopqrstuvwxyzafgrefghiugkmnopqrstuvwxyzabcdefghijkl/hostname | ||
fhkjdshgfhsdfjhdsfkjhfkdshkjhfd/host | ||
sahfhfjkhjhfhjdhfjkdhfkjdhfjkhhdsjfhdfhjdhfkj/somethingelse`; | ||
|
||
const wrongCgroupV2Data = | ||
'bcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklm/wrongkeyword'; | ||
|
||
afterEach(() => { | ||
sinon.restore(); | ||
}); | ||
|
||
describe('Supported container - Container ID ', () => { | ||
it('should return a resource attributes without container id - docker cgroup v1 detector', async () => { | ||
readStub = sinon | ||
.stub(ContainerDetector, 'readFileAsync' as any) | ||
.resolves(undefined); | ||
|
||
const resource: Resource = await containerDetector.detect(); | ||
|
||
assert.deepStrictEqual(resource.attributes, {}); | ||
assert.ok(resource); | ||
}); | ||
|
||
it('should return a resource with container ID with a valid container ID present', async () => { | ||
readStub = sinon | ||
.stub(ContainerDetector, 'readFileAsync' as any) | ||
.resolves(correctCgroupV1Data); | ||
|
||
const resource: Resource = await containerDetector.detect(); | ||
|
||
sinon.assert.calledOnce(readStub); | ||
|
||
assert.ok(resource); | ||
assertContainerResource(resource, { | ||
id: 'bcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklm', | ||
}); | ||
}); | ||
|
||
it('should return a resource with container ID with a valid container ID present for v2', async () => { | ||
readStub = sinon.stub(ContainerDetector, 'readFileAsync' as any); | ||
|
||
readStub.onFirstCall().resolves(''); | ||
readStub.onSecondCall().resolves(correctCgroupV2Data); | ||
|
||
const resource: Resource = await containerDetector.detect(); | ||
sinon.assert.calledTwice(readStub); | ||
|
||
assert.ok(resource); | ||
assertContainerResource(resource, { | ||
id: 'tmhdefghijklmnopqrstuvwxyzafgrefghiugkmnopqrstuvwxyzabcdefghijkl', | ||
}); | ||
}); | ||
|
||
it('should return a empty resource with failed hostname check for v2', async () => { | ||
readStub = sinon.stub(ContainerDetector, 'readFileAsync' as any); | ||
|
||
readStub.onFirstCall().resolves(''); | ||
readStub.onSecondCall().resolves(wrongCgroupV2Data); | ||
|
||
const resource: Resource = await containerDetector.detect(); | ||
sinon.assert.calledTwice(readStub); | ||
|
||
assert.ok(resource); | ||
}); | ||
|
||
it('should return a resource without attribute container.id when cgroup file does not contain valid Container ID', async () => { | ||
readStub = sinon | ||
.stub(ContainerDetector, 'readFileAsync' as any) | ||
.resolves(''); | ||
|
||
const resource: Resource = await containerDetector.detect(); | ||
assert.deepStrictEqual(resource.attributes, {}); | ||
|
||
sinon.assert.calledTwice(readStub); | ||
assert.ok(resource); | ||
}); | ||
|
||
it('should return an empty resource when containerId is not valid', async () => { | ||
const errorMsg = { | ||
fileNotFoundError: new Error('cannot find file in path'), | ||
}; | ||
|
||
readStub = sinon | ||
.stub(ContainerDetector, 'readFileAsync' as any) | ||
.rejects(errorMsg.fileNotFoundError); | ||
|
||
const resource: Resource = await containerDetector.detect(); | ||
|
||
sinon.assert.calledOnce(readStub); | ||
assertEmptyResource(resource); | ||
}); | ||
|
||
//cgroup v2 and containerd test | ||
|
||
it('should return an empty resource when containerId is not valid', async () => { | ||
const errorMsg = { | ||
fileNotFoundError: new Error('cannot find file in path'), | ||
}; | ||
|
||
readStub = sinon | ||
.stub(ContainerDetector, 'readFileAsync' as any) | ||
.rejects(errorMsg.fileNotFoundError); | ||
|
||
const resource: Resource = await containerDetector.detect(); | ||
sinon.assert.calledOnce(readStub); | ||
assertEmptyResource(resource); | ||
}); | ||
}); | ||
}); |
File renamed without changes.
Oops, something went wrong.