···7788use crate::config::{AppConfig};
99use crate::docker::{self, types::*};
1010+use crate::utils;
10111112#[derive(Clone)]
1213pub struct AppStateWithContainerMap {
···43444445 // if route is to list containers we want to return a filtered list
4546 if new_url.path().contains("containers/json") {
4747+ let _list_span = span!(Level::DEBUG, "Container List").entered();
46484749 let containers = &res.json::<Vec<ContainerSummary>>().await.unwrap();
48504951 // filter all containers to only those that have values from CONTAINER_NAMES includes in their names
5052 let filtered_containers = containers.into_iter()
5151- .filter(|&con| docker::container_summary_match(con, &app_config.get_ref().container_names, &app_config.get_ref().container_labels))
5353+ .filter(|&con| {
5454+ let _list_span = span!(Level::DEBUG, "Container", id = utils::short_id(con.id.as_ref().unwrap())).entered();
5555+ docker::container_summary_match(con, &app_config.get_ref().container_names, &app_config.get_ref().container_labels)
5656+ })
5257 .collect::<Vec<&ContainerSummary>>();
53585459 let fresp = web::HttpResponse::build(res.status()).json(&filtered_containers);
···5964 // only deal with routes that are for containers like /containers/1234/{some_resource}
6065 match docker::match_container_get(new_url.path()) {
6166 // the regex pulls the container id from the route with a named capture group, avaiable as m.id
6767+6268 Some (m) => {
6969+ let short_cid = utils::short_id(&m.id); //format!("{start}...{end}", start = &m.id[..6], end = &m.id[&m.id.len() - 6..]);
7070+ let _con_span = span!(Level::DEBUG, "Container", id = short_cid).entered();
7171+ debug!("Matched container route with Id {}", &m.id);
6372 // we keep a stateful hashmap of all requested container ids and their names
6473 // see AppStateWithContainerMap
6574 let mut cm = data.container_map.lock().unwrap();
···6776 // if the map does not already include the container id-name then we try to get it with our own request to docker api
6877 // or if we encountered an error last time then try again
6978 if !cm.contains_key(&m.id) || cm.get(&m.id).unwrap().is_none() {
7070- debug!("Requested container Id not in map, trying to inspect: {}", &m.id);
7979+ debug!("Requested Id not in map, trying to inspect...");
7180 let info_res = docker::get_container_info(&forward_url.to_string(), &m.id).await;
7281 match info_res {
7382 Ok((name, labels)) => {
7483 let is_container_match = docker::match_labels_or_names(&app_config.get_ref().container_names, &app_config.get_ref().container_labels, &Vec::from([name.clone()]), &labels);
7575- debug!("Container Id {} with name '{}' {} valid", &m.id, name, is!(is_container_match; "is";"is not"));
8484+ debug!("Recording container '{}' {} valid", name, is!(is_container_match; "as";"as not"));
7685 cm.insert(m.id.clone(), Some(is_container_match));
7786 }
7887 Err(e) => {
7979- warn!("Could not inspect container {}: {e}", &m.id);
8888+ warn!("Could not inspect: {e}");
8089 if e.to_string().contains("No such container") {
8190 cm.insert(m.id.clone(), Some(false));
8291 } else {
···94103 Some(n) => {
95104 // only return if a response if requested container has a name that includes values from CONTAINER_NAMES
96105 if *n {
9797-106106+ debug!("Matched container filters");
98107 // if the route resource is specifically the Container Inspect API
99108 // then we may need to scrub Envs if SCRUB_ENVS=true
100109 if m.resource == "json" {
···114123 Ok(client_resp.streaming(res.into_stream()))
115124 }
116125 } else {
117117- debug!("Container {} does not match container filters, 404ing...", &m.id);
126126+ debug!("Does not match container filters, 404ing...");
118127 client_resp.status(StatusCode::NOT_FOUND);
119128 Ok(client_resp.json(&DockerErrorMessage { message: format!("No such container: {}", &m.id)}))
120129 }
121130 }
122131 None => {
123123- debug!("Container {} does not exist or Docker API previously returned an error, 404ing...", &m.id);
132132+ debug!("Does not exist or Docker API previously returned an error, 404ing...");
124133 client_resp.status(StatusCode::NOT_FOUND);
125134 Ok(client_resp.json(&DockerErrorMessage { message: format!("No such container: {}", &m.id)}))
126135 }
+12-4
src/utils.rs
···11use crate::config::ContainerLabels;
22+use core::num;
23use std::collections::HashMap;
34use tracing::*;
4556pub fn strings_in_strings(ref_strings: &Vec<String>, contains_strings: &Vec<String>) -> bool {
66- let matched_str = ref_strings.iter().find(|x| contains_strings.iter().any(|y| x.contains(y)));
77- if matched_str.is_some() {
88- debug!("One of '{}' found in {}", contains_strings.join(","), matched_str.unwrap());
99- }
77+ let matched_str = ref_strings.iter().find(|x| contains_strings.iter().any(|y| {
88+ let contains = x.contains(y);
99+ if contains {
1010+ debug!("'{}' found in {}", y, x);
1111+ }
1212+ contains
1313+ }));
10141115 matched_str.is_some()
1216}
···4448 }
45494650 return false
5151+}
5252+5353+pub fn short_id(s: &String) -> String {
5454+ return format!("{start}...{end}", start = &s[..6], end = &s[s.len() - 6..]);
4755}