Skip to content

Commit

Permalink
Merge pull request #122 from IBM/update-event-writer
Browse files Browse the repository at this point in the history
feat: merge event-writer to main
  • Loading branch information
No9 authored Dec 28, 2022
2 parents e3efed8 + 93f5a7a commit 62bbfba
Show file tree
Hide file tree
Showing 14 changed files with 776 additions and 291 deletions.
602 changes: 352 additions & 250 deletions Cargo.lock

Large diffs are not rendered by default.

13 changes: 11 additions & 2 deletions charts/core-dump-handler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ The agent pod has the following environment variables and these are all set by t
Given the amount of time compression there is an option to disable it.
* COMP_CORE_EVENTS - Enable the creation of a core event file Default: false
Generates a file in a dedicated folder to be picked up by an external process.
* COMP_CORE_EVENT_DIR - The folder where the core dump event is saved.
* CRIO_ENDPOINT - The CRIO endpoint to use.
"unix:///run/containerd/containerd.sock" (Default): This is the default for most containerd nodes
Expand Down Expand Up @@ -261,7 +267,8 @@ Composer
* ignoreCrio: Maps to the COMP_IGNORE_CRIO enviroment variable (Default false)
* crioImageCmd: Maps to the COMP_CRIO_IMAGE_CMD enviroment variable (Default "img")
* timeout: Maps to the COMP_TIMEOUT environment variable ("Default 600)
* compression: Maps to the COMP_COMPRESSION environment varable (Default "true")
* compression: Maps to the COMP_COMPRESSION environment variable (Default "true")
* coreEvents: Maps to the COMP_CORE_EVENTS envrironment variable (Default "false")
* filenameTemplate: Maps to COMP_FILENAME_TEMPLATE environment variable
(Default {{uuid}}-dump-{{timestamp}}-{{hostname}}-{{exe_name}}-{{pid}}-{{signal}})
Expand Down Expand Up @@ -292,8 +299,10 @@ Composer
Daemonset
* hostDirectory: Maps to the HOST_DIR environment variable (Default "/var/mnt/core-dump-handler")
* coreDirectory: Maps to the CORE_DIR environment variable (Default "/var/mnt/core-dump-handler/cores")
* eventDirectory: Maps to the EVENT_DIR environment variable (Default "/var/mnt/core-dump-handler/events")
* suidDumpable: Maps to the SUID_DUMPABLE environment variable (Default 2)
* vendor: Maps to the VENDOR enviroment variable (Default default)
* vendor: Maps to the VENDOR enviroment variable (Default default)
* interval: Maps to the INTERVAL enviroment variable (Default 60000)
* schedule: Maps to the SCHEDULE enviroment variable (Default "")
* useINotify: Maps to the USE_INOTIFY environment variable (Default false)
Expand Down
11 changes: 11 additions & 0 deletions charts/core-dump-handler/templates/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ spec:
- name: core-volume
mountPath: {{ .Values.daemonset.coreDirectory }}
mountPropagation: Bidirectional
{{- if .Values.composer.events }}
- name: event-volume
mountPath: {{ .Values.daemonset.eventDirectory }}
mountPropagation: Bidirectional
{{- end }}
{{- if .Values.daemonset.mountContainerRuntimeEndpoint }}
- mountPath: {{ .Values.daemonset.hostContainerRuntimeEndpoint }}
name: container-runtime
Expand All @@ -51,6 +56,10 @@ spec:
value: {{ .Values.composer.timeout | quote }}
- name: COMP_COMPRESSION
value: {{ .Values.composer.compression | quote }}
- name: COMP_CORE_EVENTS
value: {{ .Values.composer.coreEvents }}
- name: COMP_CORE_EVENT_DIR
value: {{ .Values.daemonset.eventDirectory }}
- name: DEPLOY_CRIO_CONFIG
value: {{ .Values.daemonset.deployCrioConfig | quote }}
- name: CRIO_ENDPOINT
Expand All @@ -59,6 +68,8 @@ spec:
value: {{ .Values.daemonset.hostDirectory }}
- name: CORE_DIR
value: {{ .Values.daemonset.coreDirectory }}
- name: EVENT_DIR
value: {{ .Values.daemonset.eventDirectory }}
- name: SUID_DUMPABLE
value: {{ .Values.daemonset.suidDumpable | quote }}
- name: DEPLOY_CRIO_EXE
Expand Down
20 changes: 20 additions & 0 deletions charts/core-dump-handler/templates/event-storage-pv.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{ if .Values.composer.coreEvents }}
apiVersion: v1
kind: PersistentVolume
metadata:
name: event-volume
labels:
type: local
spec:
storageClassName: {{ .Values.storageClass }}
claimRef:
name: event-storage-pvc
namespace: {{ .Release.Namespace }}
capacity:
storage: {{ .Values.eventStorage }}
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
hostPath:
path: {{ .Values.daemonset.eventDirectory }}
{{ end }}
13 changes: 13 additions & 0 deletions charts/core-dump-handler/templates/event-storage-pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{ if .Values.composer.coreEvents }}
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: event-storage-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: {{ .Values.eventStorage }}
storageClassName: {{ .Values.storageClass }}
{{ end }}
10 changes: 9 additions & 1 deletion charts/core-dump-handler/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@
},
"compression": {
"type": "boolean"
},
"coreEvents": {
"type": "boolean"
}
},
"required": [
Expand All @@ -131,7 +134,8 @@
"logLength",
"filenameTemplate",
"timeout",
"compression"
"compression",
"coreEvents"
],
"title": "Composer"
},
Expand Down Expand Up @@ -207,6 +211,9 @@
"coreDirectory": {
"type": "string"
},
"eventDirectory": {
"type": "string"
},
"suidDumpable": {
"type": "integer"
},
Expand Down Expand Up @@ -262,6 +269,7 @@
"extraEnvVars",
"hostDirectory",
"coreDirectory",
"eventDirectory",
"includeCrioExe",
"label",
"manageStoreSecret",
Expand Down
3 changes: 3 additions & 0 deletions charts/core-dump-handler/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ fullnameOverride: ""
# Size of the Persistent volume to create
hostStorage: 1Gi
coreStorage: 10Gi
eventStorage: 1Gi
storageClass: hostclass

