Skip to content

Commit

Permalink
Prometheus client test refactor
Browse files Browse the repository at this point in the history
closes #318
  • Loading branch information
sparrc committed Oct 28, 2015
1 parent 4449f7f commit d2fb065
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ changed to just run docker commands in the Makefile. See `make docker-run` and

### Features
- [#325](https://github.com/influxdb/telegraf/pull/325): NSQ output. Thanks @jrxFive!
- [#318](https://github.com/influxdb/telegraf/pull/318): Prometheus output. Thanks @oldmantaiter!

### Bugfixes

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ found by running `telegraf -sample-config`.
* amqp (rabbitmq)
* mqtt
* librato
* prometheus

## Contributing

Expand Down
14 changes: 7 additions & 7 deletions outputs/prometheus_client/prometheus_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package prometheus_client

import (
"fmt"
"net/http"

"github.com/influxdb/influxdb/client/v2"
"github.com/influxdb/telegraf/outputs"
"github.com/prometheus/client_golang/prometheus"
"net/http"
)

type PrometheusClient struct {
Listen string
server *http.Server
metrics map[string]*prometheus.UntypedVec
}

Expand All @@ -21,16 +21,16 @@ var sampleConfig = `

func (p *PrometheusClient) Start() error {
if p.Listen == "" {
p.Listen = ":9126"
p.Listen = "localhost:9126"
}

http.Handle("/metrics", prometheus.Handler())
server := &http.Server{
Addr: p.Listen,
Handler: prometheus.Handler(),
Addr: p.Listen,
}
p.server = server

p.metrics = make(map[string]*prometheus.UntypedVec)
go p.server.ListenAndServe()
go server.ListenAndServe()
return nil
}

Expand Down
26 changes: 12 additions & 14 deletions outputs/prometheus_client/prometheus_client_test.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
package prometheus_client

import (
"testing"

"github.com/influxdb/influxdb/client/v2"
"github.com/influxdb/telegraf/plugins/prometheus"
"github.com/influxdb/telegraf/testutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"testing"
)

var pTesting *PrometheusClient = &PrometheusClient{}

func TestPrometheusStart(t *testing.T) {
require.NoError(t, pTesting.Start())
}
var pTesting *PrometheusClient

func TestPrometheusWritePointEmptyTag(t *testing.T) {
if testing.Short() {
t.Skip("Skipping integration test in short mode")
}

p := &prometheus.Prometheus{
Urls: []string{"http://" + testutil.GetLocalHost() + ":9126/metrics"},
Urls: []string{"http://localhost:9126/metrics"},
}
tags := make(map[string]string)
var points = []*client.Point{
Expand Down Expand Up @@ -53,11 +48,9 @@ func TestPrometheusWritePointEmptyTag(t *testing.T) {
}

func TestPrometheusWritePointTag(t *testing.T) {
if testing.Short() {
t.Skip("Skipping integration test in short mode")
}

p := &prometheus.Prometheus{
Urls: []string{"http://" + testutil.GetLocalHost() + ":9126/metrics"},
Urls: []string{"http://localhost:9126/metrics"},
}
tags := make(map[string]string)
tags["testtag"] = "testvalue"
Expand Down Expand Up @@ -88,3 +81,8 @@ func TestPrometheusWritePointTag(t *testing.T) {
assert.True(t, acc.CheckTaggedValue(e.name, e.value, tags))
}
}

func init() {
pTesting = &PrometheusClient{Listen: "localhost:9126"}
pTesting.Start()
}

0 comments on commit d2fb065

Please sign in to comment.