-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Stats collection. #2447
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package collector | ||
|
||
import ( | ||
"bytes" | ||
"encoding/base64" | ||
"encoding/json" | ||
"net" | ||
"net/http" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/containous/traefik/cmd/traefik/anonymize" | ||
"github.com/containous/traefik/configuration" | ||
"github.com/containous/traefik/log" | ||
"github.com/containous/traefik/version" | ||
"github.com/mitchellh/hashstructure" | ||
) | ||
|
||
// collectorURL URL where the stats are send | ||
const collectorURL = "https://collect.traefik.io/619df80498b60f985d766ce62f912b7c" | ||
|
||
// Collected data | ||
type data struct { | ||
Version string | ||
Codename string | ||
BuildDate string | ||
Configuration string | ||
Hash string | ||
} | ||
|
||
// Collect anonymous data. | ||
func Collect(globalConfiguration *configuration.GlobalConfiguration) error { | ||
anonConfig, err := anonymize.Do(globalConfiguration, false) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
log.Infof("Anonymous stats sent to %s: %s", collectorURL, anonConfig) | ||
|
||
hashConf, err := hashstructure.Hash(globalConfiguration, nil) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
data := &data{ | ||
Version: version.Version, | ||
Codename: version.Codename, | ||
BuildDate: version.BuildDate, | ||
Hash: strconv.FormatUint(hashConf, 10), | ||
Configuration: base64.StdEncoding.EncodeToString([]byte(anonConfig)), | ||
} | ||
|
||
buf := new(bytes.Buffer) | ||
err = json.NewEncoder(buf).Encode(data) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = makeHTTPClient().Post(collectorURL, "application/json; charset=utf-8", buf) | ||
return err | ||
} | ||
|
||
func makeHTTPClient() *http.Client { | ||
dialer := &net.Dialer{ | ||
Timeout: configuration.DefaultDialTimeout, | ||
KeepAlive: 30 * time.Second, | ||
DualStack: true, | ||
} | ||
|
||
transport := &http.Transport{ | ||
Proxy: http.ProxyFromEnvironment, | ||
DialContext: dialer.DialContext, | ||
IdleConnTimeout: 90 * time.Second, | ||
TLSHandshakeTimeout: 10 * time.Second, | ||
ExpectContinueTimeout: 1 * time.Second, | ||
} | ||
|
||
return &http.Client{Transport: transport} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -628,3 +628,122 @@ traefik healthcheck | |
```bash | ||
OK: http://:8082/ping | ||
``` | ||
|
||
|
||
## Collected Data | ||
|
||
**This feature is disabled by default.** | ||
|
||
You can read the public proposal on this topic [here](https://github.com/containous/traefik/issues/2369). | ||
|
||
### Why ? | ||
|
||
In order to help us learn more about how Træfik is being used and improve it, we collect anonymous usage statistics from running instances. | ||
Those data help us prioritize our developments and focus on what's more important (for example, which configuration backend is used and which is not used). | ||
|
||
### What ? | ||
|
||
Once a day (the first call begins 10 minutes after the start of Træfik), we collect: | ||
- the Træfik version | ||
- a hash of the configuration | ||
- an **anonymous version** of the static configuration: | ||
- token, user name, password, URL, IP, domain, email, etc, are removed | ||
|
||
!!! note | ||
We do not collect the dynamic configuration (frontends & backends). | ||
|
||
!!! note | ||
We do not collect data behind the scenes to run advertising programs or to sell such data to third-party. | ||
|
||
#### Here is an example | ||
|
||
- Source configuration: | ||
|
||
```toml | ||
[entryPoints] | ||
[entryPoints.http] | ||
address = ":80" | ||
|
||
[web] | ||
address = ":8080" | ||
|
||
[Docker] | ||
endpoint = "tcp://10.10.10.10:2375" | ||
domain = "foo.bir" | ||
exposedByDefault = true | ||
swarmMode = true | ||
|
||
[Docker.TLS] | ||
CA = "dockerCA" | ||
Cert = "dockerCert" | ||
Key = "dockerKey" | ||
InsecureSkipVerify = true | ||
|
||
[ECS] | ||
Domain = "foo.bar" | ||
ExposedByDefault = true | ||
Clusters = ["foo-bar"] | ||
Region = "us-west-2" | ||
AccessKeyID = "AccessKeyID" | ||
SecretAccessKey = "SecretAccessKey" | ||
``` | ||
|
||
- Obfuscated and anonymous configuration: | ||
|
||
```toml | ||
[entryPoints] | ||
[entryPoints.http] | ||
address = ":80" | ||
|
||
[web] | ||
address = ":8080" | ||
|
||
[Docker] | ||
Endpoint = "xxxx" | ||
Domain = "xxxx" | ||
ExposedByDefault = true | ||
SwarmMode = true | ||
|
||
[Docker.TLS] | ||
CA = "xxxx" | ||
Cert = "xxxx" | ||
Key = "xxxx" | ||
InsecureSkipVerify = false | ||
|
||
[ECS] | ||
Domain = "xxxx" | ||
ExposedByDefault = true | ||
Clusters = [] | ||
Region = "us-west-2" | ||
AccessKeyID = "xxxx" | ||
SecretAccessKey = "xxxx" | ||
``` | ||
|
||
### Show me the code ! | ||
|
||
If you want to dig into more details, here is the source code of the collecting system: [collector.go](https://github.com/containous/traefik/blob/master/collector/collector.go) | ||
|
||
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/configuration#GlobalConfiguration). | ||
|
||
### How to enable this ? | ||
|
||
You can enable the collecting system by: | ||
|
||
- adding this line in the configuration TOML file: | ||
|
||
```toml | ||
# Send anonymous usage data | ||
# | ||
# Optional | ||
# Default: false | ||
# | ||
sendAnonymousUsage = true | ||
``` | ||
|
||
- adding this flag in the CLI: | ||
|
||
```bash | ||
./traefik --sendAnonymousUsage=true | ||
``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 why
anonymize
is undercmd/traefik
package ?There was a problem hiding this comment.
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 thatanonimize
?)There was a problem hiding this comment.
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.