From bd4c822670931bd4444a27f298a47f1e8f732cec Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Doumenjou Date: Thu, 14 Mar 2019 19:32:03 +0100 Subject: [PATCH] Update anonymize/collect --- anonymize/anonymize_config_test.go | 202 ++++++++++++++++++- cmd/configuration.go | 3 +- cmd/traefik/traefik.go | 10 +- collector/collector.go | 2 +- config/static/static_config.go | 6 +- docs/content/contributing/data-collection.md | 8 +- integration/fixtures/access_log_config.toml | 1 + 7 files changed, 214 insertions(+), 18 deletions(-) diff --git a/anonymize/anonymize_config_test.go b/anonymize/anonymize_config_test.go index 7faa417a8..489ace6f2 100644 --- a/anonymize/anonymize_config_test.go +++ b/anonymize/anonymize_config_test.go @@ -7,11 +7,19 @@ import ( "github.com/containous/flaeg/parse" "github.com/containous/traefik/config/static" + "github.com/containous/traefik/ping" "github.com/containous/traefik/provider" "github.com/containous/traefik/provider/acme" acmeprovider "github.com/containous/traefik/provider/acme" + "github.com/containous/traefik/provider/docker" "github.com/containous/traefik/provider/file" + "github.com/containous/traefik/provider/kubernetes/crd" + "github.com/containous/traefik/provider/kubernetes/ingress" traefiktls "github.com/containous/traefik/tls" + "github.com/containous/traefik/tracing/datadog" + "github.com/containous/traefik/tracing/instana" + "github.com/containous/traefik/tracing/jaeger" + "github.com/containous/traefik/tracing/zipkin" "github.com/containous/traefik/types" assetfs "github.com/elazarl/go-bindata-assetfs" ) @@ -20,20 +28,42 @@ func TestDo_globalConfiguration(t *testing.T) { config := &static.Configuration{} + sendAnonymousUsage := true config.Global = &static.Global{ Debug: true, CheckNewVersion: true, - SendAnonymousUsage: true, + SendAnonymousUsage: &sendAnonymousUsage, } + config.AccessLog = &types.AccessLog{ FilePath: "AccessLog FilePath", Format: "AccessLog Format", + Filters: &types.AccessLogFilters{ + StatusCodes: types.StatusCodes{"200", "500"}, + RetryAttempts: true, + MinDuration: 10, + }, + Fields: &types.AccessLogFields{ + DefaultMode: "drop", + Names: types.FieldNames{ + "RequestHost": "keep", + }, + Headers: &types.FieldHeaders{ + DefaultMode: "drop", + Names: types.FieldHeaderNames{ + "Referer": "keep", + }, + }, + }, + BufferingSize: 4, } + config.Log = &types.TraefikLog{ LogLevel: "LogLevel", FilePath: "/foo/path", Format: "json", } + config.EntryPoints = static.EntryPoints{ "foo": { Address: "foo Address", @@ -63,19 +93,24 @@ func TestDo_globalConfiguration(t *testing.T) { }, } config.ACME = &acme.Configuration{ - Email: "acme Email", + Email: "acme Email", + ACMELogging: true, + CAServer: "CAServer", + Storage: "Storage", + EntryPoint: "EntryPoint", + KeyType: "MyKeyType", + OnHostRule: true, + DNSChallenge: &acmeprovider.DNSChallenge{Provider: "DNSProvider"}, + HTTPChallenge: &acmeprovider.HTTPChallenge{ + EntryPoint: "MyEntryPoint", + }, + TLSChallenge: &acmeprovider.TLSChallenge{}, Domains: []types.Domain{ { Main: "Domains Main", SANs: []string{"Domains acme SANs 1", "Domains acme SANs 2", "Domains acme SANs 3"}, }, }, - Storage: "Storage", - OnHostRule: true, - CAServer: "CAServer", - EntryPoint: "EntryPoint", - DNSChallenge: &acmeprovider.DNSChallenge{Provider: "DNSProvider"}, - ACMELogging: true, } config.Providers = &static.Providers{ ProvidersThrottleDuration: parse.Duration(111 * time.Second), @@ -134,8 +169,159 @@ func TestDo_globalConfiguration(t *testing.T) { Directory: "file Directory", } + config.Providers.Docker = &docker.Provider{ + BaseProvider: provider.BaseProvider{ + Watch: true, + Filename: "myfilename", + Constraints: nil, + Trace: true, + DebugLogGeneratedTemplate: true, + }, + Endpoint: "MyEndPoint", + DefaultRule: "PathPrefix(`/`)", + TLS: &types.ClientTLS{ + CA: "myCa", + CAOptional: true, + Cert: "mycert.pem", + Key: "mycert.key", + InsecureSkipVerify: true, + }, + ExposedByDefault: true, + UseBindPortIP: true, + SwarmMode: true, + Network: "MyNetwork", + SwarmModeRefreshSeconds: 42, + } + + config.Providers.Kubernetes = &ingress.Provider{ + BaseProvider: provider.BaseProvider{ + Watch: true, + Filename: "myFileName", + Constraints: types.Constraints{ + { + Key: "k8s Constraints Key 1", + Regex: "k8s Constraints Regex 2", + MustMatch: true, + }, + { + Key: "k8s Constraints Key 1", + Regex: "k8s Constraints Regex 2", + MustMatch: true, + }, + }, + Trace: true, + DebugLogGeneratedTemplate: true, + }, + Endpoint: "MyEndpoint", + Token: "MyToken", + CertAuthFilePath: "MyCertAuthPath", + DisablePassHostHeaders: true, + EnablePassTLSCert: true, + Namespaces: []string{"a", "b"}, + LabelSelector: "myLabelSelector", + IngressClass: "MyIngressClass", + } + + config.Providers.KubernetesCRD = &crd.Provider{ + BaseProvider: provider.BaseProvider{ + Watch: true, + Filename: "myFileName", + Constraints: types.Constraints{ + { + Key: "k8s Constraints Key 1", + Regex: "k8s Constraints Regex 2", + MustMatch: true, + }, + { + Key: "k8s Constraints Key 1", + Regex: "k8s Constraints Regex 2", + MustMatch: true, + }, + }, + Trace: true, + DebugLogGeneratedTemplate: true, + }, + Endpoint: "MyEndpoint", + Token: "MyToken", + CertAuthFilePath: "MyCertAuthPath", + DisablePassHostHeaders: true, + EnablePassTLSCert: true, + Namespaces: []string{"a", "b"}, + LabelSelector: "myLabelSelector", + IngressClass: "MyIngressClass", + } + // FIXME Test the other providers once they are migrated + config.Metrics = &types.Metrics{ + Prometheus: &types.Prometheus{ + Buckets: types.Buckets{0.1, 0.3, 1.2, 5}, + EntryPoint: "MyEntryPoint", + Middlewares: []string{"m1", "m2"}, + }, + Datadog: &types.Datadog{ + Address: "localhost:8181", + PushInterval: "12", + }, + StatsD: &types.Statsd{ + Address: "localhost:8182", + PushInterval: "42", + }, + InfluxDB: &types.InfluxDB{ + Address: "localhost:8183", + Protocol: "http", + PushInterval: "22", + Database: "myDB", + RetentionPolicy: "12", + Username: "a", + Password: "aaaa", + }, + } + + config.Ping = &ping.Handler{ + EntryPoint: "MyEntryPoint", + Middlewares: []string{"m1", "m2", "m3"}, + } + + config.Tracing = &static.Tracing{ + Backend: "myBackend", + ServiceName: "myServiceName", + SpanNameLimit: 3, + Jaeger: &jaeger.Config{ + SamplingServerURL: "aaa", + SamplingType: "bbb", + SamplingParam: 43, + LocalAgentHostPort: "ccc", + Gen128Bit: true, + Propagation: "ddd", + TraceContextHeaderName: "eee", + }, + Zipkin: &zipkin.Config{ + HTTPEndpoint: "fff", + SameSpan: true, + ID128Bit: true, + Debug: true, + SampleRate: 53, + }, + DataDog: &datadog.Config{ + LocalAgentHostPort: "ggg", + GlobalTag: "eee", + Debug: true, + PrioritySampling: true, + }, + Instana: &instana.Config{ + LocalAgentHost: "fff", + LocalAgentPort: 32, + LogLevel: "ggg", + }, + } + + config.HostResolver = &types.HostResolverConfig{ + CnameFlattening: true, + ResolvConfig: "aaa", + ResolvDepth: 3, + } + cleanJSON, err := Do(config, true) if err != nil { t.Fatal(err, cleanJSON) diff --git a/cmd/configuration.go b/cmd/configuration.go index c93c87567..a8d9dec13 100644 --- a/cmd/configuration.go +++ b/cmd/configuration.go @@ -42,8 +42,7 @@ func NewTraefikConfiguration() *TraefikConfiguration { return &TraefikConfiguration{ Configuration: static.Configuration{ Global: &static.Global{ - CheckNewVersion: true, - SendAnonymousUsage: false, + CheckNewVersion: true, }, EntryPoints: make(static.EntryPoints), Providers: &static.Providers{ diff --git a/cmd/traefik/traefik.go b/cmd/traefik/traefik.go index b4513a4be..6ae336d9f 100644 --- a/cmd/traefik/traefik.go +++ b/cmd/traefik/traefik.go @@ -383,7 +383,15 @@ func checkNewVersion() { } func stats(staticConfiguration *static.Configuration) { - if staticConfiguration.Global.SendAnonymousUsage { + if staticConfiguration.Global.SendAnonymousUsage == nil { + log.WithoutContext().Error(` +You haven't specify the sendAnonymousUsage option, it will be enable by default. +`) + sendAnonymousUsage := true + staticConfiguration.Global.SendAnonymousUsage = &sendAnonymousUsage + } + + if *staticConfiguration.Global.SendAnonymousUsage { log.WithoutContext().Info(` Stats collection is enabled. Many thanks for contributing to Traefik's improvement by allowing us to receive anonymous information from your configuration. diff --git a/collector/collector.go b/collector/collector.go index 1171c8c27..a3a714ee2 100644 --- a/collector/collector.go +++ b/collector/collector.go @@ -18,7 +18,7 @@ import ( ) // collectorURL URL where the stats are send -const collectorURL = "https://collect.traefik.io/619df80498b60f985d766ce62f912b7c" +const collectorURL = "https://collect.traefik.io/9vxmmkcdmalbdi635d4jgc5p5rx0h7h8" // Collected data type data struct { diff --git a/config/static/static_config.go b/config/static/static_config.go index 229162134..e7da0d381 100644 --- a/config/static/static_config.go +++ b/config/static/static_config.go @@ -75,9 +75,9 @@ type Configuration struct { // Global holds the global configuration. type Global struct { - Debug bool `short:"d" description:"Enable debug mode" export:"true"` - CheckNewVersion bool `description:"Periodically check if a new version has been released" export:"true"` - SendAnonymousUsage bool `description:"send periodically anonymous usage statistics" export:"true"` + Debug bool `short:"d" description:"Enable debug mode" export:"true"` + CheckNewVersion bool `description:"Periodically check if a new version has been released" export:"true"` + SendAnonymousUsage *bool `description:"send periodically anonymous usage statistics" export:"true"` } // ServersTransport options to configure communication between Traefik and the servers diff --git a/docs/content/contributing/data-collection.md b/docs/content/contributing/data-collection.md index 873bd387e..71ecabc29 100644 --- a/docs/content/contributing/data-collection.md +++ b/docs/content/contributing/data-collection.md @@ -5,15 +5,17 @@ Understanding How Traefik is Being Used ## Configuration Example -**By default, this feature is disabled;** but to allow us understand better how you use Traefik, please enable the data collection option. +Understanding how you use Traefik is very important to us: it helps us improve the solution in many different ways. +For this very reason, the sendAnonymousUsage option is mandatory: we want you to take time to consider whether or not you wish to share anonymous data with us so we can benefit from your experience and use cases. + +!!! warning + During the alpha stage only, leaving this option unset will not prevent Traefik from running but will generate an error log indicating that it enables data collection by default. ??? example "Enabling Data Collection with TOML" ```toml [Global] # Send anonymous usage data - # Default: false - # sendAnonymousUsage = true ``` diff --git a/integration/fixtures/access_log_config.toml b/integration/fixtures/access_log_config.toml index 625d168df..4fa1c587e 100644 --- a/integration/fixtures/access_log_config.toml +++ b/integration/fixtures/access_log_config.toml @@ -4,6 +4,7 @@ filePath = "traefik.log" [global] checkNewVersion = false +sendAnonymousUsage = false [accessLog] filePath = "access.log"