Skip to content

Commit

Permalink
Print monitor/processor configuration in debug
Browse files Browse the repository at this point in the history
To get some potentially helpful information on how the running
configuration is configured.

Signed-off-by: Nicolas Bock <[email protected]>
  • Loading branch information
nicolasbock committed Sep 26, 2023
1 parent a1fbb3d commit 60bfe4d
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 26 deletions.
10 changes: 10 additions & 0 deletions athena-monitor.yaml
Original file line number Diff line number Diff line change
@@ -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
66 changes: 66 additions & 0 deletions athena-processor.yaml
Original file line number Diff line number Diff line change
@@ -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
13 changes: 10 additions & 3 deletions cmd/monitor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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 {
Expand Down
12 changes: 9 additions & 3 deletions cmd/processor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 (
Expand All @@ -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 {
Expand Down
32 changes: 12 additions & 20 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -71,4 +63,4 @@ services:

networks:
athena:
driver: bridge
driver: bridge
13 changes: 13 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 60bfe4d

Please sign in to comment.