Skip to content
This repository has been archived by the owner on May 4, 2022. It is now read-only.

Commit

Permalink
Drop all extra command line flags (#80)
Browse files Browse the repository at this point in the history
* Drop all extra command line flags

In order to avoid having missed flags updated when the configuration structures change, and
since command line flags are not used in our deployment environments, this patch removes all
the unnecessary flags.

The flags -config, -servicetype, and -uname are left in place to support the existing Operator
configurations to avoid needing changes there. All other flags have been dropped in favour of
using the standard configuration files.

* Test both events and metrics structured configurations

* Disable AMQP1Connections test for metrics

Disable the AMQP1Connections test for metrics since it isn't implemented in
metrics.go yet.

* Re-add the check on the metrics side

Add the check for AMQP1MetricsURL back in since we can't use AMQP1Connections here yet.

* Align AMQP addresses in Golang tests
  • Loading branch information
leifmadsen authored Mar 3, 2020
1 parent 9990fd6 commit e16c555
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"AlertManagerURL": "http://localhost:9093/api/v1/alerts",
"ResetIndex": false,
"Debug": true,
"prefetch": 0,
"Prefetch": 0,
"API": {
"APIEndpointURL": "localhost:9999",
"AMQP1PublishURL": "localhost:5672/collectd/alert2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"UseSample": false,
"UseTimeStamp": true,
"Debug": true,
"prefetch": 0,
"Prefetch": 15000,
"Sample": {
"HostCount": 10,
"PluginCount": 100,
Expand Down
46 changes: 8 additions & 38 deletions internal/pkg/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,9 @@ func eventusage() {
doc := heredoc.Doc(`
For running with config file use
********************* config *********************
$go run cmd/main.go -config sa.events.config.json -debug -servicetype events
**************************************************
For running with AMQP and Prometheus use following option
********************* Production *********************
$go run cmd/main.go -servicetype events -amqp1EventURL=10.19.110.5:5672/collectd/notify -eshost=http://10.19.110.5:9200
**************************************************************
For running with AMQP ,Prometheus,API and AlertManager use following option
********************* Production *********************
$go run cmd/main.go -servicetype events -amqp1EventURL=10.19.110.5:5672/collectd/notify -eshost=http://10.19.110.5:9200 -alertmanager=http://localhost:9090/v1/api/alert -apiurl=localhost:8082 -amqppublishurl=127.0.0.1:5672/collectd/alert
**************************************************************`)
$go run cmd/main.go -config smartgateway_config.json -servicetype events
**************************************************`)

fmt.Fprintln(os.Stderr, `Required command line argument missing`)
fmt.Fprintln(os.Stdout, doc)
flag.PrintDefaults()
Expand Down Expand Up @@ -189,17 +182,9 @@ func StartEvents() {

// set flags for parsing options
flag.Usage = eventusage
fDebug := flag.Bool("debug", false, "Enable debug")
fServiceType := flag.String("servicetype", "event", "event type")
fConfigLocation := flag.String("config", "", "Path to configuration file(optional).if provided ignores all command line options")
fAMQP1EventURL := flag.String("amqp1EventURL", "", "AMQP1.0 collectd events listener example 127.0.0.1:5672/collectd/notify")
fElasticHostURL := flag.String("eshost", "", "ElasticSearch host http://localhost:9200")
fAlertManagerURL := flag.String("alertmanager", "", "(Optional)AlertManager endpoint http://localhost:9090/v1/api/alert")
fAPIEndpointURL := flag.String("apiurl", "", "(Optional)API endpoint localhost:8082")
fAMQP1PublishURL := flag.String("amqppublishurl", "", "(Optional) AMQP1.0 event publish address 127.0.0.1:5672/collectd/alert")
fResetIndex := flag.Bool("resetIndex", false, "Optional Clean all index before on start (default false)")
fPrefetch := flag.Int("prefetch", 0, "AMQP1.0 option: Enable prefetc and set capacity(0 is disabled,>0 enabled with capacity of >0) (OPTIONAL)")
fUniqueName := flag.String("uname", "metrics-"+strconv.Itoa(rand.Intn(100)), "Unique name across application")
fServiceType := flag.String("servicetype", "event", "Event type")
fConfigLocation := flag.String("config", "", "Path to configuration file.")
fUniqueName := flag.String("uname", "events-"+strconv.Itoa(rand.Intn(100)), "Unique name across application")
flag.Parse()

//load configuration from given config file or from cmdline parameters
Expand All @@ -211,24 +196,9 @@ func StartEvents() {
}
serverConfig = conf.(*saconfig.EventConfiguration)
serverConfig.ServiceType = *fServiceType
if *fDebug {
serverConfig.Debug = true
}
} else {
serverConfig = &saconfig.EventConfiguration{
AMQP1EventURL: *fAMQP1EventURL,
ElasticHostURL: *fElasticHostURL,
AlertManagerURL: *fAlertManagerURL,
Prefetch: *fPrefetch,
ServiceType: *fServiceType,
API: saconfig.EventAPIConfig{
APIEndpointURL: *fAPIEndpointURL,
AMQP1PublishURL: *fAMQP1PublishURL,
},
ResetIndex: *fResetIndex,
Debug: *fDebug,
UniqueName: *fUniqueName,
}
eventusage()
os.Exit(1)
}

if serverConfig.Debug {
Expand Down
39 changes: 6 additions & 33 deletions internal/pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,9 @@ func (c *cacheHandler) Collect(ch chan<- prometheus.Metric) {
// metricusage and command-line flags
func metricusage() {
doc := heredoc.Doc(`
For running with config file use
********************* config *********************
$go run cmd/main.go -config sa.metrics.config.json -debug -servicetype metrics
**************************************************
For running with AMQP and Prometheus use following option
********************* Production *********************
$go run cmd/main.go -servicetype metrics -mhost=localhost -mport=8081 -amqp1MetricURL=10.19.110.5:5672/collectd/telemetry
**************************************************************`)
$go run cmd/main.go -config smartgateway_config.json -servicetype metrics
**************************************************`)

fmt.Fprintln(os.Stderr, `Required commandline argument missing`)
fmt.Fprintln(os.Stdout, doc)
Expand All @@ -94,16 +89,8 @@ func metricusage() {
func StartMetrics() {
// set flags for parsing options
flag.Usage = metricusage
fDebug := flag.Bool("debug", false, "Enable debug")
fServiceType := flag.String("servicetype", "metrics", "metric type")
fConfigLocation := flag.String("config", "", "Path to configuration file(optional).if provided ignores all command line options")
fIncludeStats := flag.Bool("cpustats", false, "Include cpu usage info in http requests (degrades performance)")
fExporterhost := flag.String("mhost", "localhost", "Metrics url for Prometheus to export. ")
fExporterport := flag.Int("mport", 8081, "Metrics port for Prometheus to export (http://localhost:<port>/metrics) ")
fAMQP1MetricURL := flag.String("amqp1MetricURL", "", "AMQP1.0 metrics listener example 127.0.0.1:5672/collectd/telemetry")
fCount := flag.Int("count", -1, "Stop after receiving this many messages in total(-1 forever) (OPTIONAL)")
fPrefetch := flag.Int("prefetch", 0, "AMQP1.0 option: Enable prefetc and set capacity(0 is disabled,>0 enabled with capacity of >0) (OPTIONAL)")
fUsetimestamp := flag.Bool("usetimestamp", true, "Use source time stamp instead of promethues.(default true,OPTIONAL)")
fServiceType := flag.String("servicetype", "metrics", "Metric type")
fConfigLocation := flag.String("config", "", "Path to configuration file.")
fUniqueName := flag.String("uname", "metrics-"+strconv.Itoa(rand.Intn(100)), "Unique name across application")
flag.Parse()

Expand All @@ -115,23 +102,9 @@ func StartMetrics() {
}
serverConfig = conf.(*saconfig.MetricConfiguration)
serverConfig.ServiceType = *fServiceType
if *fDebug {
serverConfig.Debug = true
}
} else {
serverConfig = &saconfig.MetricConfiguration{
AMQP1MetricURL: *fAMQP1MetricURL,
CPUStats: *fIncludeStats,
Exporterhost: *fExporterhost,
Exporterport: *fExporterport,
DataCount: *fCount, //-1 for ever which is default
UseTimeStamp: *fUsetimestamp,
Debug: *fDebug,
Prefetch: *fPrefetch,
ServiceType: *fServiceType,
UniqueName: *fUniqueName,
}

metricusage()
os.Exit(1)
}
if serverConfig.Debug {
debugm = func(format string, data ...interface{}) { log.Printf(format, data...) }
Expand Down
31 changes: 27 additions & 4 deletions tests/internal_pkg/saconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const (
{
"AMQP1Connections": [
{"Url": "127.0.0.1:5672/collectd/notify", "DataSource": "collectd"},
{"Url": "127.0.0.1:5672/ceilometer/events", "DataSource": "ceilometer"},
{"Url": "127.0.0.1:5672/ceilometer/event.sample", "DataSource": "ceilometer"},
{"Url": "127.0.0.1:5672/universal/events", "DataSource": "universal"}
],
"AMQP1EventURL": "127.0.0.1:5672/collectd/notify",
Expand All @@ -35,7 +35,7 @@ const (
{
"AMQP1Connections": [
{"Url": "127.0.0.1:5672/collectd/telemetry", "DataSource": "collectd"},
{"Url": "127.0.0.1:5672/ceilometer/telemetry", "DataSource": "ceilometer"},
{"Url": "127.0.0.1:5672/ceilometer/metering.sample", "DataSource": "ceilometer"},
{"Url": "127.0.0.1:5672/universal/telemetry", "DataSource": "universal"}
],
"AMQP1MetricURL": "127.0.0.1:5672/collectd/telemetry",
Expand Down Expand Up @@ -158,7 +158,7 @@ func TestUnstructuredData(t *testing.T) {
}
}

func TestStructuredData(t *testing.T) {
func TestEventStructuredData(t *testing.T) {
confPath, err := GenerateTestConfig(EventsConfig)
if err != nil {
t.Fatal(err)
Expand All @@ -177,9 +177,32 @@ func TestStructuredData(t *testing.T) {
t.Run("Test structured AMQP connections", func(t *testing.T) {
connStruct := []saconfig.AMQPConnection{
saconfig.AMQPConnection{URL: "127.0.0.1:5672/collectd/notify", DataSource: "collectd", DataSourceID: 1},
saconfig.AMQPConnection{URL: "127.0.0.1:5672/ceilometer/events", DataSource: "ceilometer", DataSourceID: 2},
saconfig.AMQPConnection{URL: "127.0.0.1:5672/ceilometer/event.sample", DataSource: "ceilometer", DataSourceID: 2},
saconfig.AMQPConnection{URL: "127.0.0.1:5672/universal/events", DataSource: "universal", DataSourceID: 0},
}
assert.Equal(t, connStruct, cfg.(*saconfig.EventConfiguration).AMQP1Connections)
})
}

/* enable this after implementing []AMQP1Connections in metrics.go
func TestMetricStructuredData(t *testing.T) {
confPath, err := GenerateTestConfig(MetricsConfig)
if err != nil {
t.Fatal(err)
}
defer os.Remove(confPath)
cfg, err := saconfig.LoadConfiguration(confPath, "metric")
if err != nil {
t.Fatal(err)
}
t.Run("Test structured AMQP connections", func(t *testing.T) {
connStruct := []saconfig.AMQPConnection{
saconfig.AMQPConnection{URL: "127.0.0.1:5672/collectd/telemetry", DataSource: "collectd", DataSourceID: 1},
saconfig.AMQPConnection{URL: "127.0.0.1:5672/ceilometer/metering.sample", DataSource: "ceilometer", DataSourceID: 2},
saconfig.AMQPConnection{URL: "127.0.0.1:5672/universal/metrics", DataSource: "universal", DataSourceID: 0},
}
assert.Equal(t, connStruct, cfg.(*saconfig.MetricConfiguration).AMQP1Connections)
})
}
*/

0 comments on commit e16c555

Please sign in to comment.