-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a modifier for GCP cloud logging
This commit adds a modifier which will upload logs into Google Cloud Platform's Cloud Logging.
- Loading branch information
1 parent
cd68996
commit c2a3eb7
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
var/ramble/repos/builtin/modifiers/gcp-cloud-logging/modifier.py
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,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"] |