about summary refs log tree commit diff
path: root/src/main.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2019-02-04T14·48+0100
committerVincent Ambo <github@tazj.in>2019-02-04T15·31+0100
commit6d2a8adacc223f9eb7c607b5b0408fd5e8a60e7f (patch)
treed7fc002d8bf82ec5ee742cfea6bf1c642eba1426 /src/main.rs
parent9fed0bdb45962b5b54541c2563ae84f5a2d8ebdb (diff)
feat: Add best-effort support for non-GCP Error Reporting
This adds support for a special log stream name called "global", which
instead of setting that as a log stream changes the resource
descriptor to be of the `global` monitored resource descriptor.

According to the information we have in #4 logs submitted to that
resource descriptor should be compatible with Stackdriver Error
Reporting. This is relevant when running journaldriver outside of GCP
as there is no way to utilise Error Reporting with the log stream
resource.

This relates to #4. I'm unsure about saying whether or not it "fixes"
it.
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index 03b57517cc28..a57bb3505ddc 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -160,9 +160,24 @@ fn get_project_id() -> String {
 /// the metadata server.
 ///
 /// On non-GCP machines the value is determined by using the
-/// `GOOGLE_CLOUD_PROJECT` and `LOG_NAME` environment variables.
+/// `GOOGLE_CLOUD_PROJECT` and `LOG_STREAM` environment variables.
+///
+/// [issue #4]: https://github.com/tazjin/journaldriver/issues/4
 fn determine_monitored_resource() -> Value {
     if let Ok(log) = env::var("LOG_STREAM") {
+        // The special value `global` is recognised as a log stream name that
+        // results in a `global`-type resource descriptor. This is useful in
+        // cases where Stackdriver Error Reporting is intended to be used on
+        // a non-GCE instance. See [issue #4][] for details.
+        if log == "global" {
+            return json!({
+                "type": "global",
+                "labels": {
+                    "project_id": PROJECT_ID.as_str(),
+                }
+            });
+        }
+
         json!({
             "type": "logging_log",
             "labels": {