From d3de7a5efc494f4d85038b14fa4dcae75048ce5f Mon Sep 17 00:00:00 2001 From: lts120784620 Date: Tue, 16 Jun 2020 21:06:07 +0800 Subject: [PATCH] del username and password --- README.md | 3 --- collector_test.go | 29 +++++++++++++++++++++-------- config/plugin_cfg.go | 4 ---- plugin.test.json | 2 -- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 2b2e1fe..15abb9d 100644 --- a/README.md +++ b/README.md @@ -21,11 +21,8 @@ Prometheus-collector以插件形式集成在collector中,通过Nightingale插 exporter_urls | array | Address to collect metric for prometheus exporter. append_tags | array | Add tags for n9e metric default empty endpoint | string | Field endpoint for n9e metric default empty - username | string | Not needed for now - password | string | Not needed for now ignore_metrics_prefix | array | Ignore metric prefix default empty timeout | int | Timeout for access a exporter url default 500ms ### -======= ### diff --git a/collector_test.go b/collector_test.go index a270429..c0e7c8f 100644 --- a/collector_test.go +++ b/collector_test.go @@ -10,12 +10,10 @@ import ( ) const validConfigParam = `{ - "exporter_urls":["http://127.0.0.1:9104/metrics?dns=xxip:3306"], + "exporter_urls":["http://127.0.0.1:8080/metrics"], "append_tags": ["region=bj", "dept=cloud"], "endpoint": "127.0.0.1", - "username": "xxx", - "password": "xxx", - "ignore_metrics_prefix": ["go_"], + "ignore_metrics_prefix": [], "timeout": 500 } ` @@ -75,7 +73,7 @@ func TestPromMetricParser(t *testing.T) { metrics, err := collector.Parse([]byte(validPromUntypedMetric)) assert.NoError(t, err) - assert.Len(t, metrics, 0) + assert.Len(t, metrics, 1) metrics, err = collector.Parse([]byte(validPromGaugeMetric)) assert.NoError(t, err) @@ -101,8 +99,6 @@ const validStdin = `{ ], "endpoint": "xxxx", "append_tags": ["region=bj", "dept=cloud"], - "username": "xxx", - "password": "xxx", "ignore_metrics_prefix": ["gc_","go_"], "timeout": 500 } @@ -127,6 +123,23 @@ func TestStdout(t *testing.T) { printMetrics(metrics) } +func TestGather(t *testing.T) { + err := config.Parse([]byte(validConfigParam)) + assert.NoError(t, err) + + metrics := collector.Gather() + assert.NotNil(t, metrics) + printMetrics(metrics) +} + +const validIgnoreConfigParam = `{ + "exporter_urls":["http://127.0.0.1:8080/metrics"], + "append_tags": ["region=bj", "dept=cloud"], + "endpoint": "127.0.0.1", + "ignore_metrics_prefix": ["go_"], + "timeout": 500 +} +` const validPromIgnoreMetric = `# HELP go_gc_duration_seconds A summary of the GC invocation durations. # TYPE go_gc_duration_seconds summary go_gc_duration_seconds{quantile="0"} 1.2099e-05 @@ -139,7 +152,7 @@ go_gc_duration_seconds_count 84408 ` func TestIgnoreMetric(t *testing.T) { - err := config.Parse([]byte(validConfigParam)) + err := config.Parse([]byte(validIgnoreConfigParam)) assert.NoError(t, err) config.Config.IgnoreMetricsPrefix = []string{"mem"} diff --git a/config/plugin_cfg.go b/config/plugin_cfg.go index a9df92a..ff2dcd8 100644 --- a/config/plugin_cfg.go +++ b/config/plugin_cfg.go @@ -10,8 +10,6 @@ type PluginCfg struct { ExporterUrls []string `json:"exporter_urls,omitempty"` AppendTags []string `json:"append_tags"` Endpoint string `json:"endpoint"` - Username string `json:"username"` - Password string `json:"password"` Timeout int `json:"timeout"` IgnoreMetricsPrefix []string `json:"ignore_metrics_prefix"` } @@ -30,8 +28,6 @@ func Parse(bs []byte) error { ExporterUrls: []string{}, AppendTags: []string{}, Endpoint: "", - Username: "", - Password: "", Timeout: 500, IgnoreMetricsPrefix: []string{}, } diff --git a/plugin.test.json b/plugin.test.json index 745d1ab..0dd49a8 100644 --- a/plugin.test.json +++ b/plugin.test.json @@ -4,8 +4,6 @@ ], "append_tags": ["region=bj", "dept=cloud"], "endpoint": "127.0.0.1", - "username": "", - "password": "", "ignore_metrics_prefix": ["go_"], "timeout": 500 } \ No newline at end of file