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

fix: ContainerId not detected post version 0.2.2 #2270

Merged
merged 7 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class ContainerDetector implements Detector {
private async _getContainerId(): Promise<string | undefined> {
try {
return (
(await this._getContainerIdV1()) ?? (await this._getContainerIdV2())
(await this._getContainerIdV1()) || (await this._getContainerIdV2())
);
} catch (e) {
if (e instanceof Error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ describe('ContainerDetector', () => {
assert.ok(resource);
});

it('should return a correctCgroupV2Data resource with v1Detector returns empty string ', async () => {
readStub = sinon.stub(ContainerDetector, 'readFileAsync' as any);
sinon.stub(containerDetector, '_getContainerIdV1' as any).resolves('');
sinon
.stub(containerDetector, '_getContainerIdV2' as any)
.resolves(correctCgroupV2Data);
const containerId = await containerDetector['_getContainerId']();
assert.strictEqual(containerId, correctCgroupV2Data);
});

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)
Expand Down