From 60bfe4d4f0a6a61aa5abd65536c8a508daf739c9 Mon Sep 17 00:00:00 2001 From: Nicolas Bock Date: Tue, 26 Sep 2023 15:15:22 -0600 Subject: [PATCH] Print monitor/processor configuration in debug To get some potentially helpful information on how the running configuration is configured. Signed-off-by: Nicolas Bock --- athena-monitor.yaml | 10 +++++++ athena-processor.yaml | 66 +++++++++++++++++++++++++++++++++++++++++++ cmd/monitor/main.go | 13 +++++++-- cmd/processor/main.go | 12 ++++++-- docker-compose.yml | 32 ++++++++------------- pkg/config/config.go | 13 +++++++++ 6 files changed, 120 insertions(+), 26 deletions(-) create mode 100644 athena-monitor.yaml create mode 100644 athena-processor.yaml diff --git a/athena-monitor.yaml b/athena-monitor.yaml new file mode 100644 index 0000000..6b13a1a --- /dev/null +++ b/athena-monitor.yaml @@ -0,0 +1,10 @@ +monitor: + files-delta: 1m + poll-every: 10s + directories: + - "/uploads" + - "/uploads/sosreport" + processor-map: + - type: filename + regex: ".*sosreport.*.tar.[xz|gz]+$" + processor: sosreports diff --git a/athena-processor.yaml b/athena-processor.yaml new file mode 100644 index 0000000..b48c07c --- /dev/null +++ b/athena-processor.yaml @@ -0,0 +1,66 @@ +processor: + batch-comments-every: 5m + base-tmpdir: "/tmp/athena" + subscribers: + sosreports: + sf-comment-enabled: true + sf-comment-public: false + sf-comment: | + Athena processor: {{ processor }} subscriber: {{ subscriber }} has run the following reports. + {% for report in reports -%} + {% for script in report.Scripts -%} + {% if script.Name == "hotsos-short" %} + {% if script.Output != "" -%} + Summary for report: {{ report.Name }} - filepath: {{ report.FilePath }} + ------------------------------------------------------------------------- + {{ script.Output }} + {% endif %} + {% endif %} + {%- endfor -%} + {%- endfor -%} + {%- for report in reports -%} + {%- for script in report.Scripts -%} + {% if script.Name == "hotsos-full" -%} + Full {{ report.Name }} output can be found at: https://files.support.canonical.com/files/{{ script.UploadLocation }} + {% endif %} + {%- endfor -%} + {%- endfor -%} + + reports: + hotsos: + scripts: + hotsos-full: + exit-codes: 0 2 127 126 + run: | + #!/bin/bash + pip3 install hotsos --upgrade &>/dev/null + tar -xf {{filepath}} -C {{basedir}} &>/dev/null + hotsos -s --output-path hotsos-out --all-logs {{basedir}}/$(basename {{filepath}} .tar.xz)/ &>/dev/null + if [ -s hotsos-out/*/summary/full/yaml/hotsos-summary.all.yaml ]; then + cat hotsos-out/*/summary/full/yaml/hotsos-summary.all.yaml + else + echo "No full sosreport generated." + fi + rm -rf hotsos-out + exit 0 + hotsos-short: + exit-codes: 0 2 127 126 + run: | + #!/bin/bash + pip3 install hotsos --upgrade &>/dev/null + tar -xf {{filepath}} -C {{basedir}} &>/dev/null + hotsos -s --output-path hotsos-out --all-logs {{basedir}}/$(basename {{filepath}} .tar.xz)/ &>/dev/null + # check on size of output and use very-short if exceeds SF comment limit + if [ -s hotsos-out/*/summary/short/yaml/hotsos-summary.all.yaml ]; then + # SF comment limit is ~4K but leave some space for headers + if (($(wc -m hotsos-out/*/summary/short/yaml/hotsos-summary.all.yaml| cut -d ' ' -f 1) > 1000)); then + echo "NOTE: using --very-short since output exceeds SF comment char limit - check full summary for issue details." + cat hotsos-out/*/summary/very_short/yaml/hotsos-summary.all.yaml + else + cat hotsos-out/*/summary/short/yaml/hotsos-summary.all.yaml + fi + else + echo "No known bugs or issues found on sosreport." + fi + rm -rf hotsos-out + exit 0 diff --git a/cmd/monitor/main.go b/cmd/monitor/main.go index f38eb5a..969f14b 100644 --- a/cmd/monitor/main.go +++ b/cmd/monitor/main.go @@ -2,16 +2,19 @@ package main import ( "context" + "os" + "os/signal" + "strings" + "syscall" + "github.com/canonical/athena-core/pkg/common" "github.com/canonical/athena-core/pkg/config" "github.com/canonical/athena-core/pkg/monitor" "github.com/lileio/pubsub/v2" "github.com/lileio/pubsub/v2/providers/nats" "github.com/nats-io/stan.go" + log "github.com/sirupsen/logrus" "gopkg.in/alecthomas/kingpin.v2" - "os" - "os/signal" - "syscall" ) var ( @@ -30,6 +33,10 @@ func main() { if err != nil { panic(err) } + log.Debug("Configuration") + for _, line := range strings.Split(cfg.String(), "\n") { + log.Debug(line) + } filesClient, err := common.NewFilesComClient(cfg.FilesCom.Key, cfg.FilesCom.Endpoint) if err != nil { diff --git a/cmd/processor/main.go b/cmd/processor/main.go index 0219114..caf20b2 100644 --- a/cmd/processor/main.go +++ b/cmd/processor/main.go @@ -2,6 +2,11 @@ package main import ( "context" + "os" + "os/signal" + "strings" + "syscall" + "github.com/canonical/athena-core/pkg/common" "github.com/canonical/athena-core/pkg/config" "github.com/canonical/athena-core/pkg/processor" @@ -11,9 +16,6 @@ import ( "github.com/nats-io/stan.go" log "github.com/sirupsen/logrus" "gopkg.in/alecthomas/kingpin.v2" - "os" - "os/signal" - "syscall" ) var ( @@ -31,6 +33,10 @@ func main() { if err != nil { panic(err) } + log.Debug("Configuration") + for _, line := range strings.Split(cfg.String(), "\n") { + log.Debug(line) + } filesClient, err := common.NewFilesComClient(cfg.FilesCom.Key, cfg.FilesCom.Endpoint) if err != nil { diff --git a/docker-compose.yml b/docker-compose.yml index 3365334..2bf1136 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,20 +1,5 @@ version: "3.3" services: -# salesforce: -# container_name: salesforceapi -# image: outofcoffee/imposter-sfdc -# ports: -# - 8080:8080 -# volumes: -# - ./mocks:/opt/imposter/config -# command: --configDir /opt/imposter/config --serverUrl http://localhost:8080 -# -# filescom: -# container_name: filescomapi -# image: filescom/files-mock-server:latest -# networks: -# - athena -# restart: always db: container_name: db @@ -29,13 +14,17 @@ services: - athena ports: - "3306:3306" + restart: always athena-monitor: container_name: athena-monitor image: athena/athena-monitor-linux-amd64:main volumes: - - ./development-config.yaml:/etc/athena/main.yaml - command: /athena-monitor --log.level="debug" + - ./creds.yaml:/etc/athena/main.yaml + - ./athena-monitor.yaml:/etc/athena/monitor.yaml + - ./athena-monitor-directories.yaml:/etc/athena/monitor-directories.yaml + - /home/ubuntu/sosreports/tmp:/tmp/athena + command: /athena-monitor --config /etc/athena/main.yaml --config /etc/athena/monitor.yaml --config /etc/athena/monitor-directories.yaml --log.level="debug" depends_on: - nats-streaming - db @@ -47,8 +36,11 @@ services: container_name: athena-processor image: athena/athena-processor-linux-amd64:main volumes: - - ./development-config.yaml:/etc/athena/main.yaml - command: /athena-processor --config /etc/athena/main.yaml --log.level="debug" + - ./creds.yaml:/etc/athena/main.yaml + - ./athena-processor.yaml:/etc/athena/processor.yaml + - ./athena-processor-upload.yaml:/etc/athena/processor-upload.yaml + - /home/ubuntu/sosreports/tmp:/tmp/athena + command: /athena-processor --config /etc/athena/main.yaml --config /etc/athena/processor.yaml --config /etc/athena/processor-upload.yaml --log.level="debug" depends_on: - nats-streaming - db @@ -71,4 +63,4 @@ services: networks: athena: - driver: bridge \ No newline at end of file + driver: bridge diff --git a/pkg/config/config.go b/pkg/config/config.go index b273cee..4aa316d 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -59,6 +59,19 @@ type Config struct { } `yaml:"filescom,omitempty"` } +func (cfg *Config) String() string { + tempCfg := *cfg + // Sanitize output, i.e. remove sensitive information. + tempCfg.Salesforce.Password = "**********" + tempCfg.Salesforce.SecurityToken = "**********" + tempCfg.FilesCom.Key = "**********" + result, err := yaml.Marshal(tempCfg) + if err != nil { + return "could not marshal config" + } + return string(result) +} + func NewConfigFromFile(filePaths []string) (*Config, error) { var config Config