Skip to content

Commit

Permalink
chore(node): Remove legacy mercury.dfinity.systems logging targets (#…
Browse files Browse the repository at this point in the history
…2740)

NODE-1538

The mainnet does not push logs, and *.mercury.dfinity.systems machines
have been decommissioned over a year ago. We pull logs from the mainnet
machines, using vector and a [log-fetcher source/adapter that DRE team
wrote](https://github.com/dfinity/dre/tree/main/rs/log-fetcher). So it's
really worth removing these URLs from the codebase since they only cause
spam entries in the system logs.

This PR also updates update-config.service to *no longer* use
filebeat.conf as an input to update the config. Instead, it sets Logging
to the default to empty values. After we switch to [USE the new
config](https://dfinity.atlassian.net/browse/NODE-1477), the [filebeat
exec condition will
fail](https://github.com/dfinity/ic/blob/d7249e0cf1981b0727d2657182046edaefa8c0b5/ic-os/components/monitoring/filebeat/filebeat.service#L22),
and filebeat will not do any work.

---------

Co-authored-by: Andrew Battat <[email protected]>
  • Loading branch information
sasa-tomic and andrewbattat authored Dec 6, 2024
1 parent 0f35ac8 commit f42fe63
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ function read_variables() {
function assemble_config_media() {
cmd=(/opt/ic/bin/build-bootstrap-config-image.sh ${MEDIA})
cmd+=(--nns_public_key "/boot/config/nns_public_key.pem")
cmd+=(--elasticsearch_hosts "$(/opt/ic/bin/fetch-property.sh --key=.logging.hosts --metric=hostos_logging_hosts --config=${DEPLOYMENT})")
cmd+=(--ipv6_address "$(/opt/ic/bin/hostos_tool generate-ipv6-address --node-type GuestOS)")
cmd+=(--ipv6_gateway "${ipv6_gateway}")
if [[ -n "$ipv4_address" && -n "$ipv4_prefix_length" && -n "$ipv4_gateway" && -n "$domain" ]]; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ function read_variables() {
function assemble_config_media() {
cmd=(/opt/ic/bin/build-bootstrap-config-image.sh ${MEDIA})
cmd+=(--nns_public_key "/boot/config/nns_public_key.pem")
cmd+=(--elasticsearch_hosts "$(/opt/ic/bin/fetch-property.sh --key=.logging.hosts --metric=hostos_logging_hosts --config=${DEPLOYMENT})")
cmd+=(--ipv6_address "$(/opt/ic/bin/hostos_tool generate-ipv6-address --node-type GuestOS)")
cmd+=(--ipv6_gateway "${ipv6_gateway}")
if [[ -n "$ipv4_address" && -n "$ipv4_prefix_length" && -n "$ipv4_gateway" && -n "$domain" ]]; then
Expand Down
2 changes: 1 addition & 1 deletion ic-os/setupos/data/deployment.json.template
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"mgmt_mac": null
},
"logging": {
"hosts": "elasticsearch-node-0.mercury.dfinity.systems:443 elasticsearch-node-1.mercury.dfinity.systems:443 elasticsearch-node-2.mercury.dfinity.systems:443 elasticsearch-node-3.mercury.dfinity.systems:443"
"hosts": ""
},
"nns": {
"url": "NNS_URL"
Expand Down
39 changes: 39 additions & 0 deletions rs/ic_os/config/src/deployment_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,41 @@ mod test {
}
});

const DEPLOYMENT_STR_NO_LOGGING_HOSTS: &str = r#"{
"deployment": {
"name": "mainnet",
"mgmt_mac": null
},
"logging": {
"hosts": ""
},
"nns": {
"url": "https://wiki.internetcomputer.org/"
},
"resources": {
"memory": "490",
"cpu": "kvm"
}
}"#;

static DEPLOYMENT_STRUCT_NO_LOGGING_HOSTS: Lazy<DeploymentSettings> =
Lazy::new(|| DeploymentSettings {
deployment: Deployment {
name: "mainnet".to_string(),
mgmt_mac: None,
},
logging: Logging {
hosts: Default::default(),
},
nns: Nns {
url: vec![Url::parse("https://wiki.internetcomputer.org").unwrap()],
},
resources: Resources {
memory: 490,
cpu: Some("kvm".to_string()),
},
});

#[test]
fn deserialize_deployment() {
let parsed_deployment = { serde_json::from_str(DEPLOYMENT_STR).unwrap() };
Expand Down Expand Up @@ -358,6 +393,10 @@ mod test {
let parsed_deployment = { serde_json::from_value(DEPLOYMENT_VALUE.clone()).unwrap() };

assert_eq!(*DEPLOYMENT_STRUCT, parsed_deployment);

let parsed_deployment = { serde_json::from_str(DEPLOYMENT_STR_NO_LOGGING_HOSTS).unwrap() };

assert_eq!(*DEPLOYMENT_STRUCT_NO_LOGGING_HOSTS, parsed_deployment);
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion rs/ic_os/config/src/generate_testnet_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ fn create_guestos_config(config: GenerateTestnetConfigArgs) -> Result<GuestOSCon
let deployment_environment = deployment_environment.unwrap_or(DeploymentEnvironment::Testnet);

let logging = Logging {
elasticsearch_hosts: elasticsearch_hosts.unwrap_or_else(|| "".to_string()),
elasticsearch_hosts,
elasticsearch_tags,
};

Expand Down
19 changes: 3 additions & 16 deletions rs/ic_os/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,12 @@ mod tests {
ipv4_config: None,
domain_name: None,
};
let logging = Logging {
elasticsearch_hosts: [
"elasticsearch-node-0.mercury.dfinity.systems:443",
"elasticsearch-node-1.mercury.dfinity.systems:443",
"elasticsearch-node-2.mercury.dfinity.systems:443",
"elasticsearch-node-3.mercury.dfinity.systems:443",
]
.join(" "),
elasticsearch_tags: None,
};
let icos_dev_settings = ICOSDevSettings::default();
let icos_settings = ICOSSettings {
node_reward_type: Some("type3.1".to_string()),
mgmt_mac: "ec:2a:72:31:a2:0c".parse().unwrap(),
deployment_environment: DeploymentEnvironment::Mainnet,
logging,
logging: Logging::default(),
use_nns_public_key: true,
nns_urls: vec!["http://localhost".parse().unwrap()],
use_node_operator_private_key: true,
Expand Down Expand Up @@ -162,7 +152,7 @@ mod tests {
"mgmt_mac": "EC:2A:72:31:A2:0C",
"deployment_environment": "Mainnet",
"logging": {
"elasticsearch_hosts": "elasticsearch-node-0.mercury.dfinity.systems:443 elasticsearch-node-1.mercury.dfinity.systems:443",
"elasticsearch_hosts": "elasticsearch.ch1-obsdev1.dfinity.network:443",
"elasticsearch_tags": "tag1 tag2"
},
"use_nns_public_key": true,
Expand Down Expand Up @@ -221,10 +211,7 @@ mod tests {
"node_reward_type": "type3.1",
"mgmt_mac": "EC:2A:72:31:A2:0C",
"deployment_environment": "Mainnet",
"logging": {
"elasticsearch_hosts": "elasticsearch-node-0.mercury.dfinity.systems:443 elasticsearch-node-1.mercury.dfinity.systems:443",
"elasticsearch_tags": "tag1 tag2"
},
"logging": {},
"use_nns_public_key": true,
"nns_urls": [
"http://localhost"
Expand Down
7 changes: 1 addition & 6 deletions rs/ic_os/config/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,6 @@ pub fn main() -> Result<()> {
// get deployment.json variables
let deployment_json_settings = get_deployment_settings(&deployment_json_path)?;

let logging = Logging {
elasticsearch_hosts: deployment_json_settings.logging.hosts.to_string(),
elasticsearch_tags: None,
};

let mgmt_mac = resolve_mgmt_mac(deployment_json_settings.deployment.mgmt_mac)?;

let node_reward_type = node_reward_type.expect("Node reward type is required.");
Expand All @@ -228,7 +223,7 @@ pub fn main() -> Result<()> {
node_reward_type: Some(node_reward_type),
mgmt_mac,
deployment_environment: deployment_json_settings.deployment.name.parse()?,
logging,
logging: Logging::default(),
use_nns_public_key,
nns_urls: deployment_json_settings.nns.url.clone(),
use_node_operator_private_key,
Expand Down
77 changes: 2 additions & 75 deletions rs/ic_os/config/src/update_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ pub fn update_guestos_config() -> Result<()> {
let network_settings = network_config_result.network_settings;
let hostname = network_config_result.hostname.clone();

let logging = read_filebeat_conf(config_dir)?;
let nns_urls = read_nns_conf(config_dir)?;

let use_nns_public_key = state_root.join("nns_public_key.pem").exists();
Expand All @@ -49,7 +48,7 @@ pub fn update_guestos_config() -> Result<()> {
node_reward_type: None,
mgmt_mac,
deployment_environment,
logging,
logging: Logging::default(),
use_nns_public_key,
nns_urls,
use_node_operator_private_key,
Expand Down Expand Up @@ -144,36 +143,6 @@ struct NetworkConfigResult {
hostname: Option<String>,
}

fn read_filebeat_conf(config_dir: &Path) -> Result<Logging> {
let filebeat_conf_path = config_dir.join("filebeat.conf");
let conf_map = match read_conf_file(&filebeat_conf_path) {
Ok(map) => map,
Err(_) => {
// Set default values if filebeat.conf doesn't exist
return Ok(Logging {
elasticsearch_hosts: "elasticsearch-node-0.mercury.dfinity.systems:443 \
elasticsearch-node-1.mercury.dfinity.systems:443 \
elasticsearch-node-2.mercury.dfinity.systems:443 \
elasticsearch-node-3.mercury.dfinity.systems:443"
.to_string(),
elasticsearch_tags: None,
});
}
};

let elasticsearch_hosts = conf_map
.get("elasticsearch_hosts")
.cloned()
.unwrap_or_default();

let elasticsearch_tags = conf_map.get("elasticsearch_tags").cloned();

Ok(Logging {
elasticsearch_hosts,
elasticsearch_tags,
})
}

fn read_nns_conf(config_dir: &Path) -> Result<Vec<Url>> {
let nns_conf_path = config_dir.join("nns.conf");
let conf_map = match read_conf_file(&nns_conf_path) {
Expand Down Expand Up @@ -318,11 +287,6 @@ pub fn update_hostos_config(

let deployment_json_settings = get_deployment_settings(deployment_json_path)?;

let logging = Logging {
elasticsearch_hosts: deployment_json_settings.logging.hosts.to_string(),
elasticsearch_tags: None,
};

let mgmt_mac = resolve_mgmt_mac(deployment_json_settings.deployment.mgmt_mac)?;

let use_nns_public_key = Path::new("/boot/config/nns_public_key.pem").exists();
Expand All @@ -334,7 +298,7 @@ pub fn update_hostos_config(
node_reward_type,
mgmt_mac,
deployment_environment: deployment_json_settings.deployment.name.parse()?,
logging,
logging: Logging::default(),
use_nns_public_key,
nns_urls: deployment_json_settings.nns.url.clone(),
use_node_operator_private_key,
Expand Down Expand Up @@ -463,43 +427,6 @@ mod tests {
Ok(())
}

#[test]
fn test_read_filebeat_conf_existing_file() -> Result<()> {
let dir = tempdir()?;
let filebeat_conf_path = dir.path().join("filebeat.conf");
let mut file = fs::File::create(&filebeat_conf_path)?;
writeln!(file, "elasticsearch_hosts=host1:9200,host2:9200")?;
writeln!(file, "elasticsearch_tags=tag1,tag2")?;

let logging = read_filebeat_conf(dir.path())?;

assert_eq!(
logging.elasticsearch_hosts,
"host1:9200,host2:9200".to_string()
);
assert_eq!(logging.elasticsearch_tags, Some("tag1,tag2".to_string()));

Ok(())
}

#[test]
fn test_read_filebeat_conf_missing_file() -> Result<()> {
let dir = tempdir()?;
let logging = read_filebeat_conf(dir.path())?;

assert_eq!(
logging.elasticsearch_hosts,
"elasticsearch-node-0.mercury.dfinity.systems:443 \
elasticsearch-node-1.mercury.dfinity.systems:443 \
elasticsearch-node-2.mercury.dfinity.systems:443 \
elasticsearch-node-3.mercury.dfinity.systems:443"
.to_string()
);
assert_eq!(logging.elasticsearch_tags, None);

Ok(())
}

#[test]
fn test_read_nns_conf_existing_file() -> Result<()> {
let dir = tempdir()?;
Expand Down
9 changes: 3 additions & 6 deletions rs/ic_os/config_types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ impl FromStr for DeploymentEnvironment {
}
}

#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone, Default)]
pub struct Logging {
/// Space-separated lists of hosts to ship logs to.
pub elasticsearch_hosts: String,
pub elasticsearch_hosts: Option<String>,
/// Space-separated list of tags to apply to exported log records.
pub elasticsearch_tags: Option<String>,
}
Expand Down Expand Up @@ -250,10 +250,7 @@ mod tests {
node_reward_type: Some(String::new()),
mgmt_mac: "00:00:00:00:00:00".parse()?,
deployment_environment: DeploymentEnvironment::Testnet,
logging: Logging {
elasticsearch_hosts: String::new(),
elasticsearch_tags: None,
},
logging: Logging::default(),
use_nns_public_key: false,
nns_urls: vec![],
use_node_operator_private_key: false,
Expand Down

0 comments on commit f42fe63

Please sign in to comment.