Skip to content

Commit

Permalink
Merge pull request #512 from cbgbt/log-level
Browse files Browse the repository at this point in the history
Allow configuration of log level via helm
  • Loading branch information
cbgbt committed Aug 9, 2023
2 parents f84705a + 8ecc119 commit 93d14fe
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 4 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ logging_formatter: "pretty"
# Whether or not to enable ANSI colors on log messages.
# Makes the output "pretty" in terminals, but may add noise to web-based log utilities.
logging_ansi_enabled: "true"
# Controls the filter for tracing/log messages.
# This can be as simple as a log-level (e.g. "info", "debug", "error"), but also supports more complex directives.
# See https://docs.rs/tracing-subscriber/0.3.17/tracing_subscriber/filter/struct.EnvFilter.html#directives
controller_tracing_filter: "info"
agent_tracing_filter: "info"
apiserver_tracing_filter: "info"
```
#### Configure API server ports
Expand Down
6 changes: 6 additions & 0 deletions deploy/charts/bottlerocket-update-operator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,10 @@ logging_formatter: "pretty"
# Whether or not to enable ANSI colors on log messages.
# Makes the output "pretty" in terminals, but may add noise to web-based log utilities.
logging_ansi_enabled: "true"
# Controls the filter for tracing/log messages.
# This can be as simple as a log-level (e.g. "info", "debug", "error"), but also supports more complex directives.
# See https://docs.rs/tracing-subscriber/0.3.17/tracing_subscriber/filter/struct.EnvFilter.html#directives
controller_tracing_filter: "info"
agent_tracing_filter: "info"
apiserver_tracing_filter: "info"
```
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ spec:
value: "{{ .Values.logging_formatter }}"
- name: LOGGING_ANSI_ENABLED
value: "{{ .Values.logging_ansi_enabled }}"
- name: TRACING_FILTER_DIRECTIVE
value: "{{ .Values.agent_tracing_filter }}"
image: {{ .Values.image }}
name: brupop
resources:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ spec:
value: "{{ .Values.logging_formatter }}"
- name: LOGGING_ANSI_ENABLED
value: "{{ .Values.logging_ansi_enabled }}"
- name: TRACING_FILTER_DIRECTIVE
value: "{{ .Values.apiserver_tracing_filter }}"
image: {{ .Values.image }}
livenessProbe:
httpGet:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ spec:
value: "{{ .Values.logging_formatter }}"
- name: LOGGING_ANSI_ENABLED
value: "{{ .Values.logging_ansi_enabled }}"
- name: TRACING_FILTER_DIRECTIVE
value: "{{ .Values.controller_tracing_filter }}"
image: {{ .Values.image }}
name: brupop
priorityClassName: brupop-controller-high-priority
Expand Down
6 changes: 6 additions & 0 deletions deploy/charts/bottlerocket-update-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,9 @@ logging_formatter: "pretty"
# Whether or not to enable ANSI colors on log messages.
# Makes the output "pretty" in terminals, but may add noise to web-based log utilities.
logging_ansi_enabled: "true"
# Controls the filter for tracing/log messages.
# This can be as simple as a log-level (e.g. "info", "debug", "error"), but also supports more complex directives.
# See https://docs.rs/tracing-subscriber/0.3.17/tracing_subscriber/filter/struct.EnvFilter.html#directives
controller_tracing_filter: "info"
agent_tracing_filter: "info"
apiserver_tracing_filter: "info"
12 changes: 8 additions & 4 deletions models/src/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ use serde::Deserialize;
use snafu::ResultExt;
use std::env;
use tracing::Subscriber;
use tracing_subscriber::{fmt, layer::SubscriberExt, EnvFilter, Registry};
use tracing_subscriber::{filter::LevelFilter, fmt, layer::SubscriberExt, EnvFilter, Registry};

const DEFAULT_TRACE_LEVEL: &str = "info";
const DEFAULT_TRACING_FILTER_DIRECTIVE: LevelFilter = LevelFilter::INFO;

const TRACING_FILTER_DIRECTIVE_ENV_VAR: &str = "TRACING_FILTER_DIRECTIVE";
const LOGGING_FORMATTER_ENV_VAR: &str = "LOGGING_FORMATTER";
const LOGGING_ANSI_ENABLED_ENV_VAR: &str = "LOGGING_ANSI_ENABLED";

Expand Down Expand Up @@ -100,8 +102,10 @@ impl MessageFormat {
pub fn init_telemetry_from_env() -> Result<()> {
opentelemetry::global::set_text_map_propagator(TraceContextPropagator::new());

let env_filter =
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new(DEFAULT_TRACE_LEVEL));
let env_filter = EnvFilter::builder()
.with_default_directive(DEFAULT_TRACING_FILTER_DIRECTIVE.into())
.with_env_var(TRACING_FILTER_DIRECTIVE_ENV_VAR)
.from_env_lossy();

let subscriber = Registry::default().with(env_filter);
let subscriber = LogFormatter::try_from_env()?.add_format_layer(subscriber);
Expand Down

0 comments on commit 93d14fe

Please sign in to comment.