Skip to content

Commit

Permalink
Add a modifier for GCP cloud logging
Browse files Browse the repository at this point in the history
This commit adds a modifier which will upload logs into Google Cloud
Platform's Cloud Logging.
  • Loading branch information
douglasjacobsen committed Nov 9, 2024
1 parent cd68996 commit c2a3eb7
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions var/ramble/repos/builtin/modifiers/gcp-cloud-logging/modifier.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Copyright 2022-2024 The Ramble Authors
#
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
# https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
# option. This file may not be copied, modified, or distributed
# except according to those terms.

from ramble.modkit import * # noqa: F403
from ramble.util.shell_utils import last_pid_var


class GcpCloudLogging(BasicModifier):
"""Upload experiment logs to Google Cloud Platform Cloud Logging.
https://cloud.google.com/logging?e=48754805&hl=en
"""

name = "gcp-cloud-logging"

tags("info")

maintainers("douglasjacobsen")

mode("standard", description="Standard execution mode")

default_mode("standard")

target_shells("bash")

modifier_variable(
"cloud_logging_tag",
default="{experiment_namespace}",
description="Tag to prefix cloud logging entries with",
modes=["standard"],
)

register_builtin(
"start_cloud_logger", required=True, injection_method="prepend"
)

def start_cloud_logger(self):
shell = ramble.config.get("config:shell")
last_pid_str = last_pid_var(shell)
return [
"tail -f {log_file} | logger -t {cloud_logging_tag} &",
f"export LOGGER_PID={last_pid_str}",
]

register_builtin(
"kill_cloud_logger", required=True, injection_method="append"
)

def kill_cloud_logger(self):
return ["kill -9 $LOGGER_PID"]

0 comments on commit c2a3eb7

Please sign in to comment.