composer:
Expand All @@ -29,12 +30,14 @@ composer:
podSelectorLabel: ""
timeout: 600
compression: true
coreEvents: false

daemonset:
name: "core-dump-handler"
label: "core-dump-ds"
hostDirectory: "/var/mnt/core-dump-handler"
coreDirectory: "/var/mnt/core-dump-handler/cores"
eventDirectory: "/var/mnt/core-dump-handler/events"
crioEndpoint: "unix:///run/containerd/containerd.sock"
mountContainerRuntimeEndpoint: false
hostContainerRuntimeEndpoint: "/run/containerd/containerd.sock"
Expand Down
2 changes: 1 addition & 1 deletion core-dump-agent/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "core-dump-agent"
version = "8.8.0"
version = "8.9.0"
authors = ["Anthony Whalley <anton@venshare.com>"]
edition = "2021"
resolver = "2"
Expand Down
13 changes: 11 additions & 2 deletions core-dump-agent/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,14 +479,23 @@ fn create_env_file(host_location: &str) -> Result<(), std::io::Error> {
let log_length = env::var("LOG_LENGTH").unwrap_or_else(|_| "500".to_string());
let pod_selector_label = env::var("COMP_POD_SELECTOR_LABEL").unwrap_or_default();
let timeout = env::var("COMP_TIMEOUT").unwrap_or_else(|_| "600".to_string());

let compression = env::var("COMP_COMPRESSION")
.unwrap_or_else(|_| "true".to_string())
.to_lowercase();

let core_events = env::var("COMP_CORE_EVENTS")
.unwrap_or_else(|_| "false".to_string())
.to_lowercase();

let event_directory = env::var("COMP_CORE_EVENT_DIR")
.unwrap_or_else(|_| format!("{}/{}", host_location, "events"))
.to_lowercase();
info!("Creating {} file with LOG_LEVEL={}", destination, loglevel);
let mut env_file = File::create(destination)?;
let text = format!(
"LOG_LEVEL={}\nIGNORE_CRIO={}\nCRIO_IMAGE_CMD={}\nUSE_CRIO_CONF={}\nFILENAME_TEMPLATE={}\nLOG_LENGTH={}\nPOD_SELECTOR_LABEL={}\nTIMEOUT={}\nCOMPRESSION={}\n",
loglevel, ignore_crio, crio_image, use_crio_config, filename_template, log_length, pod_selector_label, timeout, compression
"LOG_LEVEL={}\nIGNORE_CRIO={}\nCRIO_IMAGE_CMD={}\nUSE_CRIO_CONF={}\nFILENAME_TEMPLATE={}\nLOG_LENGTH={}\nPOD_SELECTOR_LABEL={}\nTIMEOUT={}\nCOMPRESSION={}\nCORE_EVENTS={}\nEVENT_DIRECTORY={}\n",
loglevel, ignore_crio, crio_image, use_crio_config, filename_template, log_length, pod_selector_label, timeout, compression, core_events, event_directory
);
info!("Writing composer .env \n{}", text);
env_file.write_all(text.as_bytes())?;
Expand Down
4 changes: 3 additions & 1 deletion core-dump-agent/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ fn basic() -> Result<(), std::io::Error> {
"FILENAME_TEMPLATE={uuid}-dump-{timestamp}-{hostname}-{exe_name}-{pid}-{signal}"
));
assert!(env_content.contains("LOG_LENGTH=500"));
assert_eq!(env_content.lines().count(), 9);
assert!(env_content.contains("EVENTS=false"));
assert!(env_content.contains("EVENT_DIRECTORY=/"));
assert_eq!(env_content.lines().count(), 11);
//TODO: [No9] Test uploading of a corefile
//TODO: [No9] Test remove option
//TODO: [No9] Test sweep option
Expand Down
2 changes: 1 addition & 1 deletion core-dump-composer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "core-dump-composer"
version = "8.8.0"
version = "8.9.0"
authors = ["Anthony Whalley <anton@venshare.com>"]
edition = "2021"

