Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit 1af625b

Browse files
author
Bogdan Drutu
authored
Add documentation about detecting monitored resource. (#94)
* Add documentation about detecting monitored resource. * Add details about optional fields in GKE. * Add link to DownwardAPI. * Fix k8s sample code.
1 parent dc6f3ee commit 1af625b

1 file changed

Lines changed: 83 additions & 0 deletions

File tree

utils/MonitoredResource.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Monitored Resource
2+
3+
This document is about the monitored resource, what resources are supported and how to automatically
4+
detect these resources.
5+
6+
## Supported Monitored Resources
7+
8+
* GCP_GCE_INSTANCE
9+
* gcp_account: The GCP account number for the instance.
10+
* instance_id: The numeric VM instance identifier assigned by GCE.
11+
* zone: The GCE zone in which the VM is running.
12+
* GCP_GKE_CONTAINER
13+
* gcp_account: The GCP account number for the instance.
14+
* cluster_name: The name for the cluster the container is running in.
15+
* namespace_id: The identifier for the cluster namespace the container is running in.
16+
* instance_id: The identifier for the GCE instance the container is running in.
17+
* pod_id: The identifier for the pod the container is running in.
18+
* container_name: The name of the container.
19+
* zone: The zone for the instance.
20+
* AWS_EC2_INSTANCE
21+
* aws_account: The AWS account number for the instance.
22+
* instance_id: The VM instance identifier assigned by AWS.
23+
* region: The AWS region for the cluster.
24+
25+
## How to automatically detect the Monitored Resource
26+
27+
The resources types and properties are detected using some Metadata services or environment
28+
variables:
29+
* AWS Metadata Service documentation is [here][AWSMetadata].
30+
* GCP Metadata Service documentation is [here][GCPMetadata].
31+
32+
Before implementing any util library that talks to any metadata service look for already
33+
implemented libraries, e.g. [see this][GCPMetadataJavaExmple] for Java GCP metadata service support.
34+
35+
36+
### GCP_GKE_CONTAINER
37+
38+
If the environment variable `KUBERNETES_SERVICE_HOST` is set.
39+
40+
| Property Name | Environment Variable | Metadata Request |
41+
|----------------|----------------------|----------------------------------|
42+
| gcp_account | | project/project-id |
43+
| cluster_name | | instance/attributes/cluster-name |
44+
| namespace_id | NAMESPACE | |
45+
| instance_id | | instance/id |
46+
| pod_id | HOSTNAME | |
47+
| container_name | CONTAINER_NAME | |
48+
| zone | | instance/zone |
49+
50+
The namespace_id and container_name are optional. We cannot get their value from environment
51+
variables unless k8s users expose them via the [Downward API][DownwardAPI]. See k8s
52+
[documentation][K8SDocumentation] and [code sample][K8SCodeSample].
53+
54+
### GCP_GCE_INSTANCE
55+
56+
If the GCP metadata service returns a value for "instance/id" and not GCP_GKE_CONTAINER.
57+
58+
| Property Name | Environment Variable | Metadata Request |
59+
|----------------|----------------------|--------------------|
60+
| gcp_account | | project/project-id |
61+
| instance_id | | instance/id |
62+
| zone | | instance/zone |
63+
64+
### AWS_EC2_INSTANCE
65+
66+
If the AWS metadata service returns a value for "instance_id".
67+
68+
| Property Name | Environment Variable | Metadata Request |
69+
|----------------|----------------------|----------------------------|
70+
| aws_account | | instance-identity/document |
71+
| instance_id | | instance_id |
72+
| region | | instance-identity/document |
73+
74+
The value return by the `instance-identity/document` metadata request is a document described
75+
[here][AWSMetadataIdentityDocument].
76+
77+
[AWSMetadata]: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html#instancedata-data-retrieval
78+
[AWSMetadataIdentityDocument]: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-identity-documents.html
79+
[DownwardAPI]: https://kubernetes.io/docs/tasks/inject-data-application/downward-api-volume-expose-pod-information/
80+
[GCPMetadata]: https://cloud.google.com/compute/docs/storing-retrieving-metadata
81+
[GCPMetadataJavaExmple]: https://github.com/GoogleCloudPlatform/google-cloud-java/blob/master/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java
82+
[K8SDocumentation]: https://cloud.google.com/kubernetes-engine/docs/tutorials/custom-metrics-autoscaling#exporting_metrics_from_the_application
83+
[K8SCodeSample]: https://github.com/GoogleCloudPlatform/kubernetes-engine-samples/blob/master/custom-metrics-autoscaling/direct-to-sd/sd_dummy_exporter.go

0 commit comments

Comments
 (0)