|
| 1 | +# Copyright 2022-2024 The Ramble Authors |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 4 | +# https://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 5 | +# <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your |
| 6 | +# option. This file may not be copied, modified, or distributed |
| 7 | +# except according to those terms. |
| 8 | + |
| 9 | +from ramble.modkit import * # noqa: F403 |
| 10 | +from ramble.util.shell_utils import last_pid_var |
| 11 | + |
| 12 | + |
| 13 | +class GcpCloudLogging(BasicModifier): |
| 14 | + """Upload experiment logs to Google Cloud Platform Cloud Logging. |
| 15 | +
|
| 16 | + https://cloud.google.com/logging?e=48754805&hl=en |
| 17 | + """ |
| 18 | + |
| 19 | + name = "gcp-cloud-logging" |
| 20 | + |
| 21 | + tags("info") |
| 22 | + |
| 23 | + maintainers("douglasjacobsen") |
| 24 | + |
| 25 | + mode("standard", description="Standard execution mode") |
| 26 | + |
| 27 | + default_mode("standard") |
| 28 | + |
| 29 | + target_shells("bash") |
| 30 | + |
| 31 | + modifier_variable( |
| 32 | + "cloud_logging_tag", |
| 33 | + default="{experiment_namespace}", |
| 34 | + description="Tag to prefix cloud logging entries with", |
| 35 | + modes=["standard"], |
| 36 | + ) |
| 37 | + |
| 38 | + register_builtin( |
| 39 | + "start_cloud_logger", required=True, injection_method="prepend" |
| 40 | + ) |
| 41 | + |
| 42 | + def start_cloud_logger(self): |
| 43 | + shell = ramble.config.get("config:shell") |
| 44 | + last_pid_str = last_pid_var(shell) |
| 45 | + return [ |
| 46 | + "tail -f {log_file} | logger -t {cloud_logging_tag} &", |
| 47 | + f"export LOGGER_PID={last_pid_str}", |
| 48 | + ] |
| 49 | + |
| 50 | + register_builtin( |
| 51 | + "kill_cloud_logger", required=True, injection_method="append" |
| 52 | + ) |
| 53 | + |
| 54 | + def kill_cloud_logger(self): |
| 55 | + return ["kill -9 $LOGGER_PID"] |
0 commit comments