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

Stats collection. #2447

Merged
merged 2 commits into from
Nov 25, 2017
Merged

Conversation

ldez
Copy link
Contributor

@ldez ldez commented Nov 22, 2017

What does this PR do?

#2369

This feature is disabled by default.

In the future, as discussed in the proposal, this may be enabled by default.

Motivation

#2369

More

  • Added/updated tests
  • Added/updated documentation

@ldez ldez added kind/enhancement a new or improved feature. status/2-needs-review labels Nov 22, 2017
@ldez ldez added this to the 1.5 milestone Nov 22, 2017
@emilevauge emilevauge mentioned this pull request Nov 22, 2017
@ldez ldez force-pushed the feature/collect-anonymous-usage branch 3 times, most recently from c1f2e4e to 6116f62 Compare November 22, 2017 10:54
Copy link
Contributor

@nmengin nmengin left a comment

Choose a reason for hiding this comment

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

LGTM 👏 👍

@ldez ldez force-pushed the feature/collect-anonymous-usage branch from 6116f62 to 8ad23d0 Compare November 22, 2017 14:17
Copy link
Member

@juliens juliens 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
Collaborator

@SantoDE SantoDE 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
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 👏

func collect(globalConfiguration *configuration.GlobalConfiguration) {
ticker := time.NewTicker(24 * time.Hour)
safe.Go(func() {
time.Sleep(10 * time.Minute)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure understand why this first call of Collect is required 👼 I guess you want the first one after 10min and then each and every day, right.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

exactly, we wait 10 min for eliminate some quick restart.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we document the delay in basics.md as well?

"strconv"
"time"

"github.com/containous/traefik/cmd/traefik/anonymize"
Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 why anonymize is under cmd/traefik package ?

Copy link
Contributor

Choose a reason for hiding this comment

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

(or why collector is in a different parent package that anonimize ?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because before this PR it was use only by traefik bug command.

I can move the package anonymize at the root of the project.

Copy link
Contributor

@dtomcej dtomcej left a comment

Choose a reason for hiding this comment

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

LGTM
:shipit:

"github.com/mitchellh/hashstructure"
)

const containousURL = "https://collect.traefik.io"
Copy link
Contributor

Choose a reason for hiding this comment

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

This is probably fine, but we might want this overridable for testing, and to allow people to post the stats to their own endpoint if they want. This would also improve public perception, as they can see EXACTLY what is being sent by posting to their own endpoint.

buf := new(bytes.Buffer)
json.NewEncoder(buf).Encode(data)

_, err = makeHTTPClient().Post(containousURL, "application/json; charset=utf-8", buf)
Copy link
Contributor

Choose a reason for hiding this comment

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

This might be a dumb question, but do we want this to retry/or log the data on failure? rather than just the error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not critical for the application, we think the retry/log response is not needed in this case.


```bash
./traefik --sendAnonymousUsage=true
```
Copy link
Contributor

Choose a reason for hiding this comment

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

Might want to note that in the future, that this will be enabled by default.

@ldez ldez force-pushed the feature/collect-anonymous-usage branch 2 times, most recently from 4ecad76 to ddcd87e Compare November 24, 2017 09:23
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 @ldez for this great PR. Few comments though ;)

BuildDate: version.BuildDate,
Hash: strconv.FormatUint(hashConf, 10),
Configuration: base64.StdEncoding.EncodeToString([]byte(anonConfig)),
EmitDate: time.Now().Format(time.RFC3339),
Copy link
Member

Choose a reason for hiding this comment

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

Is-it needed ?

}

buf := new(bytes.Buffer)
json.NewEncoder(buf).Encode(data)
Copy link
Member

Choose a reason for hiding this comment

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

error is shadowed here

docs/basics.md Outdated
Once a day, we collect:
- the Træfik version
- a hash of the configuration
- an **obfuscated and anonymous version** of the static configuration:
Copy link
Member

Choose a reason for hiding this comment

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

s/obfuscated and anonymous version/anonymous version

docs/basics.md Outdated

By default we anonymize all configuration fields, except fields tagged with `export=true`.

You can check all fields in the [godoc](https://godoc.org/github.com/containous/traefik).
Copy link
Member

Choose a reason for hiding this comment

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

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.

LGTM 👏

Copy link
Contributor

@m3co-code m3co-code left a comment

Choose a reason for hiding this comment

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

LGTM, I only left two very small nit-picks :)

docs/basics.md Outdated
- an **anonymous version** of the static configuration:
- token, user name, password, URL, IP, domain, email, etc, are removed

!!! warning
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is rather another note than a warning.

log.Debug(err)
}
for {
select {
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't really need the select case here, because <-ticker.C will block anyway.

@ldez ldez force-pushed the feature/collect-anonymous-usage branch from ba322d7 to 4e7500f Compare November 24, 2017 17:00
Copy link
Contributor

@timoreimann timoreimann left a comment

Choose a reason for hiding this comment

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

I'd call out the typo fixes as mandatory, everything else as recommended / points of discussion.

if globalConfiguration.SendAnonymousUsage {
log.Info(`
Stats collection is enabled.
Many thanks to contribute to Traefik improvement by allowing us to receive anonymous information from your configuration.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it must say (emphasis by me)

Many thanks for contributing to Traefik's improvement [...]

}

func collect(globalConfiguration *configuration.GlobalConfiguration) {
ticker := time.NewTicker(24 * time.Hour)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd make it explicit that we want a never-ending ticker (we never call ticker.Stop()) by invoking time.Tick() here.

"github.com/mitchellh/hashstructure"
)

const containousURL = "https://collect.traefik.io/619df80498b60f985d766ce62f912b7c"
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we have a more expressive name to indicate what's happening behind this URL (like collectorURL), possibly even a GoDoc?

return err
}

log.Infof("Stats sent on %s: %s", containousURL, anonConfig)
Copy link
Contributor

Choose a reason for hiding this comment

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

s/on/to/

return err
}

log.Infof("Stats sent on %s: %s", containousURL, anonConfig)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd write Anonymous stats sent to [...].

(Emphasis by me.)

func collect(globalConfiguration *configuration.GlobalConfiguration) {
ticker := time.NewTicker(24 * time.Hour)
safe.Go(func() {
time.Sleep(10 * time.Minute)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we document the delay in basics.md as well?

for range ticker.C {
err := collector.Collect(globalConfiguration)
if err != nil {
log.Debug(err)
Copy link
Contributor

@timoreimann timoreimann Nov 24, 2017

Choose a reason for hiding this comment

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

It is possible to have just one call to Collect like this (slightly adopted from here):

for time.Sleep(10 * time.Minute); ; <-ticker.C {
  if err := collector.Collect(globalConfiguration); err != nil {
    log.Debug(err)
  }
}

(Simplified Go Playground example.)

@ldez
Copy link
Contributor Author

ldez commented Nov 25, 2017

@timoreimann I have take account of all your remarks.

Copy link
Contributor

@timoreimann timoreimann left a comment

Choose a reason for hiding this comment

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

LGTM 👏

@traefiker traefiker force-pushed the feature/collect-anonymous-usage branch from f4000db to 8d13309 Compare November 25, 2017 12:22
@traefiker traefiker merged commit 0ca65f9 into traefik:master Nov 25, 2017
@ldez ldez deleted the feature/collect-anonymous-usage branch November 25, 2017 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement a new or improved feature. size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.