Skip to content

Commit

Permalink
Update function parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
nikodemas committed Aug 22, 2023
1 parent 3e7bfb9 commit 0d5ac2c
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions src/go/MONIT/monit.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,10 @@ type Params struct {
Verbose int
Config StompConfig
Inject bool
HDFS string
}

// builder function to get default params for stats query
func NewStatsParams(url string, token string, q string, verbose int, config StompConfig, inject bool, hdfs string) *Params {
func NewStatsParams(url string, token string, q string, verbose int, config StompConfig, inject bool) *Params {
// per our discussion with MONIT team (RQF1647972)
// we only need to use some dbid for _stats ES API, here I use
// 9573, the id of monit_prod_cms-es-size_raw_elasticsearch datasource, and 9582
Expand All @@ -96,12 +95,11 @@ func NewStatsParams(url string, token string, q string, verbose int, config Stom
Verbose: verbose,
Config: config,
Inject: inject,
HDFS: hdfs,
}
}

// builder function of params for queries
func NewParams(url string, token string, q string, dbname string, dbid int, database string, dbtype string, esapi string, hdfs string, verbose int) *Params {
func NewParams(url string, token string, q string, dbname string, dbid int, database string, dbtype string, esapi string, verbose int) *Params {
return &Params{
URL: url,
Token: token,
Expand All @@ -112,7 +110,6 @@ func NewParams(url string, token string, q string, dbname string, dbid int, data
DBType: dbtype,
ESAPI: esapi,
Verbose: verbose,
HDFS: hdfs,
}
}

Expand All @@ -124,7 +121,6 @@ func (sp *Params) PrintStatsParams() {
log.Println("query ", sp.Query)
log.Println("short_term_dbid", sp.ShortDBID)
log.Println("long_term_dbid ", sp.LongDBID)
log.Println("hdfs ", sp.HDFS)
log.Println("inject to MONIT", sp.Inject)
}

Expand All @@ -138,7 +134,6 @@ func (p *Params) PrintParams() {
log.Println("database", p.Database)
log.Println("dbtype ", p.DBType)
log.Println("esapi ", p.ESAPI)
log.Println("hdfs ", p.HDFS)
}

// helper function to either read file content or return given string
Expand Down Expand Up @@ -491,7 +486,7 @@ func queryURL(rurl string, headers [][]string, verbose int) Record {
}

// helper function to run ES/InfluxDB or MONIT query
func run(p Params) Record {
func run(p *Params) Record {
var headers [][]string
bearer := fmt.Sprintf("Bearer %s", p.Token)
h := []string{"Authorization", bearer}
Expand Down Expand Up @@ -663,12 +658,12 @@ func parseStats(data map[string]interface{}, verbose int) []Record {
// helper function to deal with stats query
func getStats(statsParams Params) {
statsParams.URL = statsParams.ShortURL
short_term_data := run(statsParams)
short_term_data := run(&statsParams)
records := parseStats(short_term_data, statsParams.Verbose)
injectRecords(statsParams.Config, records, statsParams.Verbose, statsParams.Inject)

statsParams.URL = statsParams.LongURL
long_term_data := run(statsParams)
long_term_data := run(&statsParams)
records = parseStats(long_term_data, statsParams.Verbose)
injectRecords(statsParams.Config, records, statsParams.Verbose, statsParams.Inject)
}
Expand Down Expand Up @@ -989,6 +984,9 @@ func main() {
}
var e error
// Fetch data sources from Grafana and write to file. Requires admin token.
if token == "" {
log.Fatalf("Please provide valid token")
}
if writeDataSourcesTo != "" {
DataSources, e = datasources(defaultUrl, token, verbose)
if e == nil {
Expand Down Expand Up @@ -1071,11 +1069,8 @@ func main() {
}
dbID := dbid
var database, dbtype string
if token == "" {
log.Fatalf("Please provide valid token")
}
if strings.Contains(q, "stats") {
statsParams := NewStatsParams(url, token, q, verbose, stompConfig, inject, hdfs)
statsParams := NewStatsParams(defaultUrl, t, q, verbose, stompConfig, inject)
getStats(*statsParams)
// obtain HDFS records if requested
if hdfs != "" {
Expand All @@ -1099,11 +1094,11 @@ func main() {
if dbID > 0 {
dbid = dbID
}
params := NewParams(url, t, q, dbname, dbid, database, dbtype, esapi, hdfs, verbose)
params := NewParams(url, t, q, dbname, dbid, database, dbtype, esapi, verbose)
if verbose > 0 {
params.PrintParams()
}
data := run(*params)
data := run(params)
d, e := json.Marshal(data)
if e == nil {
fmt.Println(string(d))
Expand Down

0 comments on commit 0d5ac2c

Please sign in to comment.