public void Gke_WithData(bool withPodName) { var kubernetesData = new GkePlatformDetails.KubernetesData { PodName = withPodName ? "platformintegrationtest-1135066300-rpzm4" : null, NamespaceJson = LoadResourceString("Namespace.json"), PodJson = LoadResourceString("Pod.json"), MountInfo = new[] { "1591 1575 8:1 /var/lib/kubelet/pods/de3bf4eb-b036-11e7-8e33-42010a9a0fdd/containers/platformintegrationtest/7672e8ec " + "/dev/termination-log rw,relatime - ext4 /dev/sda1 rw,commit=30,data=ordered" } }; var gke = GkePlatformDetails.TryLoad(LoadResourceString("Metadata.json"), kubernetesData); Assert.NotNull(gke); Assert.Equal("chrisbacon-testing", gke.ProjectId); Assert.Equal("platformintegrationtest", gke.ClusterName); Assert.Equal("europe-west2-c", gke.Location); Assert.Equal("platformintegrationtest-1135066300-rpzm4", gke.HostName); Assert.Equal("2917200381659545756", gke.InstanceId); Assert.Equal("projects/233772281425/zones/europe-west2-c", gke.Zone); Assert.Equal("default", gke.NamespaceId); Assert.Equal("platformintegrationtest-1135066300-rpzm4", gke.PodId); Assert.Equal("platformintegrationtest", gke.ContainerName); }
public void GkePlatform() { const string metadataJson = @" { 'project': { 'projectId': 'FakeProjectId' }, 'instance': { 'attributes': { 'cluster-name': 'FakeClusterName', }, 'id': '123', 'zone': 'projects/FakeProject/zones/FakeLocation' } } "; const string namespaceJson = @" { 'kind': 'Namespace', 'metadata': { 'uid': 'namespaceid', 'name':'namespacename' } } "; const string podJson = @" { 'kind': 'Pod', 'metadata': { 'name': 'podname', 'uid': 'podid' } } "; var kubernetesData = new GkePlatformDetails.KubernetesData { NamespaceJson = namespaceJson, PodJson = podJson, MountInfo = new[] { "/var/lib/kubelet/pods/podid/containers/containername/ /dev/termination-log" } }; var platform = new Platform(GkePlatformDetails.TryLoad(metadataJson, kubernetesData)); var resource = MonitoredResourceBuilder.FromPlatform(platform); Assert.Equal("container", resource.Type); Assert.Equal(new Dictionary <string, string> { { "project_id", "FakeProjectId" }, { "cluster_name", "FakeClusterName" }, // Although the name of the label is namespace_id, the actual value returned and expected // by Stackdriver is the namespace name. { "namespace_id", "namespacename" }, { "instance_id", "123" }, // Although the name of the label is pod_id, the actual value returned and expected // by Stackdriver is the pod name. { "pod_id", "podname" }, { "container_name", "containername" }, { "zone", "FakeLocation" } }, resource.Labels); }
public void GkePlatform() { const string metadataJson = @" { 'project': { 'projectId': 'FakeProjectId' }, 'instance': { 'attributes': { 'cluster-name': 'FakeClusterName', 'cluster-location': 'FakeClusterLocation' }, 'id': '123', 'zone': 'projects/FakeProject/zones/FakeLocation' } } "; const string namespaceJson = @" { 'kind': 'Namespace', 'metadata': { 'uid': 'namespaceid', 'name':'namespacename' } } "; const string podJson = @" { 'kind': 'Pod', 'metadata': { 'name': 'podname', 'uid': 'podid' } } "; var kubernetesData = new GkePlatformDetails.KubernetesData { NamespaceJson = namespaceJson, PodJson = podJson, MountInfo = new[] { "1 2 3 /var/lib/kubelet/pods/podid/containers/containername/ /dev/termination-log xyz" } }; var platform = new Platform(GkePlatformDetails.TryLoad(metadataJson, kubernetesData)); var resource = MonitoredResourceBuilder.FromPlatform(platform); Assert.Equal("k8s_container", resource.Type); Assert.Equal(new Dictionary <string, string> { { "project_id", "FakeProjectId" }, { "cluster_name", "FakeClusterName" }, { "namespace_name", "namespacename" }, { "pod_name", "podname" }, { "container_name", "containername" }, { "location", "FakeClusterLocation" } }, resource.Labels); }
public void Gke_ContainerNameFromMountInfo(bool havePodUid, string mountInfo, string expectedContainerName) { var kubernetesData = new GkePlatformDetails.KubernetesData { NamespaceJson = "", PodJson = havePodUid ? podValid : "", MountInfo = mountInfo?.Split('\n').ToArray() }; var gke = GkePlatformDetails.TryLoad(metadataValid, kubernetesData); Assert.NotNull(gke); Assert.Equal(expectedContainerName, gke.ContainerName); }
public void Gke_IncompleteData( [CombinatorialValues("", metadataIncomplete, metadataValid)] string metadataJson, [CombinatorialValues(null, "", namespaceIncomplete, namespaceWrongKind, namespaceMissingKind, namespaceValid)] string namespaceJson, [CombinatorialValues(null, "", podIncomplete, podWrongKind, podMissingKind, podValid)] string podJson, [CombinatorialValues(null, "", mountInfoMultiple, mountInfoMissing, mountInfoValid)] string mountInfo) { var kubernetesData = new GkePlatformDetails.KubernetesData { NamespaceJson = namespaceJson, PodJson = podJson, MountInfo = mountInfo?.Split('\n').Where(x => x != "").ToArray() }; var gke = GkePlatformDetails.TryLoad(metadataJson, kubernetesData); if (metadataJson != metadataValid) { Assert.Null(gke); return; } Assert.NotNull(gke); if (namespaceJson == namespaceValid) { Assert.Equal("namespacename", gke.NamespaceId); } else { Assert.Equal("", gke.NamespaceId); } if (podJson == podValid) { Assert.Equal("podname", gke.PodId); Assert.Equal("podname", gke.HostName); } else { Assert.Equal("", gke.PodId); Assert.Equal("", gke.HostName); } if (mountInfo == mountInfoValid && podJson == podValid) { Assert.Equal("containername", gke.ContainerName); } else { Assert.Equal("", gke.ContainerName); } }
public void Gke_PartialData() { var kubernetesData = new GkePlatformDetails.KubernetesData { PodName = "testpodname" }; var gke = GkePlatformDetails.TryLoad(LoadResourceString("Metadata.json"), kubernetesData); Assert.NotNull(gke); Assert.Equal("chrisbacon-testing", gke.ProjectId); Assert.Equal("platformintegrationtest", gke.ClusterName); Assert.Equal("europe-west2-c", gke.Location); Assert.Equal("testpodname", gke.HostName); Assert.Equal("2917200381659545756", gke.InstanceId); Assert.Equal("projects/233772281425/zones/europe-west2-c", gke.Zone); Assert.Equal("", gke.NamespaceId); Assert.Equal("", gke.PodId); Assert.Equal("", gke.ContainerName); }