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.
This commit is contained in:
Vincent Ambo 2019-02-04 15:48:53 +01:00 committed by Vincent Ambo
parent 9fed0bdb45
commit 6d2a8adacc

View file

@ -160,9 +160,24 @@ fn get_project_id() -> String {
/// the metadata server. /// the metadata server.
/// ///
/// On non-GCP machines the value is determined by using the /// 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 { fn determine_monitored_resource() -> Value {
if let Ok(log) = env::var("LOG_STREAM") { 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!({ json!({
"type": "logging_log", "type": "logging_log",
"labels": { "labels": {