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

Add InfluxDB support for traefik metrics #2289

Merged
merged 3 commits into from
Nov 8, 2017
Merged

Conversation

adityacs
Copy link
Contributor

Add InfluxDB support for traefik metrics

This PR adds support for pushing traefik metrics to InfluxDB.

@adityacs
Copy link
Contributor Author

Hi,

Kindly requesting you guys to do a quick review before I cleanup the code and rebase.

Thanks :)


import (
"time"
"bytes"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bad indent, you should go fmt

influxdb "github.com/influxdata/influxdb/client/v2"
)

var influxClient = influx.New(map[string]string{}, influxdb.BatchPointsConfig{}, kitlog.LoggerFunc(func(keyvals ...interface{}) error {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why kitlog? traefik use logrus

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is dependent on go-kit/metrics/. Even other metrics related code uses the same
https://github.com/containous/traefik/blob/master/metrics/datadog.go#L9

@adityacs adityacs force-pushed the master branch 2 times, most recently from bf7906b to 2bdbd68 Compare October 22, 2017 09:09
@ldez
Copy link
Contributor

ldez commented Oct 22, 2017

@adityacs could you run the tests locally?

  • unit tests: make test-unit
  • integration tests: make test-integration
  • all tests: make test

https://github.com/containous/traefik/blob/master/CONTRIBUTING.md#tests

@adityacs
Copy link
Contributor Author

@ldez I have added the unit tests and the code is working fine. Could you please review and approve this?

@adityacs
Copy link
Contributor Author

adityacs commented Nov 1, 2017

@bclermont @nmengin @ldez Kindly review this PR.

@ldez
Copy link
Contributor

ldez commented Nov 1, 2017

Copy link
Member

@mmatur mmatur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution.
Few comments

kitlog "github.com/go-kit/kit/log"
"github.com/go-kit/kit/metrics/influx"
influxdb "github.com/influxdata/influxdb/client/v2"
"time"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you sort imports?


import (
"fmt"
"github.com/containous/traefik/types"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you sort imports?


return &standardRegistry{
enabled: true,
reqsCounter: influxClient.NewCounter(ddMetricsReqsName),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please create specifics const for Influx instead of using DataDog const ?

const (
	influxMetricsReqsName    = "traefik.requests.total"
	influxMetricsLatencyName = "traefik.request.duration"
	influxRetriesTotalName   = "traefik.backend.retries.total"
)


type fn func()

func getMessage(t *testing.T, body fn) string {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see that you have duplicated some code from go-udp-testing. We are not able to accept your PR like that.
You have opened an issue on go-udp-testing. Could you try do open a PR please ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adityacs adityacs force-pushed the master branch 2 times, most recently from 221fadf to a9afcfb Compare November 4, 2017 17:33
@adityacs
Copy link
Contributor Author

adityacs commented Nov 4, 2017

@mmatur Changes has been made.

Copy link
Contributor

@ldez ldez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

glide.lock Outdated
@@ -95,6 +95,8 @@ imports:
- name: github.com/coreos/etcd
version: c400d05d0aa73e21e431c16145e558d624098018
subpackages:
- Godeps/_workspace/src/github.com/ugorji/go/codec
- Godeps/_workspace/src/golang.org/x/net/context
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you remove those lines?

defer StopInflux()

if !influxRegistry.IsEnabled() {
t.Errorf("InfluxRegistry should return true for IsEnabled()")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

t.Errorf -> t.Fatalf

And replace InfluxRegistry should return true for IsEnabled() by Influx registry must be enabled

}

expected := []string{
// We are only validating counts, as it is nearly impossible to validate latency, since it varies every run
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move the comment above?


}

func extractAndMatchMessage(t *testing.T, expected []string, msg string) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you rename, change the signature and use t?

func assertMessage(t *testing.T, msg string, patterns []string) {
    t.Helper()
    for _, pattern := range patterns {
        re := regexp.MustCompile(pattern)
        match := re.FindStringSubmatch(msg)
        if len(match) != 2 {
            t.Errorf("Got %q %v, want %q", msg, match, pattern)
        }
    }
}

Please don't take over code from others: https://github.com/go-kit/kit/blob/e2b298466b32c7cd5579a9b9b07e968fc9d9452c/metrics/influx/example_test.go#L98

func initInfluxTicker(config *types.Influx) *time.Ticker {
address := config.Address
if len(address) == 0 {
address = "localhost:8089"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

http port default is 8086. We are creating a udp communication here. https://docs.influxdata.com/influxdb/v1.2/administration/config/#udp


report := time.NewTicker(pushInterval)

var buf bytes.Buffer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain why this line is not in the go routine?

return nil
}))

type bufWriter struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain why you created bufWriter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can call it with different name to avoid naming confusion

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes please

@adityacs
Copy link
Contributor Author

adityacs commented Nov 4, 2017

@ldez Could you please validate the changes?

Copy link
Member

@emilevauge emilevauge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adityacs @ldez @mmatur thanks a lot for your hard work :)
Could you add Influx in the readme and in the index of the documentation ?
Other than than, looks good :)

Copy link
Member

@mmatur mmatur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👏

Copy link
Contributor

@ldez ldez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mmatur mmatur added this to the 1.5 milestone Nov 8, 2017
Copy link
Member

@emilevauge emilevauge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot!
LGTM

@adityacs
Copy link
Contributor Author

adityacs commented Nov 8, 2017

@ldez @mmatur @emilevauge @bclermont Thanks a lot 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants