Skip to content

Commit

Permalink
refactor: adjust log of background service task
Browse files Browse the repository at this point in the history
  • Loading branch information
vicanso committed Dec 24, 2024
1 parent 7dbe176 commit 918afd3
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/acme/lets_encrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ async fn do_update_certificates(
Err(e) => error!(
error = e.to_string(),
domains = domains.join(","),
"renew certificate fail, renew it again later"
"renew certificate fail, it will be run again later"
),
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/certificate/validity_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::proxy::get_certificate_info_list;
use crate::service::SimpleServiceTaskFuture;
use crate::util;
use crate::webhook;
use tracing::warn;
use tracing::error;

// Verify the validity period of tls certificate,
// include not after and not before.
Expand Down Expand Up @@ -61,7 +61,7 @@ async fn do_validity_check(count: u32) -> Result<bool, String> {
let time_offset = 7 * 24 * 3600_i64;
if let Err(message) = validity_check(&certificate_info_list, time_offset) {
// certificate will be expired
warn!(category = "validityChecker", message);
error!(category = "validityChecker", message);
webhook::send_notification(webhook::SendNotificationParams {
level: webhook::NotificationLevel::Warn,
category: webhook::NotificationCategory::TlsValidity,
Expand Down
13 changes: 11 additions & 2 deletions src/service/auto_restart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use super::LOG_CATEGORY;
use crate::config::{
get_config_storage, get_current_config, load_config, set_current_config,
LoadConfigOptions, PingapConf, CATEGORY_CERTIFICATE, CATEGORY_LOCATION,
Expand Down Expand Up @@ -359,6 +360,8 @@ pub fn new_observer_service(
}
}

static OBSERVER_NAME: &str = "configObserver";

#[async_trait]
impl BackgroundService for ConfigObserverService {
async fn start(&self, mut shutdown: ShutdownWatch) {
Expand All @@ -368,7 +371,8 @@ impl BackgroundService for ConfigObserverService {
let period_human: humantime::Duration = self.interval.into();

info!(
name = "Config observer",
category = LOG_CATEGORY,
name = OBSERVER_NAME,
interval = period_human.to_string(),
"background service is running",
);
Expand Down Expand Up @@ -414,7 +418,12 @@ impl BackgroundService for ConfigObserverService {

async fn run_diff_and_update_config(hot_reload_only: bool) {
if let Err(e) = diff_and_update_config(hot_reload_only).await {
error!(error = e.to_string(), "auto restart validate fail");
error!(
category = LOG_CATEGORY,
error = e.to_string(),
name = OBSERVER_NAME,
"update config fail",
)
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ use async_trait::async_trait;
use futures::future::BoxFuture;
use pingora::server::ShutdownWatch;
use pingora::services::background::BackgroundService;
use std::{
sync::atomic::{AtomicU32, Ordering},
time::{Duration, SystemTime},
};
use std::sync::atomic::{AtomicU32, Ordering};
use std::time::{Duration, SystemTime};
use tokio::time::interval;
use tracing::{error, info};

Expand Down
2 changes: 1 addition & 1 deletion src/state/prom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,6 @@ mod tests {
},
);
let buf = p.metrics().unwrap();
assert_eq!(221, std::str::from_utf8(&buf).unwrap().split('\n').count());
assert_eq!(225, std::str::from_utf8(&buf).unwrap().split('\n').count());
}
}

0 comments on commit 918afd3

Please sign in to comment.