Expand Down
19 changes: 12 additions & 7 deletions core-dump-composer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ pub struct CoreConfig {
pub pod_selector_label: String,
pub use_crio_config: bool,
pub ignore_crio: bool,
pub core_events: bool,
pub timeout: u32,
pub compression: bool,
pub event_location: PathBuf,
pub image_command: ImageCommand,
pub bin_path: String,
pub os_hostname: String,
Expand Down Expand Up @@ -58,12 +60,6 @@ impl CoreConfig {
let directory = matches.value_of("directory").unwrap_or("").to_string();
let hostname = matches.value_of("hostname").unwrap_or("").to_string();
let pathname = matches.value_of("pathname").unwrap_or("").to_string();
// let timeout = matches
// .value_of("timeout")
// .unwrap_or("600")
// .parse::<u64>()
// .unwrap();
// let disable_compression = matches.contains_id("disable-compression");

let uuid = Uuid::new_v4();

Expand Down Expand Up @@ -119,6 +115,11 @@ impl CoreConfig {
.unwrap_or_else(|_| "600".to_string())
.parse::<u32>()
.unwrap();
let core_events = env::var("CORE_EVENTS")
.unwrap_or_else(|_| "false".to_string())
.to_lowercase()
.parse::<bool>()
.unwrap();
let os_hostname = hostname::get()
.unwrap_or_else(|_| OsString::from_str("unknown").unwrap_or_default())
.into_string()
Expand All @@ -138,7 +139,9 @@ impl CoreConfig {
ImageCommand::from_str(&image_command_string).unwrap_or(ImageCommand::Img);
let filename_template =
env::var("FILENAME_TEMPLATE").unwrap_or_else(|_| String::from(DEFAULT_TEMPLATE));

let event_location = PathBuf::from(
env::var("EVENT_DIRECTORY").unwrap_or_else(|_| format!("{}/events", base_path_str)),
);
Ok(CoreConfig {
log_level,
pod_selector_label,
Expand All @@ -154,6 +157,8 @@ impl CoreConfig {
log_length,
params,
compression,
core_events,
event_location,
timeout,
})
}
Expand Down
Loading

0 comments on commit 62bbfba

Please sign in to comment.