forked from Azure/azure-sdk-for-js
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Azure Monitor] OpenTelemetry Exporter Add support for Kubernetes res…
…ource attributes (Azure#26104) Use Kubernetes resource attributes when present, to support AKS customers
- Loading branch information
1 parent
4dae449
commit 365c3f9
Showing
3 changed files
with
172 additions
and
15 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
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
100 changes: 100 additions & 0 deletions
100
sdk/monitor/monitor-opentelemetry-exporter/test/internal/commonUtils.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,100 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
import os from "os"; | ||
import * as assert from "assert"; | ||
import { Resource } from "@opentelemetry/resources"; | ||
import { Tags } from "../../src/types"; | ||
import { createTagsFromResource } from "../../src/utils/common"; | ||
|
||
describe("commonUtils.ts", () => { | ||
describe("#createTagsFromResource", () => { | ||
it("default values", () => { | ||
let resource: Resource = Resource.EMPTY; | ||
const tags: Tags = createTagsFromResource(resource); | ||
assert.strictEqual(tags["ai.cloud.role"], ""); | ||
assert.strictEqual(tags["ai.cloud.roleInstance"], os.hostname()); | ||
assert.strictEqual(tags["ai.user.id"], undefined); | ||
}); | ||
|
||
it("should create Tags using custom Service attributes", () => { | ||
let resource = new Resource({ | ||
"service.name": "testServiceName", | ||
"service.namespace": "testServiceNamespace", | ||
"service.instance.id": "testServiceInstanceId", | ||
"k8s.deployment.name": "testK8sDeployment", | ||
"k8s.replicaset.name": "testK8sReplicaset", | ||
"k8s.statefulset.name": "testK8sStatefulSet", | ||
"k8s.job.name": "testK8sJob", | ||
"k8s.cronjob.name": "testK8sCronJob", | ||
"k8s.daemonset.name": "testK8sDaemonset", | ||
"k8s.pod.name": "testK8sPod", | ||
}); | ||
let tags: Tags = createTagsFromResource(resource); | ||
assert.strictEqual(tags["ai.cloud.role"], "testServiceNamespace.testServiceName"); | ||
assert.strictEqual(tags["ai.cloud.roleInstance"], "testK8sPod"); | ||
|
||
resource = new Resource({ | ||
"service.name": "testServiceName", | ||
}); | ||
tags = createTagsFromResource(resource); | ||
assert.strictEqual(tags["ai.cloud.role"], "testServiceName"); | ||
}); | ||
|
||
it("should create Tags using Kubernetes attributes if available", () => { | ||
let resource = new Resource({ | ||
"k8s.deployment.name": "testK8sDeployment", | ||
"k8s.replicaset.name": "testK8sReplicaset", | ||
"k8s.statefulset.name": "testK8sStatefulSet", | ||
"k8s.job.name": "testK8sJob", | ||
"k8s.cronjob.name": "testK8sCronJob", | ||
"k8s.daemonset.name": "testK8sDaemonset", | ||
"k8s.pod.name": "testK8sPod", | ||
}); | ||
let tags: Tags = createTagsFromResource(resource); | ||
assert.strictEqual(tags["ai.cloud.role"], "testK8sDeployment"); | ||
assert.strictEqual(tags["ai.cloud.roleInstance"], "testK8sPod"); | ||
|
||
resource = new Resource({ | ||
"k8s.replicaset.name": "testK8sReplicaset", | ||
"k8s.statefulset.name": "testK8sStatefulSet", | ||
"k8s.job.name": "testK8sJob", | ||
"k8s.cronjob.name": "testK8sCronJob", | ||
"k8s.daemonset.name": "testK8sDaemonset", | ||
}); | ||
tags = createTagsFromResource(resource); | ||
assert.strictEqual(tags["ai.cloud.role"], "testK8sReplicaset"); | ||
resource = new Resource({ | ||
"k8s.statefulset.name": "testK8sStatefulSet", | ||
"k8s.job.name": "testK8sJob", | ||
"k8s.cronjob.name": "testK8sCronJob", | ||
"k8s.daemonset.name": "testK8sDaemonset", | ||
}); | ||
tags = createTagsFromResource(resource); | ||
assert.strictEqual(tags["ai.cloud.role"], "testK8sStatefulSet"); | ||
resource = new Resource({ | ||
"k8s.job.name": "testK8sJob", | ||
"k8s.cronjob.name": "testK8sCronJob", | ||
"k8s.daemonset.name": "testK8sDaemonset", | ||
}); | ||
tags = createTagsFromResource(resource); | ||
assert.strictEqual(tags["ai.cloud.role"], "testK8sJob"); | ||
resource = new Resource({ | ||
"k8s.cronjob.name": "testK8sCronJob", | ||
"k8s.daemonset.name": "testK8sDaemonset", | ||
}); | ||
tags = createTagsFromResource(resource); | ||
assert.strictEqual(tags["ai.cloud.role"], "testK8sCronJob"); | ||
resource = new Resource({ | ||
"k8s.daemonset.name": "testK8sDaemonset", | ||
}); | ||
tags = createTagsFromResource(resource); | ||
assert.strictEqual(tags["ai.cloud.role"], "testK8sDaemonset"); | ||
}); | ||
|
||
it("should create Tags using default Resource", () => { | ||
let resource = Resource.default(); | ||
let tags: Tags = createTagsFromResource(resource); | ||
assert.ok(tags["ai.cloud.role"].startsWith("unknown_service"), "wrong ai.cloud.role"); | ||
}); | ||
}); | ||
}); |