Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CCXDEV-10821] Adding glitchtip configuration to aggregator cleaner #341

Merged
merged 2 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions cleaner.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,17 @@ package main

import (
"bufio"
"database/sql"
"errors"
"flag"
"fmt"
"github.com/RedHatInsights/insights-operator-utils/logger"
"github.com/google/uuid"
"github.com/olekukonko/tablewriter"
"github.com/rs/zerolog/log"
"os"
"strconv"
"strings"

"database/sql"

"github.com/google/uuid"

"github.com/rs/zerolog"
"github.com/rs/zerolog/log"

"github.com/olekukonko/tablewriter"
)

// Messages
Expand Down Expand Up @@ -393,6 +389,7 @@ func doSelectedOperation(configuration *ConfigStruct, connection *sql.DB, cliFla
}

func main() {

// command line flags
var cliFlags CliFlags

Expand All @@ -419,24 +416,25 @@ func main() {
if err != nil {
log.Err(err).Msg("Load configuration")
}

err = CheckConfiguration(&config)
if err != nil {
log.Err(err).Msg("Check configuration")
return
}

if config.Logging.Debug {
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
err = logger.InitZerolog(
GetLoggingConfiguration(&config),
logger.CloudWatchConfiguration{},
GetSentryConfiguration(&config),
logger.KafkaZerologConfiguration{},
)
if err != nil {
panic(err)
}

log.Debug().Msg("Started")

// override default value read from configuration file
if cliFlags.MaxAge != "" {
config.Cleaner.MaxAge = cliFlags.MaxAge
}

// initialize connection to database
connection, err := initDatabaseConnection(&config.Storage)
if err != nil {
Expand All @@ -447,11 +445,13 @@ func main() {
exitStatus, err := doSelectedOperation(&config, connection, cliFlags)
if err != nil {
log.Err(err).Msg("Operation failed")
logger.CloseZerolog()
os.Exit(exitStatus)
return
}

// finito

log.Debug().Msg("Finished")
logger.CloseZerolog()
os.Exit(ExitStatusOK)
}
3 changes: 2 additions & 1 deletion cleaner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"time"

"github.com/DATA-DOG/go-sqlmock"
"github.com/RedHatInsights/insights-operator-utils/logger"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -84,7 +85,7 @@ func TestShowConfiguration(t *testing.T) {
PGHost: "baz",
PGDBName: "aggregator",
PGParams: ""}
configuration.Logging = main.LoggingConfiguration{
configuration.Logging = logger.LoggingConfiguration{
Debug: true,
LogLevel: ""}
configuration.Cleaner = main.CleanerConfiguration{
Expand Down
40 changes: 12 additions & 28 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,12 @@ import (
"bytes"
"fmt"
"os"
"path/filepath"
"strings"

"github.com/BurntSushi/toml"
"github.com/RedHatInsights/insights-operator-utils/logger"
clowder "github.com/redhatinsights/app-common-go/pkg/api/v1"

"path/filepath"

"github.com/rs/zerolog/log"
"github.com/spf13/viper"
)
Expand All @@ -91,29 +90,10 @@ const (

// ConfigStruct is a structure holding the whole service configuration
type ConfigStruct struct {
Storage StorageConfiguration `mapstructure:"storage" toml:"storage"`
Logging LoggingConfiguration `mapstructure:"logging" toml:"logging"`
Cleaner CleanerConfiguration `mapstructure:"cleaner" toml:"cleaner"`
}

// LoggingConfiguration represents configuration for logging in general
type LoggingConfiguration struct {
// Debug enables pretty colored logging
Debug bool `mapstructure:"debug" toml:"debug"`

// LogLevel sets logging level to show. Possible values are:
// "debug"
// "info"
// "warn", "warning"
// "error"
// "fatal"
//
// logging level won't be changed if value is not one of listed above
LogLevel string `mapstructure:"log_level" toml:"log_level"`

// LoggingToCloudWatchEnabled enables logging to CloudWatch
// (configuration for CloudWatch is in CloudWatchConfiguration)
LoggingToCloudWatchEnabled bool `mapstructure:"logging_to_cloud_watch_enabled" toml:"logging_to_cloud_watch_enabled"`
Storage StorageConfiguration `mapstructure:"storage" toml:"storage"`
Logging logger.LoggingConfiguration `mapstructure:"logging" toml:"logging"`
Cleaner CleanerConfiguration `mapstructure:"cleaner" toml:"cleaner"`
Sentry logger.SentryLoggingConfiguration `mapstructure:"sentry" toml:"sentry"`
}

// CleanerConfiguration represents configuration for the main cleaner
Expand Down Expand Up @@ -209,7 +189,6 @@ func LoadConfiguration(configFileEnvVariableName, defaultConfigFile string) (Con
fmt.Println("Error loading clowder configuration")
return config, err
}

return config, err
}

Expand All @@ -219,10 +198,15 @@ func GetStorageConfiguration(config *ConfigStruct) StorageConfiguration {
}

// GetLoggingConfiguration function returns logging configuration
func GetLoggingConfiguration(config *ConfigStruct) LoggingConfiguration {
func GetLoggingConfiguration(config *ConfigStruct) logger.LoggingConfiguration {
return config.Logging
}

// GetSentryConfiguration function returns sentry configuration
func GetSentryConfiguration(config *ConfigStruct) logger.SentryLoggingConfiguration {
return config.Sentry
}

// GetCleanerConfiguration returns cleaner configuration
func GetCleanerConfiguration(config *ConfigStruct) CleanerConfiguration {
return config.Cleaner
Expand Down
5 changes: 5 additions & 0 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ schema = "ocp_recommendations"
[logging]
debug = true
log_level = ""
logging_to_sentry_enabled = false

[cleaner]
max_age = "90 days"
cluster_list_file = "cluster_list.txt"

[sentry]
dsn = ""
environment = "dev"
12 changes: 12 additions & 0 deletions deploy/clowdapp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ objects:
value: "${LOG_LEVEL}"
- name: INSIGHTS_RESULTS_CLEANER__CLEANER__MAX_AGE
value: "${MAX_AGE}"
- name: INSIGHTS_RESULTS_CLEANER__LOGGING__LOGGING_TO_SENTRY_ENABLED
value: ${SENTRY_ENABLED}
- name: INSIGHTS_RESULTS_CLEANER__SENTRY__DSN
valueFrom:
secretKeyRef:
key: dsn
name: insights-results-aggregator-cleaner-dsn
optional: true
- name: INSIGHTS_RESULTS_CLEANER__SENTRY__ENVIRONMENT
value: ${ENV_NAME}
command:
- ./insights-results-aggregator-cleaner
- -dry-run=${DRY_RUN}
Expand Down Expand Up @@ -105,3 +115,5 @@ parameters:
- name: CLEANUP_ALL
description: If true (default), the program will be executed with the -cleanup-all argument, cleaning the database from old clusters
value: "true"
- name: SENTRY_ENABLED
value: "false"
23 changes: 23 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,51 @@ require (
)

require (
github.com/RedHatInsights/cloudwatch v0.0.0-20210111105023-1df2bdfe3291 // indirect
github.com/RedHatInsights/insights-results-types v1.23.4 // indirect
github.com/RedHatInsights/kafka-zerolog v1.0.0 // indirect
github.com/Shopify/sarama v1.27.1 // indirect
github.com/archdx/zerolog-sentry v1.8.4 // indirect
github.com/aws/aws-sdk-go v1.55.5 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bitly/go-simplejson v0.5.0 // indirect
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
github.com/buger/jsonparser v1.1.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/eapache/go-resiliency v1.2.0 // indirect
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21 // indirect
github.com/eapache/queue v1.1.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/getkin/kin-openapi v0.22.1 // indirect
github.com/getsentry/sentry-go v0.24.1 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/gorilla/mux v1.8.1 // indirect
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect
github.com/hashicorp/go-uuid v1.0.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/jcmturner/gofork v1.0.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/klauspost/compress v1.17.2 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mozillazg/request v0.8.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/pierrec/lz4 v2.5.2+incompatible // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.19.1 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.48.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/segmentio/kafka-go v0.4.10 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
Expand All @@ -53,13 +71,18 @@ require (
github.com/verdverm/frisby v0.0.0-20170604211311-b16556248a9a // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/h2non/gock.v1 v1.1.2 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/jcmturner/aescts.v1 v1.0.1 // indirect
gopkg.in/jcmturner/dnsutils.v1 v1.0.1 // indirect
gopkg.in/jcmturner/gokrb5.v7 v7.5.0 // indirect
gopkg.in/jcmturner/rpc.v1 v1.1.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading
Loading