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

Gcp add gcr job support #1462

Merged
merged 3 commits into from
Sep 23, 2024
Merged
Changes from 1 commit
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
Next Next commit
Add support for GCR Jobs environment
psx95 committed Sep 23, 2024

Verified

This commit was signed with the committer’s verified signature.
gsmet Guillaume Smet
commit 69a65ce55527a2317f77c3a18fd2f08321f533ad
Original file line number Diff line number Diff line change
@@ -16,6 +16,8 @@
import static com.google.cloud.opentelemetry.detection.AttributeKeys.GCE_INSTANCE_ID;
import static com.google.cloud.opentelemetry.detection.AttributeKeys.GCE_INSTANCE_NAME;
import static com.google.cloud.opentelemetry.detection.AttributeKeys.GCE_MACHINE_TYPE;
import static com.google.cloud.opentelemetry.detection.AttributeKeys.GCR_JOB_EXECUTION_KEY;
import static com.google.cloud.opentelemetry.detection.AttributeKeys.GCR_JOB_TASK_INDEX;
import static com.google.cloud.opentelemetry.detection.AttributeKeys.GKE_CLUSTER_LOCATION;
import static com.google.cloud.opentelemetry.detection.AttributeKeys.GKE_CLUSTER_LOCATION_TYPE;
import static com.google.cloud.opentelemetry.detection.AttributeKeys.GKE_CLUSTER_NAME;
@@ -106,6 +108,9 @@ public Attributes getAttributes() {
case GOOGLE_CLOUD_FUNCTIONS:
addGcfAttributes(attrBuilder, detectedPlatform.getAttributes());
break;
case GOOGLE_CLOUD_RUN_JOB:
addGcrJobAttributes(attrBuilder, detectedPlatform.getAttributes());
break;
case GOOGLE_APP_ENGINE:
addGaeAttributes(attrBuilder, detectedPlatform.getAttributes());
break;
@@ -192,8 +197,8 @@ private static void addGkeAttributes(
}

/**
* Updates the attributes with the required keys for a GCR (Google Cloud Run) environment. The
* attributes are not updated in case the environment is not deemed to be GCR.
* Updates the attributes with the required keys for a GCR (Google Cloud Run) Service environment.
* The attributes are not updated in case the environment is not deemed to be GCR.
*
* @param attrBuilder The {@link AttributesBuilder} object that needs to be updated with the
* necessary keys.
@@ -217,6 +222,34 @@ private static void addGcfAttributes(
addCommonAttributesForServerlessCompute(attrBuilder, attributesMap);
}

/**
* Update the attributes with the required keys for a GCR (Google Cloud Run) Jobs environment. The
* attributes are not updated in case the environment is not deemed to be GCR jobs environment.
*
* @param attrBuilder The {@link AttributesBuilder} object that needs to be updated with the
* necessary keys.
*/
private static void addGcrJobAttributes(
AttributesBuilder attrBuilder, Map<String, String> attributesMap) {
attrBuilder.put(CLOUD_PLATFORM, GCP_CLOUD_RUN);
Optional.ofNullable(attributesMap.get(SERVERLESS_COMPUTE_NAME))
.ifPresent(name -> attrBuilder.put(FAAS_NAME, name));
Optional.ofNullable(attributesMap.get(SERVERLESS_COMPUTE_INSTANCE_ID))
.ifPresent(instanceId -> attrBuilder.put(FAAS_INSTANCE, instanceId));
Optional.ofNullable(attributesMap.get(SERVERLESS_COMPUTE_CLOUD_REGION))
.ifPresent(cloudRegion -> attrBuilder.put(CLOUD_REGION, cloudRegion));
Optional.ofNullable(attributesMap.get(GCR_JOB_EXECUTION_KEY))
.ifPresent(
jobExecutionKey ->
attrBuilder.put(IncubatingAttributes.GCP_CLOUD_RUN_JOB_EXECUTION, jobExecutionKey));
Optional.ofNullable(attributesMap.get(GCR_JOB_TASK_INDEX))
.ifPresent(
jobTaskIndex ->
attrBuilder.put(
IncubatingAttributes.GCP_CLOUD_RUN_JOB_TASK_INDEX,
Integer.parseInt(jobTaskIndex)));
}

/**
* Updates the attributes with the required keys for a GAE (Google App Engine) environment. The
* attributes are not updated in case the environment is not deemed to be GAE.
Original file line number Diff line number Diff line change
@@ -40,6 +40,11 @@ private CloudPlatformValues() {}
public static final AttributeKey<String> FAAS_NAME = AttributeKey.stringKey("faas.name");
public static final AttributeKey<String> FAAS_VERSION = AttributeKey.stringKey("faas.version");

public static final AttributeKey<String> GCP_CLOUD_RUN_JOB_EXECUTION =
AttributeKey.stringKey("gcp.cloud_run.job.execution");
public static final AttributeKey<Long> GCP_CLOUD_RUN_JOB_TASK_INDEX =
AttributeKey.longKey("gcp.cloud_run.job.task_index");

public static final AttributeKey<String> GCP_GCE_INSTANCE_HOSTNAME =
AttributeKey.stringKey("gcp.gce.instance.hostname");
public static final AttributeKey<String> GCP_GCE_INSTANCE_NAME =