diff --git a/README.md b/README.md index 6a26b14be99..5a9329fa763 100644 --- a/README.md +++ b/README.md @@ -3,5 +3,7 @@ This repository is the home to the common libraries used by Elastic Agent and Beats. Provided packages: -* `github.com/elastic/elastic-agent-libs/config` the previous `config.go` file from `github.com/elastic/beats/v7/libbeat/common`. A minimal wrapper around `github.com/elastic/go-ucfg`. It contains helpers for merging and accessing configuration objects. +* `github.com/elastic/elastic-agent-libs/config` the previous `config.go` file from `github.com/elastic/beats/v7/libbeat/common`. A minimal wrapper around `github.com/elastic/go-ucfg`. It contains helpers for merging and accessing configuration objects and flags. * `github.com/elastic/elastic-agent-libs/str` the previous `stringset.go` file from `github.com/elastic/beats/v7/libbeat/common`. It provides a string set implementation. +* `github.com/elastic/elastic-agent-libs/file` is responsible for rotating and writing input and output files. +* `github.com/elastic/elastic-agent-libs/logp` is the well known logger from libbeat. diff --git a/config/flags.go b/config/flags.go new file mode 100644 index 00000000000..070ec468c4d --- /dev/null +++ b/config/flags.go @@ -0,0 +1,290 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package config + +import ( + "flag" + "strings" + + ucfg "github.com/elastic/go-ucfg" + cfgflag "github.com/elastic/go-ucfg/flag" +) + +// StringsFlag collects multiple usages of the same flag into an array of strings. +// Duplicate values will be ignored. +type StringsFlag struct { + list *[]string + isDefault bool + flag *flag.Flag +} + +// SettingsFlag captures key/values pairs into an Config object. +// The flag backed by SettingsFlag can be used multiple times. +// Values are overwritten by the last usage of a key. +type SettingsFlag cfgflag.FlagValue + +// flagOverwrite provides a flag value, which always overwrites the same setting +// in an Config object. +type flagOverwrite struct { + config *ucfg.Config + path string + value string +} + +// StringArrFlag creates and registers a new StringsFlag with the given FlagSet. +// If no FlagSet is passed, flag.CommandLine will be used as target FlagSet. +func StringArrFlag(fs *flag.FlagSet, name, def, usage string) *StringsFlag { + var arr *[]string + if def != "" { + arr = &[]string{def} + } else { + arr = &[]string{} + } + + return StringArrVarFlag(fs, arr, name, usage) +} + +// StringArrVarFlag creates and registers a new StringsFlag with the given +// FlagSet. Results of the flag usage will be appended to `arr`. If the slice +// is not initially empty, its first value will be used as default. If the flag +// is used, the slice will be emptied first. If no FlagSet is passed, +// flag.CommandLine will be used as target FlagSet. +func StringArrVarFlag(fs *flag.FlagSet, arr *[]string, name, usage string) *StringsFlag { + if fs == nil { + fs = flag.CommandLine + } + f := NewStringsFlag(arr) + f.Register(fs, name, usage) + return f +} + +// NewStringsFlag creates a new, but unregistered StringsFlag instance. +// Results of the flag usage will be appended to `arr`. If the slice is not +// initially empty, its first value will be used as default. If the flag is +// used, the slice will be emptied first. +func NewStringsFlag(arr *[]string) *StringsFlag { + if arr == nil { + panic("No target array") + } + return &StringsFlag{list: arr, isDefault: true} +} + +// Register registers the StringsFlag instance with a FlagSet. +// A valid FlagSet must be used. +// Register panics if the flag is already registered. +func (f *StringsFlag) Register(fs *flag.FlagSet, name, usage string) { + if f.flag != nil { + panic("StringsFlag is already registered") + } + + fs.Var(f, name, usage) + f.flag = fs.Lookup(name) + if f.flag == nil { + panic("Failed to lookup registered flag") + } + + if len(*f.list) > 0 { + f.flag.DefValue = (*f.list)[0] + } +} + +// String joins all it's values set into a comma-separated string. +func (f *StringsFlag) String() string { + if f == nil || f.list == nil { + return "" + } + + l := *f.list + return strings.Join(l, ", ") +} + +// SetDefault sets the flags new default value. +// This overwrites the contents in the backing array. +func (f *StringsFlag) SetDefault(v string) { + if f.flag != nil { + f.flag.DefValue = v + } + + *f.list = []string{v} + f.isDefault = true +} + +// Set is used to pass usage of the flag to StringsFlag. Set adds the new value +// to the backing array. The array will be emptied on Set, if the backing array +// still contains the default value. +func (f *StringsFlag) Set(v string) error { + // Ignore duplicates, can be caused by multiple flag parses + if f.isDefault { + *f.list = []string{v} + } else { + for _, old := range *f.list { + if old == v { + return nil + } + } + *f.list = append(*f.list, v) + } + f.isDefault = false + return nil +} + +// Get returns the backing slice its contents as interface{}. The type used is +// `[]string`. +func (f *StringsFlag) Get() interface{} { + return f.List() +} + +// List returns the current set values. +func (f *StringsFlag) List() []string { + return *f.list +} + +// Type reports the type of contents (string) expected to be parsed by Set. +// It is used to build the CLI usage string. +func (f *StringsFlag) Type() string { + return "string" +} + +// SettingFlag defines a setting flag, name and it's usage. The return value is +// the Config object settings are applied to. +func SettingFlag(fs *flag.FlagSet, name, usage string) *C { + cfg := NewConfig() + SettingVarFlag(fs, cfg, name, usage) + return cfg +} + +// SettingVarFlag defines a setting flag, name and it's usage. +// Settings are applied to the Config object passed. +func SettingVarFlag(fs *flag.FlagSet, def *C, name, usage string) { + if fs == nil { + fs = flag.CommandLine + } + + f := NewSettingsFlag(def) + fs.Var(f, name, usage) +} + +// NewSettingsFlag creates a new SettingsFlag instance, not registered with any +// FlagSet. +func NewSettingsFlag(def *C) *SettingsFlag { + opts := append( + []ucfg.Option{ + ucfg.MetaData(ucfg.Meta{Source: "command line flag"}), + }, + configOpts..., + ) + + tmp := cfgflag.NewFlagKeyValue(def.access(), true, opts...) + return (*SettingsFlag)(tmp) +} + +func (f *SettingsFlag) access() *cfgflag.FlagValue { + return (*cfgflag.FlagValue)(f) +} + +// Config returns the config object the SettingsFlag stores applied settings to. +func (f *SettingsFlag) Config() *C { + return fromConfig(f.access().Config()) +} + +// Set sets a settings value in the Config object. The input string must be a +// key-value pair like `key=value`. If the value is missing, the value is set +// to the boolean value `true`. +func (f *SettingsFlag) Set(s string) error { + return f.access().Set(s) +} + +// Get returns the Config object used to store values. +func (f *SettingsFlag) Get() interface{} { + return f.Config() +} + +// String always returns an empty string. It is required to fulfil +// the flag.Value interface. +func (f *SettingsFlag) String() string { + return "" +} + +// Type reports the type of contents (setting=value) expected to be parsed by Set. +// It is used to build the CLI usage string. +func (f *SettingsFlag) Type() string { + return "setting=value" +} + +// ConfigOverwriteFlag defines a new flag updating a setting in an Config +// object. The name is used as the flag its name the path parameter is the +// full setting name to be used when the flag is set. +func ConfigOverwriteFlag( + fs *flag.FlagSet, + config *C, + name, path, def, usage string, +) *string { + if config == nil { + panic("Missing configuration") + } + if path == "" { + panic("empty path") + } + + if fs == nil { + fs = flag.CommandLine + } + + if def != "" { + err := config.SetString(path, -1, def) + if err != nil { + panic(err) + } + } + + f := newOverwriteFlag(config, path, def) + fs.Var(f, name, usage) + return &f.value +} + +func newOverwriteFlag(c *C, path, def string) *flagOverwrite { + return &flagOverwrite{config: c.access(), path: path, value: def} +} + +func (f *flagOverwrite) String() string { + return f.value +} + +func (f *flagOverwrite) Set(v string) error { + opts := append( + []ucfg.Option{ + ucfg.MetaData(ucfg.Meta{Source: "command line flag"}), + }, + configOpts..., + ) + + err := f.config.SetString(f.path, -1, v, opts...) + if err != nil { + return err + } + f.value = v + return nil +} + +func (f *flagOverwrite) Get() interface{} { + return f.value +} + +func (f *flagOverwrite) Type() string { + return "string" +} diff --git a/config/flags_test.go b/config/flags_test.go new file mode 100644 index 00000000000..da1fa456a9d --- /dev/null +++ b/config/flags_test.go @@ -0,0 +1,194 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package config + +import ( + "bytes" + "flag" + "fmt" + "io" + "os" + "strings" + "testing" + + "github.com/spf13/cobra" + "github.com/stretchr/testify/assert" +) + +func TestStringArrFlag(t *testing.T) { + tests := []struct { + init []string + def string + in []string + expected []string + }{ + {nil, "test", nil, []string{"test"}}, + {nil, "test", []string{"new"}, []string{"new"}}, + {nil, "test", []string{"a", "b"}, []string{"a", "b"}}, + {[]string{"default"}, "newdefault", nil, []string{"newdefault"}}, + {[]string{"default"}, "newdefault", []string{"arg"}, []string{"arg"}}, + {[]string{"default"}, "newdefault", []string{"a", "b"}, []string{"a", "b"}}, + {[]string{"default"}, "newdefault", []string{"a", "b", "a", "b"}, []string{"a", "b"}}, + } + + for _, test := range tests { + test := test + name := fmt.Sprintf("init=%v,default=%v,in=%v,out=%v", test.init, test.def, test.in, test.expected) + + t.Run(name, func(t *testing.T) { + init := make([]string, len(test.init)) + copy(init, test.init) + + fs := flag.NewFlagSet("test", flag.ContinueOnError) + flag := StringArrVarFlag(fs, &init, "a", "add") + + if test.def != "" { + flag.SetDefault(test.def) + } + + defaultValue := flag.String() + + goflagUsage, _ := withStderr(fs.PrintDefaults) + goflagExpectedUsage := fmt.Sprintf(" -a value\n \tadd (default %v)\n", defaultValue) + + cmd := cobra.Command{} + cmd.PersistentFlags().AddGoFlag(fs.Lookup("a")) + cobraUsage := cmd.LocalFlags().FlagUsages() + cobraExpectedUsage := fmt.Sprintf(" -a, --a string add (default \"%v\")\n", defaultValue) + + for _, v := range test.in { + err := flag.Set(v) + if err != nil { + t.Error(err) + } + } + + assert.Equal(t, goflagExpectedUsage, goflagUsage) + assert.Equal(t, cobraExpectedUsage, cobraUsage) + assert.Equal(t, test.expected, init) + assert.Equal(t, test.expected, flag.List()) + }) + } +} + +func TestSettingsFlag(t *testing.T) { + tests := []struct { + in []string + expected map[string]interface{} + }{ + {nil, map[string]interface{}{}}, + {[]string{"a=1"}, map[string]interface{}{"a": uint64(1)}}, + {[]string{"a=1", "b=false"}, map[string]interface{}{"a": uint64(1), "b": false}}, + {[]string{"a=1", "b"}, map[string]interface{}{"a": uint64(1), "b": true}}, + {[]string{"a=1", "c=${a}"}, map[string]interface{}{"a": uint64(1), "c": uint64(1)}}, + } + + for _, test := range tests { + test := test + name := strings.Join(test.in, ",") + + t.Run(name, func(t *testing.T) { + config := NewConfig() + f := NewSettingsFlag(config) + + fs := flag.NewFlagSet("test", flag.ContinueOnError) + fs.Var(f, "s", "message") + + goflagUsage, _ := withStderr(fs.PrintDefaults) + goflagExpectedUsage := " -s value\n \tmessage\n" + + cmd := cobra.Command{} + cmd.PersistentFlags().AddGoFlag(fs.Lookup("s")) + cobraUsage := cmd.LocalFlags().FlagUsages() + cobraExpectedUsage := " -s, --s setting=value message\n" + + for _, in := range test.in { + err := f.Set(in) + if err != nil { + t.Error(err) + } + } + + var result map[string]interface{} + err := config.Unpack(&result) + if err != nil { + t.Fatal(err) + } + + assert.Equal(t, goflagExpectedUsage, goflagUsage) + assert.Equal(t, cobraExpectedUsage, cobraUsage) + assert.Equal(t, test.expected, result) + }) + } +} + +func TestOverwriteFlag(t *testing.T) { + config, err := NewConfigFrom(map[string]interface{}{ + "a": "test", + }) + if err != nil { + panic(err) + } + + fs := flag.NewFlagSet("test", flag.ContinueOnError) + ConfigOverwriteFlag(fs, config, "a", "a", "", "message") + + goflagUsage, _ := withStderr(fs.PrintDefaults) + goflagExpectedUsage := " -a value\n \tmessage\n" + assert.Equal(t, goflagExpectedUsage, goflagUsage) + + cmd := cobra.Command{} + cmd.PersistentFlags().AddGoFlag(fs.Lookup("a")) + cobraUsage := cmd.LocalFlags().FlagUsages() + cobraExpectedUsage := " -a, --a string message\n" + assert.Equal(t, cobraExpectedUsage, cobraUsage) + + fs.Set("a", "overwrite") + final, err := config.String("a", -1) + assert.NoError(t, err) + assert.Equal(t, "overwrite", final) +} + +// capture stderr and return captured string +func withStderr(fn func()) (string, error) { + stderr := os.Stderr + + r, w, err := os.Pipe() + if err != nil { + return "", err + } + + os.Stderr = w + defer func() { + os.Stderr = stderr + }() + + outC := make(chan string) + go func() { + // capture all output + var buf bytes.Buffer + _, err = io.Copy(&buf, r) + r.Close() + outC <- buf.String() + }() + + fn() + w.Close() + result := <-outC + return result, err +} diff --git a/file/helper_aix.go b/file/helper_aix.go new file mode 100644 index 00000000000..985b452c1e3 --- /dev/null +++ b/file/helper_aix.go @@ -0,0 +1,45 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package file + +import ( + "os" + "path/filepath" +) + +// SafeFileRotate safely rotates an existing file under path and replaces it with the tempfile +func SafeFileRotate(path, tempfile string) error { + parent := filepath.Dir(path) + + if e := os.Rename(tempfile, path); e != nil { + return e + } + + // best-effort fsync on parent directory. The fsync is required by some + // filesystems, so to update the parents directory metadata to actually + // contain the new file being rotated in. + // On AIX, fsync will fail if the file is opened in read-only mode, + // which is the case with os.Open. + f, err := os.OpenFile(parent, os.O_RDWR, 0) + if err != nil { + return nil // ignore error + } + defer f.Close() + + return f.Sync() +} diff --git a/file/helper_other.go b/file/helper_other.go new file mode 100644 index 00000000000..a2fdee7ec94 --- /dev/null +++ b/file/helper_other.go @@ -0,0 +1,46 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//go:build !aix && !windows +// +build !aix,!windows + +package file + +import ( + "os" + "path/filepath" +) + +// SafeFileRotate safely rotates an existing file under path and replaces it with the tempfile +func SafeFileRotate(path, tempfile string) error { + parent := filepath.Dir(path) + + if e := os.Rename(tempfile, path); e != nil { + return e + } + + // best-effort fsync on parent directory. The fsync is required by some + // filesystems, so to update the parents directory metadata to actually + // contain the new file being rotated in. + f, err := os.Open(parent) + if err != nil { + return nil // ignore error + } + defer f.Close() + + return f.Sync() +} diff --git a/file/helper_test.go b/file/helper_test.go new file mode 100644 index 00000000000..2a936e7994d --- /dev/null +++ b/file/helper_test.go @@ -0,0 +1,85 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//go:build !integration +// +build !integration + +package file + +import ( + "io/ioutil" + "os" + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestSafeFileRotateExistingFile(t *testing.T) { + tempdir, err := ioutil.TempDir("", "") + assert.NoError(t, err) + defer func() { + assert.NoError(t, os.RemoveAll(tempdir)) + }() + + // create an existing registry file + err = ioutil.WriteFile(filepath.Join(tempdir, "registry"), + []byte("existing filebeat"), 0x777) + assert.NoError(t, err) + + // create a new registry.new file + err = ioutil.WriteFile(filepath.Join(tempdir, "registry.new"), + []byte("new filebeat"), 0x777) + assert.NoError(t, err) + + // rotate registry.new into registry + err = SafeFileRotate(filepath.Join(tempdir, "registry"), + filepath.Join(tempdir, "registry.new")) + assert.NoError(t, err) + + contents, err := ioutil.ReadFile(filepath.Join(tempdir, "registry")) + assert.NoError(t, err) + assert.Equal(t, []byte("new filebeat"), contents) + + // do it again to make sure we deal with deleting the old file + + err = ioutil.WriteFile(filepath.Join(tempdir, "registry.new"), + []byte("new filebeat 1"), 0x777) + assert.NoError(t, err) + + err = SafeFileRotate(filepath.Join(tempdir, "registry"), + filepath.Join(tempdir, "registry.new")) + assert.NoError(t, err) + + contents, err = ioutil.ReadFile(filepath.Join(tempdir, "registry")) + assert.NoError(t, err) + assert.Equal(t, []byte("new filebeat 1"), contents) + + // and again for good measure + + err = ioutil.WriteFile(filepath.Join(tempdir, "registry.new"), + []byte("new filebeat 2"), 0x777) + assert.NoError(t, err) + + err = SafeFileRotate(filepath.Join(tempdir, "registry"), + filepath.Join(tempdir, "registry.new")) + assert.NoError(t, err) + + contents, err = ioutil.ReadFile(filepath.Join(tempdir, "registry")) + assert.NoError(t, err) + assert.Equal(t, []byte("new filebeat 2"), contents) +} diff --git a/file/helper_windows.go b/file/helper_windows.go new file mode 100644 index 00000000000..f13477e2407 --- /dev/null +++ b/file/helper_windows.go @@ -0,0 +1,53 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package file + +import ( + "os" + "path/filepath" +) + +// SafeFileRotate safely rotates an existing file under path and replaces it with the tempfile +func SafeFileRotate(path, tempfile string) error { + old := path + ".old" + var e error + + // In Windows, one cannot rename a file if the destination already exists, at least + // not with using the os.Rename function that Golang offers. + // This tries to move the existing file into an old file first and only do the + // move after that. + if e = os.Remove(old); e != nil { + // ignore error in case old doesn't exit yet + } + if e = os.Rename(path, old); e != nil { + // ignore error in case path doesn't exist + } + + if e = os.Rename(tempfile, path); e != nil { + return e + } + + // sync all files + parent := filepath.Dir(path) + if f, err := os.OpenFile(parent, os.O_SYNC|os.O_RDWR, 0755); err == nil { + f.Sync() + f.Close() + } + + return nil +} diff --git a/file/rotator.go b/file/rotator.go new file mode 100644 index 00000000000..e32e317dbfb --- /dev/null +++ b/file/rotator.go @@ -0,0 +1,542 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package file + +import ( + "fmt" + "os" + "path/filepath" + "sort" + "strconv" + "sync" + "time" + + "github.com/pkg/errors" +) + +const ( + // MaxBackupsLimit is the upper bound on the number of backup files. Any values + // greater will result in an error. + MaxBackupsLimit = 1024 + DateFormat = "20060102" +) + +// rotater is the interface responsible for rotating and finding files. +type rotater interface { + // ActiveFile returns the path to the file that is actively written. + ActiveFile() string + // RotatedFiles returns the list of rotated files. The oldest comes first. + RotatedFiles() []string + // Rotate rotates the file. + Rotate(reason rotateReason, rotateTime time.Time) error +} + +// Rotator is a io.WriteCloser that automatically rotates the file it is +// writing to when it reaches a maximum size and optionally on a time interval +// basis. It also purges the oldest rotated files when the maximum number of +// backups is reached. +type Rotator struct { + rot rotater + triggers []trigger + + filename string + maxSizeBytes uint + maxBackups uint + interval time.Duration + permissions os.FileMode + log Logger // Optional Logger (may be nil). + rotateOnStartup bool + redirectStderr bool + clock clock + + file *os.File + mutex sync.Mutex +} + +// Logger allows the rotator to write debug information. +type Logger interface { + Debugw(msg string, keysAndValues ...interface{}) // Debug +} + +// RotatorOption is a configuration option for Rotator. +type RotatorOption func(r *Rotator) + +// MaxSizeBytes configures the maximum number of bytes that a file should +// contain before being rotated. The default is 10 MiB. +func MaxSizeBytes(n uint) RotatorOption { + return func(r *Rotator) { + r.maxSizeBytes = n + } +} + +// MaxBackups configures the maximum number of backup files to save (not +// counting the active file). The upper limit is 1024 on this value is. +// The default is 7. +func MaxBackups(n uint) RotatorOption { + return func(r *Rotator) { + r.maxBackups = n + } +} + +// Permissions configures the file permissions to use for the file that +// the Rotator creates. The default is 0600. +func Permissions(m os.FileMode) RotatorOption { + return func(r *Rotator) { + r.permissions = m + } +} + +// WithLogger injects a logger implementation for logging debug information. +// If no logger is injected then the no logging will occur. +func WithLogger(l Logger) RotatorOption { + return func(r *Rotator) { + r.log = l + } +} + +// Interval sets the time interval for log rotation in addition to log +// rotation by size. The default is 0 for disabled. +func Interval(d time.Duration) RotatorOption { + return func(r *Rotator) { + r.interval = d + } +} + +// RotateOnStartup immediately rotates files on startup rather than appending to +// the existing file. The default is true. +func RotateOnStartup(b bool) RotatorOption { + return func(r *Rotator) { + r.rotateOnStartup = b + } +} + +// RedirectStderr causes all writes to standard error to be redirected +// to this rotator. +func RedirectStderr(redirect bool) RotatorOption { + return func(r *Rotator) { + r.redirectStderr = redirect + } +} + +func WithClock(clock clock) RotatorOption { + return func(r *Rotator) { + r.clock = clock + } +} + +// NewFileRotator returns a new Rotator. +func NewFileRotator(filename string, options ...RotatorOption) (*Rotator, error) { + r := &Rotator{ + maxSizeBytes: 10 * 1024 * 1024, // 10 MiB + maxBackups: 7, + permissions: 0600, + interval: 0, + rotateOnStartup: true, + clock: &realClock{}, + } + + for _, opt := range options { + opt(r) + } + + if r.maxSizeBytes == 0 { + return nil, errors.New("file rotator max file size must be greater than 0") + } + if r.maxBackups > MaxBackupsLimit { + return nil, errors.Errorf("file rotator max backups %d is greater than the limit of %v", r.maxBackups, MaxBackupsLimit) + } + if r.permissions > os.ModePerm { + return nil, errors.Errorf("file rotator permissions mask of %o is invalid", r.permissions) + } + + if r.interval != 0 && r.interval < time.Second { + return nil, errors.New("the minimum time interval for log rotation is 1 second") + } + + r.rot = newDateRotater(r.log, filename, r.clock) + + shouldRotateOnStart := r.rotateOnStartup + if _, err := os.Stat(r.rot.ActiveFile()); os.IsNotExist(err) { + shouldRotateOnStart = false + } + + r.triggers = newTriggers(shouldRotateOnStart, r.interval, r.maxSizeBytes, r.clock) + + if r.log != nil { + r.log.Debugw("Initialized file rotator", + "filename", r.filename, + "max_size_bytes", r.maxSizeBytes, + "max_backups", r.maxBackups, + "permissions", r.permissions, + ) + } + + return r, nil +} + +// Write writes the given bytes to the file. This implements io.Writer. If +// the write would trigger a rotation the rotation is done before writing to +// avoid going over the max size. Write is safe for concurrent use. +func (r *Rotator) Write(data []byte) (int, error) { + r.mutex.Lock() + defer r.mutex.Unlock() + + dataLen := uint(len(data)) + if dataLen > r.maxSizeBytes { + return 0, errors.Errorf("data size (%d bytes) is greater than "+ + "the max file size (%d bytes)", dataLen, r.maxSizeBytes) + } + + if r.file == nil { + if err := r.openNew(); err != nil { + return 0, errors.Wrap(err, "failed to open new log file for writing") + } + } else { + if reason, t := r.isRotationTriggered(dataLen); reason != rotateReasonNoRotate { + if err := r.rotateWithTime(reason, t); err != nil { + return 0, errors.Wrapf(err, "error file rotating files reason: %s", reason) + } + + if err := r.openFile(); err != nil { + return 0, errors.Wrap(err, "failed to open existing log file for writing") + } + } + } + + n, err := r.file.Write(data) + return n, errors.Wrap(err, "failed to write to file") +} + +// openNew opens r's log file for the first time, creating it if it doesn't +// exist. +func (r *Rotator) openNew() error { + err := os.MkdirAll(r.dir(), r.dirMode()) + if err != nil { + return errors.Wrap(err, "failed to make directories for new file") + } + + _, err = os.Stat(r.rot.ActiveFile()) + if err == nil { + // check if the file has to be rotated before writing to it + reason, t := r.isRotationTriggered(0) + if reason == rotateReasonNoRotate { + return r.appendToFile() + } + if err = r.rot.Rotate(reason, t); err != nil { + return errors.Wrap(err, "failed to rotate backups") + } + if err = r.purge(); err != nil { + return errors.Wrap(err, "failed to purge unnecessary rotated files") + } + } + + return r.openFile() +} + +// appendToFile opens an existing log file for appending. Unlike openFile it +// does not call MkdirAll because it is an error for the file to not already +// exist. +func (r *Rotator) appendToFile() error { + var err error + r.file, err = os.OpenFile(r.rot.ActiveFile(), os.O_WRONLY|os.O_APPEND, r.permissions) + if err != nil { + return errors.Wrap(err, "failed to append to existing file") + } + if r.redirectStderr { + RedirectStandardError(r.file) + } + return nil +} + +func (r *Rotator) openFile() error { + err := os.MkdirAll(r.dir(), r.dirMode()) + if err != nil { + return errors.Wrap(err, "failed to make directories for new file") + } + + r.file, err = os.OpenFile(r.rot.ActiveFile(), os.O_CREATE|os.O_WRONLY|os.O_TRUNC, r.permissions) + if err != nil { + return errors.Wrap(err, fmt.Sprintf("failed to open new file '%s'", r.rot.ActiveFile())) + } + if r.redirectStderr { + RedirectStandardError(r.file) + } + return nil +} + +func (r *Rotator) rotate(reason rotateReason) error { + return r.rotateWithTime(reason, r.clock.Now()) +} + +// rotateWithTime closes the actively written file, and rotates it along with exising +// rotated files if needed. When it is done, unnecessary files are removed. +func (r *Rotator) rotateWithTime(reason rotateReason, rotationTime time.Time) error { + if err := r.closeFile(); err != nil { + return errors.Wrap(err, "error file closing current file") + } + + if err := r.rot.Rotate(reason, rotationTime); err != nil { + return errors.Wrap(err, "failed to rotate backups") + } + + return r.purge() +} + +func (r *Rotator) purge() error { + rotatedFiles := r.rot.RotatedFiles() + count := uint(len(rotatedFiles)) + if count <= r.maxBackups { + return nil + } + + purgeUntil := count - r.maxBackups + filesToPurge := rotatedFiles[:purgeUntil] + for _, name := range filesToPurge { + _, err := os.Stat(name) + switch { + case err == nil: + if err = os.Remove(name); err != nil { + return errors.Wrapf(err, "failed to delete %v during rotation", name) + } + case os.IsNotExist(err): + return nil + default: + return errors.Wrapf(err, "failed on %v during rotation", name) + } + } + + return nil +} + +func (r *Rotator) isRotationTriggered(dataLen uint) (rotateReason, time.Time) { + for _, t := range r.triggers { + reason := t.TriggerRotation(dataLen) + if reason != rotateReasonNoRotate { + return reason, r.clock.Now() + } + } + return rotateReasonNoRotate, time.Time{} +} + +// Sync commits the current contents of the file to stable storage. Typically, +// this means flushing the file system's in-memory copy of recently written data +// to disk. +func (r *Rotator) Sync() error { + r.mutex.Lock() + defer r.mutex.Unlock() + if r.file == nil { + return nil + } + return r.file.Sync() +} + +// Rotate triggers a file rotation. +func (r *Rotator) Rotate() error { + r.mutex.Lock() + defer r.mutex.Unlock() + return r.rotate(rotateReasonManualTrigger) +} + +// Close closes the currently open file. +func (r *Rotator) Close() error { + r.mutex.Lock() + defer r.mutex.Unlock() + return r.closeFile() +} + +func (r *Rotator) dir() string { + return filepath.Dir(r.rot.ActiveFile()) +} + +func (r *Rotator) dirMode() os.FileMode { + mode := 0700 + if r.permissions&0070 > 0 { + mode |= 0050 + } + if r.permissions&0007 > 0 { + mode |= 0005 + } + return os.FileMode(mode) +} + +func (r *Rotator) closeFile() error { + if r.file == nil { + return nil + } + err := r.file.Close() + r.file = nil + return errors.Wrap(err, "failed to close active file") +} + +type dateRotator struct { + log Logger + clock clock + format string + filenamePrefix string + currentFilename string + extension string + + prefixLen int + filenameLen int + extensionLen int + + // logOrderCache is used to cache log file meta information between rotations + logOrderCache map[string]logOrder +} + +func newDateRotater(log Logger, filename string, clock clock) rotater { + d := &dateRotator{ + log: log, + clock: clock, + filenamePrefix: filename + "-", + extension: ".ndjson", + format: DateFormat, + logOrderCache: make(map[string]logOrder), + } + d.prefixLen = len(d.filenamePrefix) + d.filenameLen = d.prefixLen + len(DateFormat) + d.extensionLen = len(d.extension) + + d.currentFilename = d.filenamePrefix + d.clock.Now().Format(d.format) + d.extension + files, err := filepath.Glob(d.filenamePrefix + "*" + d.extension) + if err != nil { + return d + } + + // continue from last file + if len(files) != 0 { + if len(files) == 1 { + d.currentFilename = files[0] + } else { + d.SortModTimeLogs(files) + d.currentFilename = files[len(files)-1] + } + } + + return d +} + +func (d *dateRotator) ActiveFile() string { + return d.currentFilename +} + +func (d *dateRotator) Rotate(reason rotateReason, rotateTime time.Time) error { + if d.log != nil { + d.log.Debugw("Rotating file", "filename", d.currentFilename, "reason", reason) + } + + d.logOrderCache = make(map[string]logOrder, 0) + + newFileNamePrefix := d.filenamePrefix + rotateTime.Format(d.format) + files, err := filepath.Glob(newFileNamePrefix + "*" + d.extension) + if err != nil { + return fmt.Errorf("failed to get possible files: %+v", err) + } + + if len(files) == 0 { + d.currentFilename = newFileNamePrefix + d.extension + return nil + } + + d.SortModTimeLogs(files) + order := d.OrderLog(files[len(files)-1]) + + d.currentFilename = newFileNamePrefix + "-" + strconv.Itoa(order.index+1) + d.extension + + return nil +} + +func (d *dateRotator) RotatedFiles() []string { + files, err := filepath.Glob(d.filenamePrefix + "*") + if err != nil { + if d.log != nil { + d.log.Debugw("failed to list existing logs: %+v", err) + } + } + + for i, name := range files { + if name == d.ActiveFile() { + files = append(files[:i], files[i+1:]...) + break + } + } + + d.SortModTimeLogs(files) + return files +} + +// SortModTimeLogs puts newest file to the last +func (d *dateRotator) SortModTimeLogs(strings []string) { + sort.Slice( + strings, + func(i, j int) bool { + return d.OrderLog(strings[i]).After(d.OrderLog(strings[j])) + }, + ) +} + +// logOrder stores information required to sort log files +// parsed out from the following format {filename}-{datetime}-{index}.ndjson +type logOrder struct { + index int + datetime time.Time +} + +func (o logOrder) After(other logOrder) bool { + if o.datetime.Equal(other.datetime) { + return other.index > o.index + } + return !o.datetime.After(other.datetime) +} + +func (d *dateRotator) OrderLog(filename string) logOrder { + if o, ok := d.logOrderCache[filename]; ok { + return o + } + + var o logOrder + var err error + + o.datetime, err = time.Parse(d.format, filename[d.prefixLen:d.filenameLen]) + if err != nil { + return o + } + + if d.isFilenameWithIndex(filename) { + o.index, err = d.filenameIndex(filename) + if err != nil { + return o + } + } + + d.logOrderCache[filename] = o + + return o +} + +func (d *dateRotator) isFilenameWithIndex(filename string) bool { + return d.filenameLen+d.extensionLen < len(filename) +} + +func (d *dateRotator) filenameIndex(filename string) (int, error) { + indexStr := filename[d.filenameLen+1 : len(filename)-d.extensionLen] + if len(indexStr) > 0 { + return strconv.Atoi(indexStr) + } + return 0, nil +} diff --git a/file/rotator_test.go b/file/rotator_test.go new file mode 100644 index 00000000000..48f6e96eece --- /dev/null +++ b/file/rotator_test.go @@ -0,0 +1,307 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//go:build !windows + +package file_test + +import ( + "fmt" + "os" + "path/filepath" + "sync" + "testing" + "time" + + "github.com/stretchr/testify/assert" + + "github.com/elastic/elastic-agent-libs/file" + "github.com/elastic/elastic-agent-libs/logp" +) + +const logMessage = "Test file rotator.\n" + +func TestFileRotator(t *testing.T) { + logp.TestingSetup() + + dir := t.TempDir() + logname := "sample" + c := &testClock{time.Date(2021, 11, 11, 0, 0, 0, 0, time.Local)} + + filename := filepath.Join(dir, logname) + r, err := file.NewFileRotator(filename, + file.MaxBackups(2), + file.WithLogger(logp.NewLogger("rotator").With(logp.Namespace("rotator"))), + file.WithClock(c), + ) + if err != nil { + t.Fatal(err) + } + defer r.Close() + + firstFile := fmt.Sprintf("%s-%s.ndjson", logname, c.Now().Format(file.DateFormat)) + + WriteMsg(t, r) + AssertDirContents(t, dir, firstFile) + + c.time = time.Date(2021, 11, 12, 0, 0, 0, 0, time.Local) + + Rotate(t, r) + AssertDirContents(t, dir, firstFile) + + WriteMsg(t, r) + + secondFile := fmt.Sprintf("%s-%s.ndjson", logname, c.Now().Format(file.DateFormat)) + AssertDirContents(t, dir, firstFile, secondFile) + + c.time = time.Date(2021, 11, 13, 0, 0, 0, 0, time.Local) + + Rotate(t, r) + AssertDirContents(t, dir, firstFile, secondFile) + + WriteMsg(t, r) + thirdFile := fmt.Sprintf("%s-%s.ndjson", logname, c.Now().Format(file.DateFormat)) + AssertDirContents(t, dir, firstFile, secondFile, thirdFile) + + c.time = time.Date(2021, 11, 14, 0, 0, 0, 0, time.Local) + Rotate(t, r) + AssertDirContents(t, dir, secondFile, thirdFile) + + c.time = time.Date(2021, 11, 15, 0, 0, 0, 0, time.Local) + Rotate(t, r) + AssertDirContents(t, dir, secondFile, thirdFile) +} + +func TestFileRotatorConcurrently(t *testing.T) { + dir := t.TempDir() + + filename := filepath.Join(dir, "sample") + r, err := file.NewFileRotator(filename, file.MaxBackups(2)) + if err != nil { + t.Fatal(err) + } + defer r.Close() + + var wg sync.WaitGroup + wg.Add(1000) + for i := 0; i < 1000; i++ { + go func() { + defer wg.Done() + WriteMsg(t, r) + }() + } + wg.Wait() +} + +func TestDailyRotation(t *testing.T) { + dir := t.TempDir() + + logname := "daily" + yesterday := time.Now().AddDate(0, 0, -1).Format(file.DateFormat) + twoDaysAgo := time.Now().AddDate(0, 0, -2).Format(file.DateFormat) + + // seed directory with existing log files + files := []string{ + logname + "-" + yesterday + "-1.ndjson", + logname + "-" + yesterday + "-2.ndjson", + logname + "-" + yesterday + "-3.ndjson", + logname + "-" + yesterday + "-4.ndjson", + logname + "-" + yesterday + "-5.ndjson", + logname + "-" + yesterday + "-6.ndjson", + logname + "-" + yesterday + "-7.ndjson", + logname + "-" + yesterday + "-8.ndjson", + logname + "-" + yesterday + "-9.ndjson", + logname + "-" + yesterday + "-10.ndjson", + logname + "-" + yesterday + "-11.ndjson", + logname + "-" + yesterday + "-12.ndjson", + logname + "-" + yesterday + "-13.ndjson", + logname + "-" + twoDaysAgo + "-1.ndjson", + logname + "-" + twoDaysAgo + "-2.ndjson", + logname + "-" + twoDaysAgo + "-3.ndjson", + } + + for _, f := range files { + CreateFile(t, filepath.Join(dir, f)) + } + + maxSizeBytes := uint(500) + filename := filepath.Join(dir, logname) + r, err := file.NewFileRotator(filename, file.MaxBackups(2), file.Interval(24*time.Hour), file.MaxSizeBytes(maxSizeBytes)) + if err != nil { + t.Fatal(err) + } + defer r.Close() + + // The backups exceeding the max of 2 aren't deleted until the first rotation. + AssertDirContents(t, dir, files...) + + Rotate(t, r) + + AssertDirContents(t, dir, logname+"-"+yesterday+"-12.ndjson", logname+"-"+yesterday+"-13.ndjson") + + WriteMsg(t, r) + + today := time.Now().Format(file.DateFormat) + AssertDirContents(t, dir, logname+"-"+yesterday+"-12.ndjson", logname+"-"+yesterday+"-13.ndjson", logname+"-"+today+".ndjson") + + Rotate(t, r) + + AssertDirContents(t, dir, logname+"-"+yesterday+"-13.ndjson", logname+"-"+today+".ndjson") + + WriteMsg(t, r) + + AssertDirContents(t, dir, logname+"-"+yesterday+"-13.ndjson", logname+"-"+today+".ndjson", logname+"-"+today+"-1.ndjson") + + for i := 0; i < (int(maxSizeBytes)/len(logMessage))+1; i++ { + WriteMsg(t, r) + } + + AssertDirContents(t, dir, logname+"-"+today+"-1.ndjson", logname+"-"+today+"-2.ndjson", logname+"-"+today+"-3.ndjson") +} + +// Tests the FileConfig.RotateOnStartup parameter +func TestRotateOnStartup(t *testing.T) { + dir := t.TempDir() + + logname := "rotate_on_open" + c := &testClock{time.Date(2021, 11, 11, 0, 0, 0, 0, time.Local)} + firstFile := fmt.Sprintf("%s-%s.ndjson", logname, c.Now().Format(file.DateFormat)) + filename := filepath.Join(dir, firstFile) + + // Create an existing log file with this name. + CreateFile(t, filename) + AssertDirContents(t, dir, firstFile) + + r, err := file.NewFileRotator(filepath.Join(dir, logname), file.RotateOnStartup(false), file.WithClock(c)) + if err != nil { + t.Fatal(err) + } + defer r.Close() + WriteMsg(t, r) + + // The line should have been appended to the existing file without rotation. + AssertDirContents(t, dir, firstFile) + + // Close the first rotator early (the deferred close will be a no-op if + // we haven't hit an error by now), so it can't interfere with the second one. + r.Close() + + // Create a second rotator with the default setting of rotateOnStartup=true + c = &testClock{time.Date(2021, 11, 12, 0, 0, 0, 0, time.Local)} + r, err = file.NewFileRotator(filepath.Join(dir, logname), file.WithClock(c)) + if err != nil { + t.Fatal(err) + } + defer r.Close() + + // The directory contents shouldn't change until the first Write. + AssertDirContents(t, dir, firstFile) + + secondFile := fmt.Sprintf("%s-%s.ndjson", logname, c.Now().Format(file.DateFormat)) + + WriteMsg(t, r) + AssertDirContents(t, dir, firstFile, secondFile) +} + +func TestRotate(t *testing.T) { + dir := t.TempDir() + + logname := "beatname" + filename := filepath.Join(dir, logname) + + c := &testClock{time.Date(2021, 11, 11, 0, 0, 0, 0, time.Local)} + r, err := file.NewFileRotator(filename, file.MaxBackups(1), file.WithClock(c)) + if err != nil { + t.Fatal(err) + } + defer r.Close() + + WriteMsg(t, r) + + firstFile := fmt.Sprintf("%s-%s.ndjson", logname, c.Now().Format(file.DateFormat)) + AssertDirContents(t, dir, firstFile) + + c.time = time.Date(2021, 11, 13, 0, 0, 0, 0, time.Local) + secondFile := fmt.Sprintf("%s-%s.ndjson", logname, c.Now().Format(file.DateFormat)) + + Rotate(t, r) + WriteMsg(t, r) + + AssertDirContents(t, dir, firstFile, secondFile) + + c.time = time.Date(2021, 11, 15, 0, 0, 0, 0, time.Local) + thirdFile := fmt.Sprintf("%s-%s.ndjson", logname, c.Now().Format(file.DateFormat)) + + Rotate(t, r) + WriteMsg(t, r) + + AssertDirContents(t, dir, secondFile, thirdFile) +} + +func CreateFile(t *testing.T, filename string) { + t.Helper() + f, err := os.Create(filename) + if err != nil { + t.Fatal(err) + } + err = f.Close() + if err != nil { + t.Fatal(err) + } +} + +func AssertDirContents(t *testing.T, dir string, files ...string) { + t.Helper() + + f, err := os.Open(dir) + if err != nil { + t.Fatal(err) + } + + names, err := f.Readdirnames(-1) + if err != nil { + t.Fatal(err) + } + + assert.ElementsMatch(t, files, names) +} + +func WriteMsg(t *testing.T, r *file.Rotator) { + t.Helper() + + n, err := r.Write([]byte(logMessage)) + if err != nil { + t.Fatal(err) + } + assert.Equal(t, len(logMessage), n) +} + +func Rotate(t *testing.T, r *file.Rotator) { + t.Helper() + + if err := r.Rotate(); err != nil { + t.Fatal(err) + } +} + +type testClock struct { + time time.Time +} + +func (t testClock) Now() time.Time { + return t.time +} diff --git a/file/stderr_other.go b/file/stderr_other.go new file mode 100644 index 00000000000..d6454ee6804 --- /dev/null +++ b/file/stderr_other.go @@ -0,0 +1,33 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//go:build !windows +// +build !windows + +package file + +import ( + "os" + + "golang.org/x/sys/unix" +) + +// RedirectStandardError causes all standard error output to be directed to the +// given file. +func RedirectStandardError(toFile *os.File) error { + return unix.Dup2(int(toFile.Fd()), 2) +} diff --git a/file/stderr_windows.go b/file/stderr_windows.go new file mode 100644 index 00000000000..f256470b6f1 --- /dev/null +++ b/file/stderr_windows.go @@ -0,0 +1,30 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package file + +import ( + "os" + + "golang.org/x/sys/windows" +) + +// RedirectStandardError causes all standard error output to be directed to the +// given file. +func RedirectStandardError(toFile *os.File) error { + return windows.SetStdHandle(windows.STD_ERROR_HANDLE, windows.Handle(toFile.Fd())) +} diff --git a/file/trigger.go b/file/trigger.go new file mode 100644 index 00000000000..22c128a334b --- /dev/null +++ b/file/trigger.go @@ -0,0 +1,182 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package file + +import ( + "time" +) + +// rotateReason is the reason why file rotation occurred. +type rotateReason uint32 + +const ( + rotateReasonNoRotate rotateReason = iota + rotateReasonInitializing + rotateReasonFileSize + rotateReasonManualTrigger + rotateReasonTimeInterval +) + +func (rr rotateReason) String() string { + switch rr { + case rotateReasonInitializing: + return "initializing" + case rotateReasonFileSize: + return "file size" + case rotateReasonManualTrigger: + return "manual trigger" + case rotateReasonTimeInterval: + return "time interval" + default: + return "unknown" + } +} + +// trigger interface causes the log writer to rotate the active file. +type trigger interface { + TriggerRotation(dataLen uint) rotateReason +} + +func newTriggers(rotateOnStartup bool, interval time.Duration, maxSizeBytes uint, clock clock) []trigger { + triggers := make([]trigger, 0) + + if rotateOnStartup { + triggers = append(triggers, &initTrigger{}) + } + if interval > 0 { + triggers = append(triggers, newIntervalTrigger(interval, clock)) + } + if maxSizeBytes > 0 { + triggers = append(triggers, &sizeTrigger{maxSizeBytes: maxSizeBytes, size: 0}) + } + return triggers +} + +// initTrigger is triggered once on startup. +type initTrigger struct { + triggered bool +} + +func (t *initTrigger) TriggerRotation(_ uint) rotateReason { + if !t.triggered { + t.triggered = true + return rotateReasonInitializing + } + return rotateReasonNoRotate +} + +// sizeTrigger starts a rotation when the file reaches the configured size. +type sizeTrigger struct { + maxSizeBytes uint + size uint +} + +func (t *sizeTrigger) TriggerRotation(dataLen uint) rotateReason { + if t.size+dataLen > t.maxSizeBytes { + t.size = 0 + return rotateReasonFileSize + } + t.size += dataLen + return rotateReasonNoRotate +} + +// intervalTrigger rotates the files after the configured interval. +type intervalTrigger struct { + interval time.Duration + clock clock + lastRotate time.Time + newInterval func(lastTime time.Time, currentTime time.Time) bool +} + +type clock interface { + Now() time.Time +} + +type realClock struct{} + +func (realClock) Now() time.Time { + return time.Now() +} + +func newIntervalTrigger(interval time.Duration, clock clock) trigger { + t := intervalTrigger{interval: interval, clock: clock} + + switch interval { + case time.Second: + t.newInterval = newSecond + case time.Minute: + t.newInterval = newMinute + case time.Hour: + t.newInterval = newHour + case 24 * time.Hour: // calendar day + t.newInterval = newDay + case 7 * 24 * time.Hour: // calendar week + t.newInterval = newWeek + case 30 * 24 * time.Hour: // calendar month + t.newInterval = newMonth + case 365 * 24 * time.Hour: // calendar year + t.newInterval = newYear + default: + t.newInterval = func(lastTime time.Time, currentTime time.Time) bool { + lastInterval := lastTime.Unix() / (int64(t.interval) / int64(time.Second)) + currentInterval := currentTime.Unix() / (int64(t.interval) / int64(time.Second)) + return lastInterval != currentInterval + } + } + return &t +} + +func (t *intervalTrigger) TriggerRotation(_ uint) rotateReason { + now := t.clock.Now() + if t.newInterval(t.lastRotate, now) { + t.lastRotate = now + return rotateReasonTimeInterval + } + return rotateReasonNoRotate +} + +func newSecond(lastTime time.Time, currentTime time.Time) bool { + return lastTime.Second() != currentTime.Second() || newMinute(lastTime, currentTime) +} + +func newMinute(lastTime time.Time, currentTime time.Time) bool { + return lastTime.Minute() != currentTime.Minute() || newHour(lastTime, currentTime) +} + +func newHour(lastTime time.Time, currentTime time.Time) bool { + return lastTime.Hour() != currentTime.Hour() || newDay(lastTime, currentTime) +} + +func newDay(lastTime time.Time, currentTime time.Time) bool { + return lastTime.Day() != currentTime.Day() || newMonth(lastTime, currentTime) +} + +func newWeek(lastTime time.Time, currentTime time.Time) bool { + lastYear, lastWeek := lastTime.ISOWeek() + currentYear, currentWeek := currentTime.ISOWeek() + return lastWeek != currentWeek || + lastYear != currentYear +} + +func newMonth(lastTime time.Time, currentTime time.Time) bool { + return lastTime.Month() != currentTime.Month() || newYear(lastTime, currentTime) +} + +func newYear(lastTime time.Time, currentTime time.Time) bool { + return lastTime.Year() != currentTime.Year() +} diff --git a/go.mod b/go.mod index f18f3a82aab..eb9f4c4ae42 100644 --- a/go.mod +++ b/go.mod @@ -4,12 +4,24 @@ go 1.17 require ( github.com/elastic/go-ucfg v0.8.4 + github.com/hashicorp/go-multierror v1.1.1 github.com/magefile/mage v1.12.1 - github.com/stretchr/testify v1.4.0 + github.com/pkg/errors v0.9.1 + github.com/spf13/cobra v1.3.0 + github.com/stretchr/testify v1.7.0 + go.elastic.co/ecszap v1.0.0 + go.uber.org/zap v1.21.0 + golang.org/x/sys v0.0.0-20220209214540-3681064d5158 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect + github.com/hashicorp/errwrap v1.0.0 // indirect + github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - gopkg.in/yaml.v2 v2.2.8 // indirect + github.com/spf13/pflag v1.0.5 // indirect + go.uber.org/atomic v1.7.0 // indirect + go.uber.org/multierr v1.6.0 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect + gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect ) diff --git a/go.sum b/go.sum index 4044af64dd6..e4e9e762c34 100644 --- a/go.sum +++ b/go.sum @@ -1,24 +1,798 @@ -github.com/magefile/mage v1.12.1 h1:oGdAbhIUd6iKamKlDGVtU6XGdy5SgNuCWn7gCTgHDtU= -github.com/magefile/mage v1.12.1/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A= +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= +cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= +cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= +cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= +cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= +cloud.google.com/go v0.50.0/go.mod h1:r9sluTvynVuxRIOHXQEHMFffphuXHOMZMycpNR5e6To= +cloud.google.com/go v0.52.0/go.mod h1:pXajvRH/6o3+F9jDHZWQ5PbGhn+o8w9qiu/CffaVdO4= +cloud.google.com/go v0.53.0/go.mod h1:fp/UouUEsRkN6ryDKNW/Upv/JBKnv6WDthjR6+vze6M= +cloud.google.com/go v0.54.0/go.mod h1:1rq2OEkV3YMf6n/9ZvGWI3GWw0VoqH/1x2nd8Is/bPc= +cloud.google.com/go v0.56.0/go.mod h1:jr7tqZxxKOVYizybht9+26Z/gUq7tiRzu+ACVAMbKVk= +cloud.google.com/go v0.57.0/go.mod h1:oXiQ6Rzq3RAkkY7N6t3TcE6jE+CIBBbA36lwQ1JyzZs= +cloud.google.com/go v0.62.0/go.mod h1:jmCYTdRCQuc1PHIIJ/maLInMho30T/Y0M4hTdTShOYc= +cloud.google.com/go v0.65.0/go.mod h1:O5N8zS7uWy9vkA9vayVHs65eM1ubvY4h553ofrNHObY= +cloud.google.com/go v0.72.0/go.mod h1:M+5Vjvlc2wnp6tjzE102Dw08nGShTscUx2nZMufOKPI= +cloud.google.com/go v0.74.0/go.mod h1:VV1xSbzvo+9QJOxLDaJfTjx5e+MePCpCWwvftOeQmWk= +cloud.google.com/go v0.78.0/go.mod h1:QjdrLG0uq+YwhjoVOLsS1t7TW8fs36kLs4XO5R5ECHg= +cloud.google.com/go v0.79.0/go.mod h1:3bzgcEeQlzbuEAYu4mrWhKqWjmpprinYgKJLgKHnbb8= +cloud.google.com/go v0.81.0/go.mod h1:mk/AM35KwGk/Nm2YSeZbxXdrNK3KZOYHmLkOqC2V6E0= +cloud.google.com/go v0.83.0/go.mod h1:Z7MJUsANfY0pYPdw0lbnivPx4/vhy/e2FEkSkF7vAVY= +cloud.google.com/go v0.84.0/go.mod h1:RazrYuxIK6Kb7YrzzhPoLmCVzl7Sup4NrbKPg8KHSUM= +cloud.google.com/go v0.87.0/go.mod h1:TpDYlFy7vuLzZMMZ+B6iRiELaY7z/gJPaqbMx6mlWcY= +cloud.google.com/go v0.90.0/go.mod h1:kRX0mNRHe0e2rC6oNakvwQqzyDmg57xJ+SZU1eT2aDQ= +cloud.google.com/go v0.93.3/go.mod h1:8utlLll2EF5XMAV15woO4lSbWQlk8rer9aLOfLh7+YI= +cloud.google.com/go v0.94.1/go.mod h1:qAlAugsXlC+JWO+Bke5vCtc9ONxjQT3drlTTnAplMW4= +cloud.google.com/go v0.97.0/go.mod h1:GF7l59pYBVlXQIBLx3a761cZ41F9bBH3JUlihCt2Udc= +cloud.google.com/go v0.98.0/go.mod h1:ua6Ush4NALrHk5QXDWnjvZHN93OuF0HfuEPq9I1X0cM= +cloud.google.com/go v0.99.0/go.mod h1:w0Xx2nLzqWJPuozYQX+hFfCSI8WioryfRDzkoI/Y2ZA= +cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= +cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE= +cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvftPBK2Dvzc= +cloud.google.com/go/bigquery v1.5.0/go.mod h1:snEHRnqQbz117VIFhE8bmtwIDY80NLUZUMb4Nv6dBIg= +cloud.google.com/go/bigquery v1.7.0/go.mod h1://okPTzCYNXSlb24MZs83e2Do+h+VXtc4gLoIoXIAPc= +cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM77hZzJN/fQ= +cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= +cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk= +cloud.google.com/go/firestore v1.6.1/go.mod h1:asNXNOzBdyVQmEU+ggO8UPodTkEVFW5Qx+rwHnAz+EY= +cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= +cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw= +cloud.google.com/go/pubsub v1.2.0/go.mod h1:jhfEVHT8odbXTkndysNHCcx0awwzvfOlguIAii9o8iA= +cloud.google.com/go/pubsub v1.3.1/go.mod h1:i+ucay31+CNRpDW4Lu78I4xXG+O1r/MAHgjpRVR+TSU= +cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= +cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos= +cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk= +cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= +cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= +dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= +github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= +github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= +github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= +github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= +github.com/armon/go-metrics v0.3.10/go.mod h1:4O98XIr/9W0sxpJ8UaYkvjk10Iff7SnFrb4QAOwNTFc= +github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= +github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= +github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= +github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= +github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= +github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= +github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/census-instrumentation/opencensus-proto v0.3.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= +github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= +github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= +github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= +github.com/circonus-labs/circonus-gometrics v2.3.1+incompatible/go.mod h1:nmEj6Dob7S7YxXgwXpfOuvO54S+tGdZdw9fuRZt25Ag= +github.com/circonus-labs/circonusllhist v0.1.3/go.mod h1:kMXHVDlOchFAehlya5ePtbp5jckzBHf4XRpQvBOLI+I= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= +github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= +github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= +github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4/go.mod h1:6pvJx4me5XPnfI9Z40ddWsdw2W/uZgQLFXToKeRcDiI= +github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cncf/xds/go v0.0.0-20211130200136-a8f946100490/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= +github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/elastic/go-ucfg v0.8.4 h1:OAHTnubzXKsYYYWVzl8psLcS5mCbNKjXxtMY41itthk= github.com/elastic/go-ucfg v0.8.4/go.mod h1:4E8mPOLSUV9hQ7sgLEJ4bvt0KhMuDJa8joDT2QGAEKA= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= +github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po= +github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= +github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= +github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ= +github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0= +github.com/envoyproxy/go-control-plane v0.10.1/go.mod h1:AY7fTTXNdv/aJ2O5jwpxAPOWUZ7hQAEvzN5Pf27BkQQ= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/envoyproxy/protoc-gen-validate v0.6.2/go.mod h1:2t7qjJNvHPx8IjnBOzl9E9/baC+qXE/TeeyBRzgJDws= +github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= +github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU= +github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= +github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5Ai1i3InKU= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= +github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= +github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= +github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= +github.com/golang/mock v1.5.0/go.mod h1:CWnOUgYIOo4TcNZ0wHX3YZCqsaM1I1Jvs6v3mP3KVu8= +github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.1/go.mod h1:DopwsBzvsk0Fs44TXzsVbJyPhcCPeIwnvohx4u74HPM= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= +github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= +github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= +github.com/google/martian/v3 v3.2.1/go.mod h1:oBOf6HBosgwRXnUGWUB05QECsc6uvmMiJ3+6W4l/CUk= +github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20201023163331-3e6fc7fc9c4c/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20210122040257-d980be63207e/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20210601050228-01bbb1931b22/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20210609004039-a478d1d731e9/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= +github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= +github.com/googleapis/gax-go/v2 v2.1.0/go.mod h1:Q3nei7sK6ybPYH7twZdmQpAd1MKb7pfu6SK+H1/DsU0= +github.com/googleapis/gax-go/v2 v2.1.1/go.mod h1:hddJymUZASv3XPyGkUpKj8pPO47Rmb0eJc8R6ouapiM= +github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= +github.com/hashicorp/consul/api v1.11.0/go.mod h1:XjsvQN+RJGWI2TWy1/kqaE16HrR2J/FWgkYjdZQsX9M= +github.com/hashicorp/consul/sdk v0.8.0/go.mod h1:GBvyrGALthsZObzUGsfgHZQDXjg4lOjagTIwIR1vPms= +github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= +github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= +github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= +github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= +github.com/hashicorp/go-hclog v0.12.0/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= +github.com/hashicorp/go-hclog v1.0.0/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= +github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= +github.com/hashicorp/go-immutable-radix v1.3.1/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= +github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= +github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= +github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+vmowP0z+KUhOZdA= +github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= +github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= +github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs= +github.com/hashicorp/go-rootcerts v1.0.2/go.mod h1:pqUvnprVnM5bf7AOirdbb01K4ccR319Vf4pU3K5EGc8= +github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU= +github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4= +github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= +github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= +github.com/hashicorp/mdns v1.0.1/go.mod h1:4gW7WsVCke5TE7EPeYliwHlRUyBtfCwuFwuMg2DmyNY= +github.com/hashicorp/mdns v1.0.4/go.mod h1:mtBihi+LeNXGtG8L9dX59gAEa12BDtBQSp4v/YAJqrc= +github.com/hashicorp/memberlist v0.2.2/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOnAH9VT3Sh9MUE= +github.com/hashicorp/memberlist v0.3.0/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOnAH9VT3Sh9MUE= +github.com/hashicorp/serf v0.9.5/go.mod h1:UWDWwZeL5cuWDJdl0C6wrvrUwEqtQ4ZKBKKENpqIUyk= +github.com/hashicorp/serf v0.9.6/go.mod h1:TXZNMjZQijwlDvp+r0b63xZ45H7JmCmgg4gpTwn9UV4= +github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= +github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= +github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= +github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= +github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= +github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= +github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= +github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= +github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= +github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/lyft/protoc-gen-star v0.5.3/go.mod h1:V0xaHgaf5oCCqmcxYcWiDfTiKsZsRc87/1qhoTACD8w= +github.com/magefile/mage v1.9.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A= +github.com/magefile/mage v1.12.1 h1:oGdAbhIUd6iKamKlDGVtU6XGdy5SgNuCWn7gCTgHDtU= +github.com/magefile/mage v1.12.1/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A= +github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= +github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= +github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= +github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= +github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= +github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= +github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= +github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= +github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= +github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= +github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= +github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso= +github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI= +github.com/mitchellh/cli v1.1.0/go.mod h1:xcISNoH86gajksDmfB23e/pu+B+GeFRMYmoHXxx3xhI= +github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= +github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/mitchellh/mapstructure v1.4.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= +github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= +github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= +github.com/pelletier/go-toml v1.9.4/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= +github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s= +github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= +github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= +github.com/prometheus/client_golang v1.4.0/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU= +github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= +github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= +github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= +github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= +github.com/sagikazarmark/crypt v0.3.0/go.mod h1:uD/D+6UF4SrIR1uGEv7bBNkNqLGqUr43MRiaGWX1Nig= +github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= +github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= +github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/spf13/afero v1.3.3/go.mod h1:5KUK8ByomD5Ti5Artl0RtHeI5pTF7MIDuXL3yY520V4= +github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I= +github.com/spf13/cast v1.4.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= +github.com/spf13/cobra v1.3.0 h1:R7cSvGu+Vv+qX0gW5R/85dx2kmmJT5z5NM8ifdYjdn0= +github.com/spf13/cobra v1.3.0/go.mod h1:BrRVncBjOJa/eUcVVm9CE+oC6as8k+VYr4NY7WCi9V4= +github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/viper v1.10.0/go.mod h1:SoyBPwAtKDzypXNDFKN5kzH7ppppbGZtls1UpIy5AsM= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.5.0/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= +github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= +github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +go.elastic.co/ecszap v1.0.0 h1:PdQkRUeraR3XHJ14T7JMa+ncU0XXrVrcEN/BoRa2nMI= +go.elastic.co/ecszap v1.0.0/go.mod h1:HTUi+QRmr3EuZMqxPX+5fyOdMNfUu5iPebgfhgsTJYQ= +go.etcd.io/etcd/api/v3 v3.5.1/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs= +go.etcd.io/etcd/client/pkg/v3 v3.5.1/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g= +go.etcd.io/etcd/client/v2 v2.305.1/go.mod h1:pMEacxZW7o8pg4CrFE7pquyCJJzZvkvdD2RibOCCCGs= +go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= +go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= +go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= +go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E= +go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= +go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= +go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= +go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI= +go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= +go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= +go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4= +go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= +go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= +go.uber.org/zap v1.14.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= +go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo= +go.uber.org/zap v1.21.0 h1:WefMeulhovoZ2sYXz7st6K0sLj7bBhpiFaud4r4zST8= +go.uber.org/zap v1.21.0/go.mod h1:wjWOCqI0f2ZZrJF/UufIOkiC8ii6tm1iqIsLo76RfJw= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= +golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= +golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= +golang.org/x/exp v0.0.0-20191129062945-2f5052295587/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= +golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= +golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= +golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= +golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= +golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= +golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= +golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= +golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.5.0/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20201031054903-ff519b6c9102/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc= +golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= +golang.org/x/net v0.0.0-20210410081132-afb366fc7cd1/go.mod h1:9tjilg8BloeKEkVJvy7fQ90B1CfIiPueXVOjqfkSzI8= +golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20201109201403-9fd604954f58/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210220000619-9bb904979d93/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210313182246-cd4f82c27b84/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210805134026-6f1e6394065a/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20211005180243-6b3c2da341f1/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200501052902-10377860bb8e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200905004654-be1d3432aa8f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210305230114-8fe3ee5dd75b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210603125802-9665404d3644/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210816183151-1e6c022a8912/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210908233432-aa78b53d3365/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220209214540-3681064d5158 h1:rm+CHSpPEEW2IsXUib1ThaHIjuBVZjxNgSKmBLFfD4c= +golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20190907020128-2ca718005c18/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200117161641-43d50277825c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200122220014-bf1340f18c4a/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200204074204-1cc6d1ef6c74/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200227222343-706bc42d1f0d/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= +golang.org/x/tools v0.0.0-20200312045724-11d5b4c81c7d/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= +golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= +golang.org/x/tools v0.0.0-20200501065659-ab2804fb9c9d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200515010526-7d3b6ebf133d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200904185747-39188db58858/go.mod h1:Cj7w3i3Rnn0Xh82ur9kSqwfTHTeVxaDqrfMjpcNT6bE= +golang.org/x/tools v0.0.0-20201110124207-079ba7bd75cd/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.0.0-20201201161351-ac6f37ff4c2a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= +golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= +google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= +google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.14.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.15.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.17.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.18.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.19.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.20.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.22.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.24.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= +google.golang.org/api v0.28.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= +google.golang.org/api v0.29.0/go.mod h1:Lcubydp8VUV7KeIHD9z2Bys/sm/vGKnG1UHuDBSrHWM= +google.golang.org/api v0.30.0/go.mod h1:QGmEvQ87FHZNiUVJkT14jQNYJ4ZJjdRF23ZXz5138Fc= +google.golang.org/api v0.35.0/go.mod h1:/XrVsuzM0rZmrsbjJutiuftIzeuTQcEeaYcSk/mQ1dg= +google.golang.org/api v0.36.0/go.mod h1:+z5ficQTmoYpPn8LCUNVpK5I7hwkpjbcgqA7I34qYtE= +google.golang.org/api v0.40.0/go.mod h1:fYKFpnQN0DsDSKRVRcQSDQNtqWPfM9i+zNPxepjRCQ8= +google.golang.org/api v0.41.0/go.mod h1:RkxM5lITDfTzmyKFPt+wGrCJbVfniCr2ool8kTBzRTU= +google.golang.org/api v0.43.0/go.mod h1:nQsDGjRXMo4lvh5hP0TKqF244gqhGcr/YSIykhUk/94= +google.golang.org/api v0.47.0/go.mod h1:Wbvgpq1HddcWVtzsVLyfLp8lDg6AA241LmgIL59tHXo= +google.golang.org/api v0.48.0/go.mod h1:71Pr1vy+TAZRPkPs/xlCf5SsU8WjuAWv1Pfjbtukyy4= +google.golang.org/api v0.50.0/go.mod h1:4bNT5pAuq5ji4SRZm+5QIkjny9JAyVD/3gaSihNefaw= +google.golang.org/api v0.51.0/go.mod h1:t4HdrdoNgyN5cbEfm7Lum0lcLDLiise1F8qDKX00sOU= +google.golang.org/api v0.54.0/go.mod h1:7C4bFFOvVDGXjfDTAsgGwDgAxRDeQ4X8NvUedIt6z3k= +google.golang.org/api v0.55.0/go.mod h1:38yMfeP1kfjsl8isn0tliTjIb1rJXcQi4UXlbqivdVE= +google.golang.org/api v0.56.0/go.mod h1:38yMfeP1kfjsl8isn0tliTjIb1rJXcQi4UXlbqivdVE= +google.golang.org/api v0.57.0/go.mod h1:dVPlbZyBo2/OjBpmvNdpn2GRm6rPy75jyU7bmhdrMgI= +google.golang.org/api v0.59.0/go.mod h1:sT2boj7M9YJxZzgeZqXogmhfmRWDtPzT31xkieUbuZU= +google.golang.org/api v0.61.0/go.mod h1:xQRti5UdCmoCEqFxcz93fTl338AVqDgyaDRuOZ3hg9I= +google.golang.org/api v0.62.0/go.mod h1:dKmwPCydfsad4qCH08MSdgWjfHOyfpd4VtDGgRFdavw= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= +google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= +google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191115194625-c23dd37a84c9/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191230161307-f3c370f40bfb/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200115191322-ca5a22157cba/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200122232147-0452cf42e150/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200204135345-fa8e72b47b90/go.mod h1:GmwEX6Z4W5gMy59cAlVYjN9JhxgbQH6Gn+gFDQe2lzA= +google.golang.org/genproto v0.0.0-20200212174721-66ed5ce911ce/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200224152610-e50cd9704f63/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200228133532-8c2c7df3a383/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200305110556-506484158171/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200312145019-da6875a35672/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200511104702-f5ebc3bea380/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200515170657-fc4c6c6a6587/go.mod h1:YsZOwe1myG/8QRHRsmBRE1LrgQY60beZKjly0O1fX9U= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7FcilCzHH/e9qn6dsT145K34l5v+OpcnNgKAAA= +google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200904004341-0bd0a958aa1d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20201109203340-2640f1f9cdfb/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20201201144952-b05cb90ed32e/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20201210142538-e3217bee35cc/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20201214200347-8c77b98c765d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20210222152913-aa3ee6e6a81c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20210303154014-9728d6b83eeb/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20210310155132-4ce2db91004e/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20210319143718-93e7006c17a6/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20210402141018-6c239bbf2bb1/go.mod h1:9lPAdzaEmUacj36I+k7YKbEc5CXzPIeORRgDAUOu28A= +google.golang.org/genproto v0.0.0-20210513213006-bf773b8c8384/go.mod h1:P3QM42oQyzQSnHPnZ/vqoCdDmzH28fzWByN9asMeM8A= +google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= +google.golang.org/genproto v0.0.0-20210604141403-392c879c8b08/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= +google.golang.org/genproto v0.0.0-20210608205507-b6d2f5bf0d7d/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= +google.golang.org/genproto v0.0.0-20210624195500-8bfb893ecb84/go.mod h1:SzzZ/N+nwJDaO1kznhnlzqS8ocJICar6hYhVyhi++24= +google.golang.org/genproto v0.0.0-20210713002101-d411969a0d9a/go.mod h1:AxrInvYm1dci+enl5hChSFPOmmUF1+uAa/UsgNRWd7k= +google.golang.org/genproto v0.0.0-20210716133855-ce7ef5c701ea/go.mod h1:AxrInvYm1dci+enl5hChSFPOmmUF1+uAa/UsgNRWd7k= +google.golang.org/genproto v0.0.0-20210728212813-7823e685a01f/go.mod h1:ob2IJxKrgPT52GcgX759i1sleT07tiKowYBGbczaW48= +google.golang.org/genproto v0.0.0-20210805201207-89edb61ffb67/go.mod h1:ob2IJxKrgPT52GcgX759i1sleT07tiKowYBGbczaW48= +google.golang.org/genproto v0.0.0-20210813162853-db860fec028c/go.mod h1:cFeNkxwySK631ADgubI+/XFU/xp8FD5KIVV4rj8UC5w= +google.golang.org/genproto v0.0.0-20210821163610-241b8fcbd6c8/go.mod h1:eFjDcFEctNawg4eG61bRv87N7iHBWyVhJu7u1kqDUXY= +google.golang.org/genproto v0.0.0-20210828152312-66f60bf46e71/go.mod h1:eFjDcFEctNawg4eG61bRv87N7iHBWyVhJu7u1kqDUXY= +google.golang.org/genproto v0.0.0-20210831024726-fe130286e0e2/go.mod h1:eFjDcFEctNawg4eG61bRv87N7iHBWyVhJu7u1kqDUXY= +google.golang.org/genproto v0.0.0-20210903162649-d08c68adba83/go.mod h1:eFjDcFEctNawg4eG61bRv87N7iHBWyVhJu7u1kqDUXY= +google.golang.org/genproto v0.0.0-20210909211513-a8c4777a87af/go.mod h1:eFjDcFEctNawg4eG61bRv87N7iHBWyVhJu7u1kqDUXY= +google.golang.org/genproto v0.0.0-20210924002016-3dee208752a0/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= +google.golang.org/genproto v0.0.0-20211008145708-270636b82663/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= +google.golang.org/genproto v0.0.0-20211028162531-8db9c33dc351/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= +google.golang.org/genproto v0.0.0-20211118181313-81c1377c94b1/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= +google.golang.org/genproto v0.0.0-20211129164237-f09f9a12af12/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= +google.golang.org/genproto v0.0.0-20211203200212-54befc351ae9/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= +google.golang.org/genproto v0.0.0-20211206160659-862468c7d6e0/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= +google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= +google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= +google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60= +google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= +google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/grpc v1.31.1/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= +google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= +google.golang.org/grpc v1.34.0/go.mod h1:WotjhfgOW/POjDeRt8vscBtXq+2VjORFy659qA51WJ8= +google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= +google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= +google.golang.org/grpc v1.36.1/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= +google.golang.org/grpc v1.37.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= +google.golang.org/grpc v1.37.1/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= +google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= +google.golang.org/grpc v1.39.0/go.mod h1:PImNr+rS9TWYb2O4/emRugxiyHZ5JyHW5F+RPnDzfrE= +google.golang.org/grpc v1.39.1/go.mod h1:PImNr+rS9TWYb2O4/emRugxiyHZ5JyHW5F+RPnDzfrE= +google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34= +google.golang.org/grpc v1.40.1/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34= +google.golang.org/grpc v1.42.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU= +google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= +google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/hjson/hjson-go.v3 v3.0.1/go.mod h1:X6zrTSVeImfwfZLfgQdInl9mWjqPqgH90jom9nym/lw= +gopkg.in/ini.v1 v1.66.2/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= +gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= +honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= +honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= +rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= +rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= +rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= diff --git a/logp/config.go b/logp/config.go new file mode 100644 index 00000000000..83aace2bc80 --- /dev/null +++ b/logp/config.go @@ -0,0 +1,101 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package logp + +import ( + "time" +) + +// Config contains the configuration options for the logger. To create a Config +// from a common.Config use logp/config.Build. +type Config struct { + Beat string `config:",ignore"` // Name of the Beat (for default file name). + Level Level `config:"level"` // Logging level (error, warning, info, debug). + Selectors []string `config:"selectors"` // Selectors for debug level logging. + + toObserver bool + toIODiscard bool + ToStderr bool `config:"to_stderr" yaml:"to_stderr"` + ToSyslog bool `config:"to_syslog" yaml:"to_syslog"` + ToFiles bool `config:"to_files" yaml:"to_files"` + ToEventLog bool `config:"to_eventlog" yaml:"to_eventlog"` + + Files FileConfig `config:"files"` + Metrics MetricsConfig `config:"metrics"` + + environment Environment + addCaller bool // Adds package and line number info to messages. + development bool // Controls how DPanic behaves. + logsPath string +} + +// FileConfig contains the configuration options for the file output. +type FileConfig struct { + Path string `config:"path" yaml:"path"` + Name string `config:"name" yaml:"name"` + MaxSize uint `config:"rotateeverybytes" yaml:"rotateeverybytes" validate:"min=1"` + MaxBackups uint `config:"keepfiles" yaml:"keepfiles" validate:"max=1024"` + Permissions uint32 `config:"permissions"` + Interval time.Duration `config:"interval"` + RotateOnStartup bool `config:"rotateonstartup"` + RedirectStderr bool `config:"redirect_stderr" yaml:"redirect_stderr"` +} + +// MetricsConfig contains configuration used by the monitor to output metrics into the logstream. +// +// Currently these options are not used through this object in beats (as monitoring is setup elsewhere). +type MetricsConfig struct { + Enabled bool `config:"enabled"` + Period time.Duration `config:"period"` +} + +const ( + defaultLevel = InfoLevel +) + +// DefaultConfig returns the default config options for a given environment the +// Beat is supposed to be run within. +func DefaultConfig(environment Environment) Config { + return Config{ + Level: defaultLevel, + Files: FileConfig{ + MaxSize: 10 * 1024 * 1024, + MaxBackups: 7, + Permissions: 0600, + Interval: 0, + RotateOnStartup: true, + }, + Metrics: MetricsConfig{ + Enabled: true, + Period: 30 * time.Second, + }, + environment: environment, + addCaller: true, + } +} + +// LogFilename returns the base filename to which logs will be written for +// the "files" log output. If another log output is used, or `logging.files.name` +// is unspecified, then the beat name will be returned. +func (cfg Config) LogFilename() string { + name := cfg.Beat + if cfg.Files.Name != "" { + name = cfg.Files.Name + } + return name +} diff --git a/logp/configure/configure.png b/logp/configure/configure.png new file mode 100644 index 00000000000..444abc172c8 Binary files /dev/null and b/logp/configure/configure.png differ diff --git a/logp/configure/logging.go b/logp/configure/logging.go new file mode 100644 index 00000000000..f23e1792049 --- /dev/null +++ b/logp/configure/logging.go @@ -0,0 +1,107 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package configure + +import ( + "flag" + "fmt" + "strings" + + "go.uber.org/zap/zapcore" + + "github.com/elastic/elastic-agent-libs/config" + "github.com/elastic/elastic-agent-libs/logp" +) + +// CLI flags for configuring logging. +var ( + verbose bool + toStderr bool + debugSelectors []string + environment logp.Environment +) + +type environmentVar logp.Environment + +func init() { + flag.BoolVar(&verbose, "v", false, "Log at INFO level") + flag.BoolVar(&toStderr, "e", false, "Log to stderr and disable syslog/file output") + config.StringArrVarFlag(nil, &debugSelectors, "d", "Enable certain debug selectors") + flag.Var((*environmentVar)(&environment), "environment", "set environment being ran in") +} + +// Logging builds a logp.Config based on the given common.Config and the specified +// CLI flags. +func Logging(beatName string, cfg *config.C) error { + config := logp.DefaultConfig(environment) + config.Beat = beatName + if cfg != nil { + if err := cfg.Unpack(&config); err != nil { + return err + } + } + + applyFlags(&config) + return logp.Configure(config) +} + +// LoggingWithOutputs builds a logp.Config based on the given common.Config and the specified +// CLI flags along with the given outputs. +func LoggingWithOutputs(beatName string, cfg *config.C, outputs ...zapcore.Core) error { + config := logp.DefaultConfig(environment) + config.Beat = beatName + if cfg != nil { + if err := cfg.Unpack(&config); err != nil { + return err + } + } + + applyFlags(&config) + return logp.ConfigureWithOutputs(config, outputs...) +} + +func applyFlags(cfg *logp.Config) { + if toStderr { + cfg.ToStderr = true + } + if cfg.Level > logp.InfoLevel && verbose { + cfg.Level = logp.InfoLevel + } + for _, selectors := range debugSelectors { + cfg.Selectors = append(cfg.Selectors, strings.Split(selectors, ",")...) + } + + // Elevate level if selectors are specified on the CLI. + if len(debugSelectors) > 0 { + cfg.Level = logp.DebugLevel + } +} + +func (v *environmentVar) Set(in string) error { + env := logp.ParseEnvironment(in) + if env == logp.InvalidEnvironment { + return fmt.Errorf("'%v' is not supported", in) + } + + *(*logp.Environment)(v) = env + return nil +} + +func (v *environmentVar) String() string { + return (*logp.Environment)(v).String() +} diff --git a/logp/core.go b/logp/core.go new file mode 100644 index 00000000000..f4cdadf660c --- /dev/null +++ b/logp/core.go @@ -0,0 +1,332 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package logp + +import ( + "flag" + "io/ioutil" + golog "log" + "os" + "path/filepath" + "strings" + "sync/atomic" + "unsafe" + + "github.com/hashicorp/go-multierror" + + "github.com/pkg/errors" + "go.uber.org/zap" + "go.uber.org/zap/zapcore" + "go.uber.org/zap/zaptest/observer" + + "go.elastic.co/ecszap" + + "github.com/elastic/elastic-agent-libs/file" + "github.com/elastic/elastic-agent-libs/paths" +) + +var ( + _log unsafe.Pointer // Pointer to a coreLogger. Access via atomic.LoadPointer. + _defaultGoLog = golog.Writer() +) + +func init() { + storeLogger(&coreLogger{ + selectors: map[string]struct{}{}, + rootLogger: zap.NewNop(), + globalLogger: zap.NewNop(), + logger: newLogger(zap.NewNop(), ""), + }) +} + +type coreLogger struct { + selectors map[string]struct{} // Set of enabled debug selectors. + rootLogger *zap.Logger // Root logger without any options configured. + globalLogger *zap.Logger // Logger used by legacy global functions (e.g. logp.Info). + logger *Logger // Logger that is the basis for all logp.Loggers. + observedLogs *observer.ObservedLogs // Contains events generated while in observation mode (a testing mode). +} + +// Configure configures the logp package. +func Configure(cfg Config) error { + return ConfigureWithOutputs(cfg) +} + +// ConfigureWithOutputs XXX: is used by elastic-agent only (See file: x-pack/elastic-agent/pkg/core/logger/logger.go). +// The agent requires that the output specified in the config object is configured and merged with the +// logging outputs given. +func ConfigureWithOutputs(cfg Config, outputs ...zapcore.Core) error { + var ( + sink zapcore.Core + observedLogs *observer.ObservedLogs + err error + ) + + // Build a single output (stderr has priority if more than one are enabled). + if cfg.toObserver { + sink, observedLogs = observer.New(cfg.Level.ZapLevel()) + } else { + sink, err = createLogOutput(cfg) + } + if err != nil { + return errors.Wrap(err, "failed to build log output") + } + + // Default logger is always discard, debug level below will + // possibly re-enable it. + golog.SetOutput(ioutil.Discard) + + // Enabled selectors when debug is enabled. + selectors := make(map[string]struct{}, len(cfg.Selectors)) + if cfg.Level.Enabled(DebugLevel) && len(cfg.Selectors) > 0 { + for _, sel := range cfg.Selectors { + selectors[strings.TrimSpace(sel)] = struct{}{} + } + + // Default to all enabled if no selectors are specified. + if len(selectors) == 0 { + selectors["*"] = struct{}{} + } + + // Re-enable the default go logger output when either stdlog + // or all selector is enabled. + _, stdlogEnabled := selectors["stdlog"] + _, allEnabled := selectors["*"] + if stdlogEnabled || allEnabled { + golog.SetOutput(_defaultGoLog) + } + + sink = selectiveWrapper(sink, selectors) + } + + sink = newMultiCore(append(outputs, sink)...) + root := zap.New(sink, makeOptions(cfg)...) + storeLogger(&coreLogger{ + selectors: selectors, + rootLogger: root, + globalLogger: root.WithOptions(zap.AddCallerSkip(1)), + logger: newLogger(root, ""), + observedLogs: observedLogs, + }) + return nil +} + +func createLogOutput(cfg Config) (zapcore.Core, error) { + switch { + case cfg.toIODiscard: + return makeDiscardOutput(cfg) + case cfg.ToStderr: + return makeStderrOutput(cfg) + case cfg.ToSyslog: + return makeSyslogOutput(cfg) + case cfg.ToEventLog: + return makeEventLogOutput(cfg) + case cfg.ToFiles: + return makeFileOutput(cfg) + } + + switch cfg.environment { + case SystemdEnvironment, ContainerEnvironment: + return makeStderrOutput(cfg) + case MacOSServiceEnvironment, WindowsServiceEnvironment: + fallthrough + default: + return makeFileOutput(cfg) + } +} + +// DevelopmentSetup configures the logger in development mode at debug level. +// By default the output goes to stderr. +func DevelopmentSetup(options ...Option) error { + cfg := Config{ + Level: DebugLevel, + ToStderr: true, + development: true, + addCaller: true, + } + for _, apply := range options { + apply(&cfg) + } + return Configure(cfg) +} + +// TestingSetup configures logging by calling DevelopmentSetup if and only if +// verbose testing is enabled (as in 'go test -v'). +func TestingSetup(options ...Option) error { + // Use the flag to avoid a dependency on the testing package. + f := flag.Lookup("test.v") + if f != nil && f.Value.String() == "true" { + return DevelopmentSetup(options...) + } + return nil +} + +// ObserverLogs provides the list of logs generated during the observation +// process. +func ObserverLogs() *observer.ObservedLogs { + return loadLogger().observedLogs +} + +// Sync flushes any buffered log entries. Applications should take care to call +// Sync before exiting. +func Sync() error { + return loadLogger().rootLogger.Sync() +} + +func makeOptions(cfg Config) []zap.Option { + var options []zap.Option + if cfg.addCaller { + options = append(options, zap.AddCaller()) + } + if cfg.development { + options = append(options, zap.Development()) + } + if cfg.Beat != "" { + fields := []zap.Field{ + zap.String("service.name", cfg.Beat), + } + options = append(options, zap.Fields(fields...)) + } + return options +} + +func makeStderrOutput(cfg Config) (zapcore.Core, error) { + stderr := zapcore.Lock(os.Stderr) + return newCore(cfg, buildEncoder(cfg), stderr, cfg.Level.ZapLevel()), nil +} + +func makeDiscardOutput(cfg Config) (zapcore.Core, error) { + discard := zapcore.AddSync(ioutil.Discard) + return newCore(cfg, buildEncoder(cfg), discard, cfg.Level.ZapLevel()), nil +} + +func makeSyslogOutput(cfg Config) (zapcore.Core, error) { + core, err := newSyslog(buildEncoder(cfg), cfg.Level.ZapLevel()) + if err != nil { + return nil, err + } + return wrappedCore(cfg, core), nil +} + +func makeEventLogOutput(cfg Config) (zapcore.Core, error) { + core, err := newEventLog(cfg.Beat, buildEncoder(cfg), cfg.Level.ZapLevel()) + if err != nil { + return nil, err + } + return wrappedCore(cfg, core), nil +} + +func makeFileOutput(cfg Config) (zapcore.Core, error) { + filename := paths.Resolve(paths.Logs, filepath.Join(cfg.Files.Path, cfg.LogFilename())) + + rotator, err := file.NewFileRotator(filename, + file.MaxSizeBytes(cfg.Files.MaxSize), + file.MaxBackups(cfg.Files.MaxBackups), + file.Permissions(os.FileMode(cfg.Files.Permissions)), + file.Interval(cfg.Files.Interval), + file.RotateOnStartup(cfg.Files.RotateOnStartup), + file.RedirectStderr(cfg.Files.RedirectStderr), + ) + if err != nil { + return nil, errors.Wrap(err, "failed to create file rotator") + } + + return newCore(cfg, buildEncoder(cfg), rotator, cfg.Level.ZapLevel()), nil +} + +func newCore(cfg Config, enc zapcore.Encoder, ws zapcore.WriteSyncer, enab zapcore.LevelEnabler) zapcore.Core { + return wrappedCore(cfg, zapcore.NewCore(enc, ws, enab)) +} +func wrappedCore(cfg Config, core zapcore.Core) zapcore.Core { + return ecszap.WrapCore(core) +} + +func globalLogger() *zap.Logger { + return loadLogger().globalLogger +} + +func loadLogger() *coreLogger { + p := atomic.LoadPointer(&_log) + return (*coreLogger)(p) +} + +func storeLogger(l *coreLogger) { + if old := loadLogger(); old != nil { + old.rootLogger.Sync() + } + atomic.StorePointer(&_log, unsafe.Pointer(l)) +} + +// newMultiCore creates a sink that sends to multiple cores. +func newMultiCore(cores ...zapcore.Core) zapcore.Core { + return &multiCore{cores} +} + +// multiCore allows multiple cores to be used for logging. +type multiCore struct { + cores []zapcore.Core +} + +// Enabled returns true if the level is enabled in any one of the cores. +func (m multiCore) Enabled(level zapcore.Level) bool { + for _, core := range m.cores { + if core.Enabled(level) { + return true + } + } + return false +} + +// With creates a new multiCore with each core set with the given fields. +func (m multiCore) With(fields []zapcore.Field) zapcore.Core { + cores := make([]zapcore.Core, len(m.cores)) + for i, core := range m.cores { + cores[i] = core.With(fields) + } + return &multiCore{cores} +} + +// Check will place each core that checks for that entry. +func (m multiCore) Check(entry zapcore.Entry, checked *zapcore.CheckedEntry) *zapcore.CheckedEntry { + for _, core := range m.cores { + checked = core.Check(entry, checked) + } + return checked +} + +// Write writes the entry to each core. +func (m multiCore) Write(entry zapcore.Entry, fields []zapcore.Field) error { + var errs error + for _, core := range m.cores { + if err := core.Write(entry, fields); err != nil { + errs = multierror.Append(errs, err) + } + } + return errs +} + +// Sync syncs each core. +func (m multiCore) Sync() error { + var errs error + for _, core := range m.cores { + if err := core.Sync(); err != nil { + errs = multierror.Append(errs, err) + } + } + return errs +} diff --git a/logp/core_test.go b/logp/core_test.go new file mode 100644 index 00000000000..f8537eb6aa7 --- /dev/null +++ b/logp/core_test.go @@ -0,0 +1,172 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package logp + +import ( + "io/ioutil" + golog "log" + "testing" + + "github.com/stretchr/testify/assert" + "go.uber.org/zap" +) + +func TestLogger(t *testing.T) { + exerciseLogger := func() { + log := NewLogger("example") + log.Info("some message") + log.Infof("some message with parameter x=%v, y=%v", 1, 2) + log.Infow("some message", "x", 1, "y", 2) + log.Infow("some message", Int("x", 1)) + log.Infow("some message with namespaced args", Namespace("metrics"), "x", 1, "y", 1) + log.Infow("", "empty_message", true) + + // Add context. + log.With("x", 1, "y", 2).Warn("logger with context") + + someStruct := struct { + X int `json:"x"` + Y int `json:"y"` + }{1, 2} + log.Infow("some message with struct value", "metrics", someStruct) + } + + TestingSetup() + exerciseLogger() + TestingSetup() + exerciseLogger() +} + +func TestLoggerLevel(t *testing.T) { + if err := DevelopmentSetup(ToObserverOutput()); err != nil { + t.Fatal(err) + } + + const loggerName = "tester" + logger := NewLogger(loggerName) + + logger.Debug("debug") + logs := ObserverLogs().TakeAll() + if assert.Len(t, logs, 1) { + assert.Equal(t, zap.DebugLevel, logs[0].Level) + assert.Equal(t, loggerName, logs[0].LoggerName) + assert.Equal(t, "debug", logs[0].Message) + } + + logger.Info("info") + logs = ObserverLogs().TakeAll() + if assert.Len(t, logs, 1) { + assert.Equal(t, zap.InfoLevel, logs[0].Level) + assert.Equal(t, loggerName, logs[0].LoggerName) + assert.Equal(t, "info", logs[0].Message) + } + + logger.Warn("warn") + logs = ObserverLogs().TakeAll() + if assert.Len(t, logs, 1) { + assert.Equal(t, zap.WarnLevel, logs[0].Level) + assert.Equal(t, loggerName, logs[0].LoggerName) + assert.Equal(t, "warn", logs[0].Message) + } + + logger.Error("error") + logs = ObserverLogs().TakeAll() + if assert.Len(t, logs, 1) { + assert.Equal(t, zap.ErrorLevel, logs[0].Level) + assert.Equal(t, loggerName, logs[0].LoggerName) + assert.Equal(t, "error", logs[0].Message) + } +} + +func TestL(t *testing.T) { + if err := DevelopmentSetup(ToObserverOutput()); err != nil { + t.Fatal(err) + } + + L().Infow("infow", "rate", 2) + logs := ObserverLogs().TakeAll() + if assert.Len(t, logs, 1) { + log := logs[0] + assert.Equal(t, zap.InfoLevel, log.Level) + assert.Equal(t, "", log.LoggerName) + assert.Equal(t, "infow", log.Message) + assert.Contains(t, log.ContextMap(), "rate") + } + + const loggerName = "tester" + L().Named(loggerName).Warnf("warning %d", 1) + logs = ObserverLogs().TakeAll() + if assert.Len(t, logs, 1) { + log := logs[0] + assert.Equal(t, zap.WarnLevel, log.Level) + assert.Equal(t, loggerName, log.LoggerName) + assert.Equal(t, "warning 1", log.Message) + } +} + +func TestDebugAllStdoutEnablesDefaultGoLogger(t *testing.T) { + DevelopmentSetup(WithSelectors("*")) + assert.Equal(t, _defaultGoLog, golog.Writer()) + + DevelopmentSetup(WithSelectors("stdlog")) + assert.Equal(t, _defaultGoLog, golog.Writer()) + + DevelopmentSetup(WithSelectors("*", "stdlog")) + assert.Equal(t, _defaultGoLog, golog.Writer()) + + DevelopmentSetup(WithSelectors("other")) + assert.Equal(t, ioutil.Discard, golog.Writer()) +} + +func TestNotDebugAllStdoutDisablesDefaultGoLogger(t *testing.T) { + DevelopmentSetup(WithSelectors("*"), WithLevel(InfoLevel)) + assert.Equal(t, ioutil.Discard, golog.Writer()) + + DevelopmentSetup(WithSelectors("stdlog"), WithLevel(InfoLevel)) + assert.Equal(t, ioutil.Discard, golog.Writer()) + + DevelopmentSetup(WithSelectors("*", "stdlog"), WithLevel(InfoLevel)) + assert.Equal(t, ioutil.Discard, golog.Writer()) + + DevelopmentSetup(WithSelectors("other"), WithLevel(InfoLevel)) + assert.Equal(t, ioutil.Discard, golog.Writer()) +} + +func TestLoggingECSFields(t *testing.T) { + cfg := Config{ + Beat: "beat1", + Level: DebugLevel, + development: true, + Files: FileConfig{ + Name: "beat1", + }, + } + ToObserverOutput()(&cfg) + Configure(cfg) + + logger := NewLogger("tester") + + logger.Debug("debug") + logs := ObserverLogs().TakeAll() + if assert.Len(t, logs, 1) { + if assert.Len(t, logs[0].Context, 1) { + assert.Equal(t, "service.name", logs[0].Context[0].Key) + assert.Equal(t, "beat1", logs[0].Context[0].String) + } + } +} diff --git a/logp/encoding.go b/logp/encoding.go new file mode 100644 index 00000000000..a2f477fdce0 --- /dev/null +++ b/logp/encoding.go @@ -0,0 +1,80 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package logp + +import ( + "go.uber.org/zap/zapcore" + + "go.elastic.co/ecszap" +) + +var baseEncodingConfig = zapcore.EncoderConfig{ + TimeKey: "timestamp", + LevelKey: "level", + NameKey: "logger", + CallerKey: "caller", + MessageKey: "message", + StacktraceKey: "stacktrace", + LineEnding: zapcore.DefaultLineEnding, + EncodeLevel: zapcore.LowercaseLevelEncoder, + EncodeTime: zapcore.ISO8601TimeEncoder, + EncodeDuration: zapcore.NanosDurationEncoder, + EncodeCaller: zapcore.ShortCallerEncoder, + EncodeName: zapcore.FullNameEncoder, +} + +type encoderCreator func(cfg zapcore.EncoderConfig) zapcore.Encoder + +func buildEncoder(cfg Config) zapcore.Encoder { + var encCfg zapcore.EncoderConfig + var encCreator encoderCreator + if cfg.ToSyslog { + encCfg = SyslogEncoderConfig() + encCreator = zapcore.NewConsoleEncoder + } else { + encCfg = JSONEncoderConfig() + encCreator = zapcore.NewJSONEncoder + } + + encCfg = ecszap.ECSCompatibleEncoderConfig(encCfg) + return encCreator(encCfg) +} + +func JSONEncoderConfig() zapcore.EncoderConfig { + return baseEncodingConfig +} + +func ConsoleEncoderConfig() zapcore.EncoderConfig { + c := baseEncodingConfig + c.EncodeLevel = zapcore.CapitalLevelEncoder + c.EncodeName = bracketedNameEncoder + return c +} + +func SyslogEncoderConfig() zapcore.EncoderConfig { + c := ConsoleEncoderConfig() + // Time is generally added by syslog. + // But when logging with ECS the empty TimeKey will be + // ignored and @timestamp is still added to log line + c.TimeKey = "" + return c +} + +func bracketedNameEncoder(loggerName string, enc zapcore.PrimitiveArrayEncoder) { + enc.AppendString("[" + loggerName + "]") +} diff --git a/logp/environment.go b/logp/environment.go new file mode 100644 index 00000000000..ae74ba7d46b --- /dev/null +++ b/logp/environment.go @@ -0,0 +1,82 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package logp + +import "strings" + +// Environment indicates the environment the logger is supped to be run in. +// The default logger configuration may be different for different environments. +type Environment int + +const ( + // DefaultEnvironment is used if the environment the process runs in is not known. + DefaultEnvironment Environment = iota + + // SystemdEnvironment indicates that the process is started and managed by systemd. + SystemdEnvironment + + // ContainerEnvironment indicates that the process is running within a container (docker, k8s, rkt, ...). + ContainerEnvironment + + // MacOSServiceEnvironment indicates that the process is running as a daemon on macOS (e.g. managed via launchctl). + MacOSServiceEnvironment + + // WindowsServiceEnvironment indicates the the process is run as a windows service. + WindowsServiceEnvironment + + // InvalidEnvironment indicates that the environment name given is unknown or invalid. + InvalidEnvironment +) + +// String returns the string representation the configured environment +func (v Environment) String() string { + switch v { + case DefaultEnvironment: + return "default" + case SystemdEnvironment: + return "systemd" + case ContainerEnvironment: + return "container" + case MacOSServiceEnvironment: + return "macOS_service" + case WindowsServiceEnvironment: + return "windows_service" + default: + return "" + } +} + +// ParseEnvironment returns the environment type by name. +// The parse is case insensitive. +// InvalidEnvironment is returned if the environment type is unknown. +func ParseEnvironment(in string) Environment { + switch strings.ToLower(in) { + case "default": + return DefaultEnvironment + case "systemd": + return SystemdEnvironment + case "container": + return ContainerEnvironment + case "macos_service": + return MacOSServiceEnvironment + case "windows_service": + return WindowsServiceEnvironment + default: + return InvalidEnvironment + } +} diff --git a/logp/eventlog_unsupported.go b/logp/eventlog_unsupported.go new file mode 100644 index 00000000000..f63308170b7 --- /dev/null +++ b/logp/eventlog_unsupported.go @@ -0,0 +1,30 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//go:build !windows +// +build !windows + +package logp + +import ( + "github.com/pkg/errors" + "go.uber.org/zap/zapcore" +) + +func newEventLog(_ string, _ zapcore.Encoder, _ zapcore.LevelEnabler) (zapcore.Core, error) { + return nil, errors.New("eventlog is only supported on Windows") +} diff --git a/logp/eventlog_windows.go b/logp/eventlog_windows.go new file mode 100644 index 00000000000..8a5473a5d4a --- /dev/null +++ b/logp/eventlog_windows.go @@ -0,0 +1,109 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package logp + +import ( + "strings" + + "github.com/pkg/errors" + "go.uber.org/zap/zapcore" + "golang.org/x/sys/windows/svc/eventlog" +) + +const ( + // eventID is arbitrary but must be between [1-1000]. + eventID = 100 + supports = eventlog.Error | eventlog.Warning | eventlog.Info +) + +const alreadyExistsMsg = "registry key already exists" + +type eventLogCore struct { + zapcore.LevelEnabler + encoder zapcore.Encoder + fields []zapcore.Field + log *eventlog.Log +} + +func newEventLog(appName string, encoder zapcore.Encoder, enab zapcore.LevelEnabler) (zapcore.Core, error) { + if appName == "" { + return nil, errors.New("appName cannot be empty") + } + appName = strings.Title(strings.ToLower(appName)) + + if err := eventlog.InstallAsEventCreate(appName, supports); err != nil { + if !strings.Contains(err.Error(), alreadyExistsMsg) { + return nil, errors.Wrap(err, "failed to setup eventlog") + } + } + + log, err := eventlog.Open(appName) + if err != nil { + return nil, errors.Wrap(err, "failed to open eventlog") + } + + return &eventLogCore{ + LevelEnabler: enab, + encoder: encoder, + log: log, + }, nil +} + +func (c *eventLogCore) With(fields []zapcore.Field) zapcore.Core { + clone := c.Clone() + clone.fields = append(clone.fields, fields...) + return clone +} + +func (c *eventLogCore) Check(entry zapcore.Entry, checked *zapcore.CheckedEntry) *zapcore.CheckedEntry { + if c.Enabled(entry.Level) { + return checked.AddCore(entry, c) + } + return checked +} + +func (c *eventLogCore) Write(entry zapcore.Entry, fields []zapcore.Field) error { + buffer, err := c.encoder.EncodeEntry(entry, fields) + if err != nil { + return errors.Wrap(err, "failed to encode entry") + } + + msg := buffer.String() + switch entry.Level { + case zapcore.DebugLevel, zapcore.InfoLevel: + return c.log.Info(eventID, msg) + case zapcore.WarnLevel: + return c.log.Warning(eventID, msg) + case zapcore.ErrorLevel, zapcore.DPanicLevel, zapcore.PanicLevel, zapcore.FatalLevel: + return c.log.Error(eventID, msg) + default: + return errors.Errorf("unhandled log level: %v", entry.Level) + } +} + +func (c *eventLogCore) Sync() error { + return nil +} + +func (c *eventLogCore) Clone() *eventLogCore { + clone := *c + clone.encoder = c.encoder.Clone() + clone.fields = make([]zapcore.Field, len(c.fields), len(c.fields)+10) + copy(clone.fields, c.fields) + return &clone +} diff --git a/logp/fields.go b/logp/fields.go new file mode 100644 index 00000000000..d9d1655f250 --- /dev/null +++ b/logp/fields.go @@ -0,0 +1,76 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package logp + +import ( + "go.uber.org/zap" +) + +// Field types for structured logging. Most fields are lazily marshaled so it +// is inexpensive to add fields to disabled log statements. +var ( + Any = zap.Any + Array = zap.Array + Binary = zap.Binary + Bool = zap.Bool + Bools = zap.Bools + ByteString = zap.ByteString + ByteStrings = zap.ByteStrings + Complex64 = zap.Complex64 + Complex64s = zap.Complex64s + Complex128 = zap.Complex128 + Complex128s = zap.Complex128s + Duration = zap.Duration + Durations = zap.Durations + Error = zap.Error + Errors = zap.Errors + Float32 = zap.Float32 + Float32s = zap.Float32s + Float64 = zap.Float64 + Float64s = zap.Float64s + Int = zap.Int + Ints = zap.Ints + Int8 = zap.Int8 + Int8s = zap.Int8s + Int16 = zap.Int16 + Int16s = zap.Int16s + Int32 = zap.Int32 + Int32s = zap.Int32s + Int64 = zap.Int64 + Int64s = zap.Int64s + Namespace = zap.Namespace + Reflect = zap.Reflect + Stack = zap.Stack + String = zap.String + Stringer = zap.Stringer + Strings = zap.Strings + Time = zap.Time + Times = zap.Times + Uint = zap.Uint + Uints = zap.Uints + Uint8 = zap.Uint8 + Uint8s = zap.Uint8s + Uint16 = zap.Uint16 + Uint16s = zap.Uint16s + Uint32 = zap.Uint32 + Uint32s = zap.Uint32s + Uint64 = zap.Uint64 + Uint64s = zap.Uint64s + Uintptr = zap.Uintptr + Uintptrs = zap.Uintptrs +) diff --git a/logp/global.go b/logp/global.go new file mode 100644 index 00000000000..7a836aae026 --- /dev/null +++ b/logp/global.go @@ -0,0 +1,104 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//go:build !nologpglobal +// +build !nologpglobal + +package logp + +import ( + "fmt" + + "go.uber.org/zap" +) + +// MakeDebug returns a function that logs at debug level. +// Deprecated: Use logp.NewLogger. +func MakeDebug(selector string) func(string, ...interface{}) { + return func(format string, v ...interface{}) { + globalLogger().Named(selector).Debug(fmt.Sprintf(format, v...)) + } +} + +// IsDebug returns true if the given selector would be logged. +// Deprecated: Use logp.NewLogger. +func IsDebug(selector string) bool { + return globalLogger().Named(selector).Check(zap.DebugLevel, "") != nil +} + +// Debug uses fmt.Sprintf to construct and log a message. +// Deprecated: Use logp.NewLogger. +func Debug(selector string, format string, v ...interface{}) { + log := globalLogger() + if log.Core().Enabled(zap.DebugLevel) { + log.Named(selector).Debug(fmt.Sprintf(format, v...)) + } +} + +// Info uses fmt.Sprintf to construct and log a message. +// Deprecated: Use logp.NewLogger. +func Info(format string, v ...interface{}) { + log := globalLogger() + if log.Core().Enabled(zap.InfoLevel) { + log.Info(fmt.Sprintf(format, v...)) + } +} + +// Warn uses fmt.Sprintf to construct and log a message. +// Deprecated: Use logp.NewLogger. +func Warn(format string, v ...interface{}) { + log := globalLogger() + if log.Core().Enabled(zap.WarnLevel) { + globalLogger().Warn(fmt.Sprintf(format, v...)) + } +} + +// Err uses fmt.Sprintf to construct and log a message. +// Deprecated: Use logp.NewLogger. +func Err(format string, v ...interface{}) { + log := globalLogger() + if log.Core().Enabled(zap.ErrorLevel) { + globalLogger().Error(fmt.Sprintf(format, v...)) + } +} + +// Critical uses fmt.Sprintf to construct and log a message. It's an alias for +// Error. +// Deprecated: Use logp.NewLogger. +func Critical(format string, v ...interface{}) { + log := globalLogger() + if log.Core().Enabled(zap.ErrorLevel) { + globalLogger().Error(fmt.Sprintf(format, v...)) + } +} + +// WTF prints the message at PanicLevel and immediately panics with the same +// message. +// +// Deprecated: Use logp.NewLogger and its Panic or DPanic methods. +func WTF(format string, v ...interface{}) { + globalLogger().Panic(fmt.Sprintf(format, v...)) +} + +// Recover stops a panicking goroutine and logs an Error. +func Recover(msg string) { + if r := recover(); r != nil { + msg := fmt.Sprintf("%s. Recovering, but please report this.", msg) + globalLogger().WithOptions(zap.AddCallerSkip(1)). + Error(msg, zap.Any("panic", r), zap.Stack("stack")) + } +} diff --git a/logp/global_test.go b/logp/global_test.go new file mode 100644 index 00000000000..b0df4262805 --- /dev/null +++ b/logp/global_test.go @@ -0,0 +1,112 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//go:build !nologpglobal +// +build !nologpglobal + +package logp + +import ( + "strings" + "testing" + + "github.com/stretchr/testify/assert" + "go.uber.org/zap" +) + +func TestGlobalLoggerLevel(t *testing.T) { + if err := DevelopmentSetup(ToObserverOutput()); err != nil { + t.Fatal(err) + } + + const loggerName = "tester" + + Debug(loggerName, "debug") + logs := ObserverLogs().TakeAll() + if assert.Len(t, logs, 1) { + assert.Equal(t, zap.DebugLevel, logs[0].Level) + assert.Equal(t, loggerName, logs[0].LoggerName) + assert.Equal(t, "debug", logs[0].Message) + } + + Info("info") + logs = ObserverLogs().TakeAll() + if assert.Len(t, logs, 1) { + assert.Equal(t, zap.InfoLevel, logs[0].Level) + assert.Equal(t, "", logs[0].LoggerName) + assert.Equal(t, "info", logs[0].Message) + } + + Warn("warning") + logs = ObserverLogs().TakeAll() + if assert.Len(t, logs, 1) { + assert.Equal(t, zap.WarnLevel, logs[0].Level) + assert.Equal(t, "", logs[0].LoggerName) + assert.Equal(t, "warning", logs[0].Message) + } + + Err("error") + logs = ObserverLogs().TakeAll() + if assert.Len(t, logs, 1) { + assert.Equal(t, zap.ErrorLevel, logs[0].Level) + assert.Equal(t, "", logs[0].LoggerName) + assert.Equal(t, "error", logs[0].Message) + } + + Critical("critical") + logs = ObserverLogs().TakeAll() + if assert.Len(t, logs, 1) { + assert.Equal(t, zap.ErrorLevel, logs[0].Level) + assert.Equal(t, "", logs[0].LoggerName) + assert.Equal(t, "critical", logs[0].Message) + } +} + +func TestRecover(t *testing.T) { + const recoveryExplanation = "Something went wrong" + const cause = "unexpected condition" + + DevelopmentSetup(ToObserverOutput()) + + defer func() { + logs := ObserverLogs().TakeAll() + if assert.Len(t, logs, 1) { + log := logs[0] + assert.Equal(t, zap.ErrorLevel, log.Level) + assert.Equal(t, "logp/global_test.go", + strings.Split(log.Caller.TrimmedPath(), ":")[0]) + assert.Contains(t, log.Message, recoveryExplanation+ + ". Recovering, but please report this.") + assert.Contains(t, log.ContextMap(), "panic") + } + }() + + defer Recover(recoveryExplanation) + panic(cause) +} + +func TestIsDebug(t *testing.T) { + DevelopmentSetup() + assert.True(t, IsDebug("all")) + + DevelopmentSetup(WithSelectors("*")) + assert.True(t, IsDebug("all")) + + DevelopmentSetup(WithSelectors("only_this")) + assert.False(t, IsDebug("all")) + assert.True(t, IsDebug("only_this")) +} diff --git a/logp/level.go b/logp/level.go new file mode 100644 index 00000000000..f1699d46e53 --- /dev/null +++ b/logp/level.go @@ -0,0 +1,111 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package logp + +import ( + "fmt" + "strings" + + "github.com/pkg/errors" + "go.uber.org/zap/zapcore" +) + +// Level is a logging priority. Higher levels are more important. +type Level int8 + +// Logging levels. +const ( + DebugLevel Level = iota - 1 + InfoLevel + WarnLevel + ErrorLevel + CriticalLevel // Critical exists only for config backward compatibility. +) + +var levelStrings = map[Level]string{ + DebugLevel: "debug", + InfoLevel: "info", + WarnLevel: "warning", + ErrorLevel: "error", + CriticalLevel: "critical", +} + +var zapLevels = map[Level]zapcore.Level{ + DebugLevel: zapcore.DebugLevel, + InfoLevel: zapcore.InfoLevel, + WarnLevel: zapcore.WarnLevel, + ErrorLevel: zapcore.ErrorLevel, + CriticalLevel: zapcore.ErrorLevel, +} + +// String returns the name of the logging level. +func (l Level) String() string { + s, found := levelStrings[l] + if found { + return s + } + return fmt.Sprintf("Level(%d)", l) +} + +// Enabled returns true if given level is enabled. +func (l Level) Enabled(level Level) bool { + return level >= l +} + +// Unpack unmarshals a level string to a Level. This implements +// ucfg.StringUnpacker. +func (l *Level) Unpack(str string) error { + str = strings.ToLower(str) + for level, name := range levelStrings { + if name == str { + *l = level + return nil + } + } + + return errors.Errorf("invalid level '%v'", str) +} + +// MarshalYAML marshals level in a correct form +func (l Level) MarshalYAML() (interface{}, error) { + s, found := levelStrings[l] + if found { + return s, nil + } + + return nil, errors.Errorf("invalid level '%d'", l) +} + +// MarshalJSON marshals level in a correct form +func (l Level) MarshalJSON() ([]byte, error) { + s, found := levelStrings[l] + if found { + return []byte(s), nil + } + + return nil, errors.Errorf("invalid level '%d'", l) +} + +// ZapLevel returns zap alternative to logp.Level. +func (l Level) ZapLevel() zapcore.Level { + z, found := zapLevels[l] + if found { + return z + } + return zapcore.InfoLevel +} diff --git a/logp/logger.go b/logp/logger.go new file mode 100644 index 00000000000..2bbe6b3ce53 --- /dev/null +++ b/logp/logger.go @@ -0,0 +1,230 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package logp + +import ( + "fmt" + + "go.uber.org/zap" + "go.uber.org/zap/zapcore" +) + +// LogOption configures a Logger. +type LogOption = zap.Option + +// Logger logs messages to the configured output. +type Logger struct { + logger *zap.Logger + sugar *zap.SugaredLogger +} + +func newLogger(rootLogger *zap.Logger, selector string, options ...LogOption) *Logger { + log := rootLogger. + WithOptions(zap.AddCallerSkip(1)). + WithOptions(options...). + Named(selector) + return &Logger{log, log.Sugar()} +} + +// NewLogger returns a new Logger labeled with the name of the selector. This +// should never be used from any global contexts, otherwise you will receive a +// no-op Logger. This is because the logp package needs to be initialized first. +// Instead create new Logger instance that your object reuses. Or if you need to +// log from a static context then you may use logp.L().Infow(), for example. +func NewLogger(selector string, options ...LogOption) *Logger { + return newLogger(loadLogger().rootLogger, selector, options...) +} + +// WithOptions returns a clone of l with options applied. +func (l *Logger) WithOptions(options ...LogOption) *Logger { + cloned := l.logger.WithOptions(options...) + return &Logger{cloned, cloned.Sugar()} +} + +// With creates a child logger and adds structured context to it. Fields added +// to the child don't affect the parent, and vice versa. +func (l *Logger) With(args ...interface{}) *Logger { + sugar := l.sugar.With(args...) + return &Logger{sugar.Desugar(), sugar} +} + +// Named adds a new path segment to the logger's name. Segments are joined by +// periods. +func (l *Logger) Named(name string) *Logger { + logger := l.logger.Named(name) + return &Logger{logger, logger.Sugar()} +} + +// Sprint + +// Debug uses fmt.Sprint to construct and log a message. +func (l *Logger) Debug(args ...interface{}) { + l.sugar.Debug(args...) +} + +// Info uses fmt.Sprint to construct and log a message. +func (l *Logger) Info(args ...interface{}) { + l.sugar.Info(args...) +} + +// Warn uses fmt.Sprint to construct and log a message. +func (l *Logger) Warn(args ...interface{}) { + l.sugar.Warn(args...) +} + +// Error uses fmt.Sprint to construct and log a message. +func (l *Logger) Error(args ...interface{}) { + l.sugar.Error(args...) +} + +// Fatal uses fmt.Sprint to construct and log a message, then calls os.Exit(1). +func (l *Logger) Fatal(args ...interface{}) { + l.sugar.Fatal(args...) +} + +// Panic uses fmt.Sprint to construct and log a message, then panics. +func (l *Logger) Panic(args ...interface{}) { + l.sugar.Panic(args...) +} + +// DPanic uses fmt.Sprint to construct and log a message. In development, the +// logger then panics. +func (l *Logger) DPanic(args ...interface{}) { + l.sugar.DPanic(args...) +} + +// IsDebug checks to see if the given logger is Debug enabled. +func (l *Logger) IsDebug() bool { + return l.logger.Check(zapcore.DebugLevel, "") != nil +} + +// Sprintf + +// Debugf uses fmt.Sprintf to construct and log a message. +func (l *Logger) Debugf(format string, args ...interface{}) { + l.sugar.Debugf(format, args...) +} + +// Infof uses fmt.Sprintf to log a templated message. +func (l *Logger) Infof(format string, args ...interface{}) { + l.sugar.Infof(format, args...) +} + +// Warnf uses fmt.Sprintf to log a templated message. +func (l *Logger) Warnf(format string, args ...interface{}) { + l.sugar.Warnf(format, args...) +} + +// Errorf uses fmt.Sprintf to log a templated message. +func (l *Logger) Errorf(format string, args ...interface{}) { + l.sugar.Errorf(format, args...) +} + +// Fatalf uses fmt.Sprintf to log a templated message, then calls os.Exit(1). +func (l *Logger) Fatalf(format string, args ...interface{}) { + l.sugar.Fatalf(format, args...) +} + +// Panicf uses fmt.Sprintf to log a templated message, then panics. +func (l *Logger) Panicf(format string, args ...interface{}) { + l.sugar.Panicf(format, args...) +} + +// DPanicf uses fmt.Sprintf to log a templated message. In development, the +// logger then panics. +func (l *Logger) DPanicf(format string, args ...interface{}) { + l.sugar.DPanicf(format, args...) +} + +// With context (reflection based) + +// Debugw logs a message with some additional context. The additional context +// is added in the form of key-value pairs. The optimal way to write the value +// to the log message will be inferred by the value's type. To explicitly +// specify a type you can pass a Field such as logp.Stringer. +func (l *Logger) Debugw(msg string, keysAndValues ...interface{}) { + l.sugar.Debugw(msg, keysAndValues...) +} + +// Infow logs a message with some additional context. The additional context +// is added in the form of key-value pairs. The optimal way to write the value +// to the log message will be inferred by the value's type. To explicitly +// specify a type you can pass a Field such as logp.Stringer. +func (l *Logger) Infow(msg string, keysAndValues ...interface{}) { + l.sugar.Infow(msg, keysAndValues...) +} + +// Warnw logs a message with some additional context. The additional context +// is added in the form of key-value pairs. The optimal way to write the value +// to the log message will be inferred by the value's type. To explicitly +// specify a type you can pass a Field such as logp.Stringer. +func (l *Logger) Warnw(msg string, keysAndValues ...interface{}) { + l.sugar.Warnw(msg, keysAndValues...) +} + +// Errorw logs a message with some additional context. The additional context +// is added in the form of key-value pairs. The optimal way to write the value +// to the log message will be inferred by the value's type. To explicitly +// specify a type you can pass a Field such as logp.Stringer. +func (l *Logger) Errorw(msg string, keysAndValues ...interface{}) { + l.sugar.Errorw(msg, keysAndValues...) +} + +// Fatalw logs a message with some additional context, then calls os.Exit(1). +// The additional context is added in the form of key-value pairs. The optimal +// way to write the value to the log message will be inferred by the value's +// type. To explicitly specify a type you can pass a Field such as +// logp.Stringer. +func (l *Logger) Fatalw(msg string, keysAndValues ...interface{}) { + l.sugar.Fatalw(msg, keysAndValues...) +} + +// Panicw logs a message with some additional context, then panics. The +// additional context is added in the form of key-value pairs. The optimal way +// to write the value to the log message will be inferred by the value's type. +// To explicitly specify a type you can pass a Field such as logp.Stringer. +func (l *Logger) Panicw(msg string, keysAndValues ...interface{}) { + l.sugar.Panicw(msg, keysAndValues...) +} + +// DPanicw logs a message with some additional context. The logger panics only +// in Development mode. The additional context is added in the form of +// key-value pairs. The optimal way to write the value to the log message will +// be inferred by the value's type. To explicitly specify a type you can pass a +// Field such as logp.Stringer. +func (l *Logger) DPanicw(msg string, keysAndValues ...interface{}) { + l.sugar.DPanicw(msg, keysAndValues...) +} + +// Recover stops a panicking goroutine and logs an Error. +func (l *Logger) Recover(msg string) { + if r := recover(); r != nil { + msg := fmt.Sprintf("%s. Recovering, but please report this.", msg) + l.Error(msg, zap.Any("panic", r), zap.Stack("stack")) + } +} + +// Sync syncs the logger. +func (l *Logger) Sync() error { + return l.logger.Sync() +} + +// L returns an unnamed global logger. +func L() *Logger { + return loadLogger().logger +} diff --git a/logp/logger_test.go b/logp/logger_test.go new file mode 100644 index 00000000000..eaf8a1070ce --- /dev/null +++ b/logp/logger_test.go @@ -0,0 +1,52 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package logp + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "go.uber.org/zap" + "go.uber.org/zap/zapcore" + "go.uber.org/zap/zaptest/observer" +) + +func TestLoggerWithOptions(t *testing.T) { + core1, observed1 := observer.New(zapcore.DebugLevel) + core2, observed2 := observer.New(zapcore.DebugLevel) + + logger1 := NewLogger("bo", zap.WrapCore(func(in zapcore.Core) zapcore.Core { + return zapcore.NewTee(in, core1) + })) + logger2 := logger1.WithOptions(zap.WrapCore(func(in zapcore.Core) zapcore.Core { + return zapcore.NewTee(in, core2) + })) + + logger1.Info("hello logger1") // should just go to the first observer + logger2.Info("hello logger1 and logger2") // should go to both observers + + observedEntries1 := observed1.All() + require.Len(t, observedEntries1, 2) + assert.Equal(t, "hello logger1", observedEntries1[0].Message) + assert.Equal(t, "hello logger1 and logger2", observedEntries1[1].Message) + + observedEntries2 := observed2.All() + require.Len(t, observedEntries2, 1) + assert.Equal(t, "hello logger1 and logger2", observedEntries2[0].Message) +} diff --git a/logp/options.go b/logp/options.go new file mode 100644 index 00000000000..4b7efa373c0 --- /dev/null +++ b/logp/options.go @@ -0,0 +1,54 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package logp + +// Option configures the logp package behavior. +type Option func(cfg *Config) + +// WithLevel specifies the logging level. +func WithLevel(level Level) Option { + return func(cfg *Config) { + cfg.Level = level + } +} + +// WithSelectors specifies what debug selectors are enabled. If no selectors are +// specified then they are all enabled. +func WithSelectors(selectors ...string) Option { + return func(cfg *Config) { + cfg.Selectors = append(cfg.Selectors, selectors...) + } +} + +// ToObserverOutput specifies that the output should be collected in memory so +// that they can be read by an observer by calling ObserverLogs(). +func ToObserverOutput() Option { + return func(cfg *Config) { + cfg.toObserver = true + cfg.ToStderr = false + } +} + +// ToDiscardOutput configures the logger to write to io.Discard. This is for +// benchmarking purposes only. +func ToDiscardOutput() Option { + return func(cfg *Config) { + cfg.toIODiscard = true + cfg.ToStderr = false + } +} diff --git a/logp/selective.go b/logp/selective.go new file mode 100644 index 00000000000..cf73a3f7e6b --- /dev/null +++ b/logp/selective.go @@ -0,0 +1,89 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package logp + +import ( + "go.uber.org/zap/zapcore" +) + +type selectiveCore struct { + allSelectors bool + selectors map[string]struct{} + core zapcore.Core +} + +// HasSelector returns true if the given selector was explicitly set. +func HasSelector(selector string) bool { + _, found := loadLogger().selectors[selector] + return found +} + +func selectiveWrapper(core zapcore.Core, selectors map[string]struct{}) zapcore.Core { + if len(selectors) == 0 { + return core + } + _, allSelectors := selectors["*"] + return &selectiveCore{selectors: selectors, core: core, allSelectors: allSelectors} +} + +// Enabled returns whether a given logging level is enabled when logging a +// message. +func (c *selectiveCore) Enabled(level zapcore.Level) bool { + return c.core.Enabled(level) +} + +// With adds structured context to the Core. +func (c *selectiveCore) With(fields []zapcore.Field) zapcore.Core { + return selectiveWrapper(c.core.With(fields), c.selectors) +} + +// Check determines whether the supplied Entry should be logged (using the +// embedded LevelEnabler and possibly some extra logic). If the entry +// should be logged, the Core adds itself to the CheckedEntry and returns +// the result. +// +// Callers must use Check before calling Write. +func (c *selectiveCore) Check(ent zapcore.Entry, ce *zapcore.CheckedEntry) *zapcore.CheckedEntry { + if c.Enabled(ent.Level) { + if ent.Level == zapcore.DebugLevel { + if c.allSelectors { + return ce.AddCore(ent, c) + } else if _, enabled := c.selectors[ent.LoggerName]; enabled { + return ce.AddCore(ent, c) + } + return ce + } + + return ce.AddCore(ent, c) + } + return ce +} + +// Write serializes the Entry and any Fields supplied at the log site and +// writes them to their destination. +// +// If called, Write should always log the Entry and Fields; it should not +// replicate the logic of Check. +func (c *selectiveCore) Write(ent zapcore.Entry, fields []zapcore.Field) error { + return c.core.Write(ent, fields) +} + +// Sync flushes buffered logs (if any). +func (c *selectiveCore) Sync() error { + return c.core.Sync() +} diff --git a/logp/selective_test.go b/logp/selective_test.go new file mode 100644 index 00000000000..2fd90f89ecf --- /dev/null +++ b/logp/selective_test.go @@ -0,0 +1,54 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package logp + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestHasSelector(t *testing.T) { + DevelopmentSetup(WithSelectors("*", "config")) + assert.True(t, HasSelector("config")) + assert.False(t, HasSelector("publish")) +} + +func TestLoggerSelectors(t *testing.T) { + if err := DevelopmentSetup(WithSelectors("good", " padded "), ToObserverOutput()); err != nil { + t.Fatal(err) + } + + assert.True(t, HasSelector("padded")) + + good := NewLogger("good") + bad := NewLogger("bad") + + good.Debug("is logged") + logs := ObserverLogs().TakeAll() + assert.Len(t, logs, 1) + + // Selectors only apply to debug level logs. + bad.Debug("not logged") + logs = ObserverLogs().TakeAll() + assert.Len(t, logs, 0) + + bad.Info("is also logged") + logs = ObserverLogs().TakeAll() + assert.Len(t, logs, 1) +} diff --git a/logp/syslog_unix.go b/logp/syslog_unix.go new file mode 100644 index 00000000000..c6d28bde039 --- /dev/null +++ b/logp/syslog_unix.go @@ -0,0 +1,117 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//go:build !windows && !nacl && !plan9 +// +build !windows,!nacl,!plan9 + +package logp + +import ( + "log/syslog" + "os" + "path/filepath" + + "github.com/pkg/errors" + "go.uber.org/zap/zapcore" +) + +type syslogCore struct { + zapcore.LevelEnabler + encoder zapcore.Encoder + writer *syslog.Writer + fields []zapcore.Field +} + +// newSyslog returns a new Core that outputs to syslog. +func newSyslog(encoder zapcore.Encoder, enab zapcore.LevelEnabler) (zapcore.Core, error) { + // Initialize a syslog writer. + writer, err := syslog.New(syslog.LOG_ERR|syslog.LOG_LOCAL0, filepath.Base(os.Args[0])) + if err != nil { + return nil, errors.Wrap(err, "failed to get a syslog writer") + } + + return &syslogCore{ + LevelEnabler: enab, + encoder: encoder, + writer: writer, + }, nil +} + +func (c *syslogCore) With(fields []zapcore.Field) zapcore.Core { + clone := c.Clone() + clone.fields = append(clone.fields, fields...) + return clone +} + +func (c *syslogCore) Check(entry zapcore.Entry, checked *zapcore.CheckedEntry) *zapcore.CheckedEntry { + if c.Enabled(entry.Level) { + return checked.AddCore(entry, c) + } + return checked +} + +func (c *syslogCore) Write(entry zapcore.Entry, fields []zapcore.Field) error { + buffer, err := c.encoder.EncodeEntry(entry, fields) + if err != nil { + return errors.Wrap(err, "failed to encode entry") + } + + // Console encoder writes tabs which don't render nicely with syslog. + replaceTabsWithSpaces(buffer.Bytes(), 4) + + msg := buffer.String() + switch entry.Level { + case zapcore.DebugLevel: + return c.writer.Debug(msg) + case zapcore.InfoLevel: + return c.writer.Info(msg) + case zapcore.WarnLevel: + return c.writer.Warning(msg) + case zapcore.ErrorLevel: + return c.writer.Err(msg) + case zapcore.DPanicLevel, zapcore.PanicLevel, zapcore.FatalLevel: + return c.writer.Crit(msg) + default: + return errors.Errorf("unhandled log level: %v", entry.Level) + } +} + +func (c *syslogCore) Sync() error { + return nil +} + +func (c *syslogCore) Clone() *syslogCore { + clone := *c + clone.encoder = c.encoder.Clone() + clone.fields = make([]zapcore.Field, len(c.fields), len(c.fields)+10) + copy(clone.fields, c.fields) + return &clone +} + +func replaceTabsWithSpaces(b []byte, n int) { + var count = 0 + for i, v := range b { + if v == '\t' { + b[i] = ' ' + + count++ + if n >= 0 && count >= n { + return + } + } + } +} diff --git a/logp/syslog_unsupported.go b/logp/syslog_unsupported.go new file mode 100644 index 00000000000..677ded92d8d --- /dev/null +++ b/logp/syslog_unsupported.go @@ -0,0 +1,30 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//go:build windows || nacl || plan9 +// +build windows nacl plan9 + +package logp + +import ( + "github.com/pkg/errors" + "go.uber.org/zap/zapcore" +) + +func newSyslog(_ zapcore.Encoder, _ zapcore.LevelEnabler) (zapcore.Core, error) { + return nil, errors.New("syslog is not supported on this OS") +} diff --git a/paths/paths.go b/paths/paths.go new file mode 100644 index 00000000000..f73c0e34e97 --- /dev/null +++ b/paths/paths.go @@ -0,0 +1,161 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +// Package paths provides a common way to handle paths +// configuration for all Beats. +// +// Currently the following paths are defined: +// +// path.home - It’s the default folder for everything that doesn't fit in +// the categories below +// +// path.data - Contains things that are expected to change often during normal +// operations (“registry” files, UUID file, etc.) +// +// path.config - Configuration files and Elasticsearch template default location +// +// These settings can be set via the configuration file or via command line flags. +// The CLI flags overwrite the configuration file options. +// +// Use the Resolve function to resolve files to their absolute paths. For example, +// to look for a file in the config path: +// +// cfgfilePath := paths.Resolve(paths.Config, "beat.yml" +package paths + +import ( + "fmt" + "os" + "path/filepath" +) + +// Path tracks user-configurable path locations and directories +type Path struct { + Home string + Config string + Data string + Logs string +} + +// FileType is an enumeration type representing the file types. +// Currently existing file types are: Home, Config, Data +type FileType string + +const ( + // Home is the "root" directory for the running beats instance + Home FileType = "home" + // Config is the path to the beat config + Config FileType = "config" + // Data is the path to the beat data directory + Data FileType = "data" + // Logs is the path to the beats logs directory + Logs FileType = "logs" +) + +// Paths is the Path singleton on which the top level functions from this +// package operate. +var Paths = New() + +// New creates a new Paths object with all values set to empty values. +func New() *Path { + return &Path{} +} + +// InitPaths sets the default paths in the configuration based on CLI flags, +// configuration file and default values. It also tries to create the data +// path with mode 0750 and returns an error on failure. +func (paths *Path) InitPaths(cfg *Path) error { + err := paths.initPaths(cfg) + if err != nil { + return err + } + + // make sure the data path exists + err = os.MkdirAll(paths.Data, 0750) + if err != nil { + return fmt.Errorf("Failed to create data path %s: %v", paths.Data, err) + } + + return nil +} + +// InitPaths sets the default paths in the configuration based on CLI flags, +// configuration file and default values. It also tries to create the data +// path with mode 0750 and returns an error on failure. +func InitPaths(cfg *Path) error { + return Paths.InitPaths(cfg) +} + +// initPaths sets the default paths in the configuration based on CLI flags, +// configuration file and default values. +func (paths *Path) initPaths(cfg *Path) error { + *paths = *cfg + + // default for config path + if paths.Config == "" { + paths.Config = paths.Home + } + + // default for data path + if paths.Data == "" { + paths.Data = filepath.Join(paths.Home, "data") + } + + // default for logs path + if paths.Logs == "" { + paths.Logs = filepath.Join(paths.Home, "logs") + } + + return nil +} + +// Resolve resolves a path to a location in one of the default +// folders. For example, Resolve(Home, "test") returns an absolute +// path for "test" in the home path. +func (paths *Path) Resolve(fileType FileType, path string) string { + // absolute paths are not changed for non-hostfs file types, since hostfs is a little odd + if filepath.IsAbs(path) { + return path + } + + switch fileType { + case Home: + return filepath.Join(paths.Home, path) + case Config: + return filepath.Join(paths.Config, path) + case Data: + return filepath.Join(paths.Data, path) + case Logs: + return filepath.Join(paths.Logs, path) + default: + panic(fmt.Sprintf("Unknown file type: %s", fileType)) + } +} + +// Resolve resolves a path to a location in one of the default +// folders. For example, Resolve(Home, "test") returns an absolute +// path for "test" in the home path. +// In case path is already an absolute path, the path itself is returned. +func Resolve(fileType FileType, path string) string { + return Paths.Resolve(fileType, path) +} + +// String returns a textual representation +func (paths *Path) String() string { + return fmt.Sprintf("Home path: [%s] Config path: [%s] Data path: [%s] Logs path: [%s]", + paths.Home, paths.Config, paths.Data, paths.Logs) +} diff --git a/paths/paths_test.go b/paths/paths_test.go new file mode 100644 index 00000000000..1d430e78c98 --- /dev/null +++ b/paths/paths_test.go @@ -0,0 +1,176 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package paths + +import ( + "os" + "path/filepath" + "runtime" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestHomePath(t *testing.T) { + type io struct { + Home string // cli flag home setting + Path string // requested path + ResultHome string // expected home path + ResultData string // expected data path + } + + binDir, err := filepath.Abs(filepath.Dir(os.Args[0])) + if err != nil { + t.Fatal(err) + } + + tests := []io{ + { + Home: binDir, + Path: "test", + ResultHome: filepath.Join(binDir, "test"), + ResultData: filepath.Join(binDir, "data", "test"), + }, + { + Home: rootDir("/tmp"), + Path: "test", + ResultHome: rootDir("/tmp/test"), + ResultData: rootDir("/tmp/data/test"), + }, + { + Home: rootDir("/home"), + Path: rootDir("/abc/test"), + ResultHome: rootDir("/abc/test"), + ResultData: rootDir("/abc/test"), + }, + } + + for _, test := range tests { + cfg := Path{Home: test.Home} + if err := Paths.initPaths(&cfg); err != nil { + t.Errorf("error on %+v: %v", test, err) + continue + } + + assert.Equal(t, test.ResultHome, Resolve(Home, test.Path), "failed on %+v", test) + + // config path same as home path + assert.Equal(t, test.ResultHome, Resolve(Config, test.Path), "failed on %+v", test) + + // data path under home path + assert.Equal(t, test.ResultData, Resolve(Data, test.Path), "failed on %+v", test) + } +} + +func TestDataPath(t *testing.T) { + type io struct { + Home string // cli flag home setting + Data string // cli flag for data setting + Path string // requested path + ResultData string // expected data path + } + + binDir, err := filepath.Abs(filepath.Dir(os.Args[0])) + if err != nil { + t.Fatal(err) + } + + tests := []io{ + { + Home: binDir, + Data: "", + Path: "test", + ResultData: filepath.Join(binDir, "data", "test"), + }, + { + Home: rootDir("/tmp"), + Data: rootDir("/root"), + Path: "test", + ResultData: rootDir("/root/test"), + }, + { + Home: rootDir("/tmp"), + Data: rootDir("root"), + Path: rootDir("/var/data"), + ResultData: rootDir("/var/data"), + }, + } + + for _, test := range tests { + cfg := Path{Home: test.Home, Data: test.Data} + if err := Paths.initPaths(&cfg); err != nil { + t.Errorf("error on %+v: %v", test, err) + continue + } + + assert.Equal(t, test.ResultData, Resolve(Data, test.Path), "failed on %+v", test) + } +} + +func TestLogsPath(t *testing.T) { + type io struct { + Home string // cli flag home setting + Logs string // cli flag for data setting + Path string // requested path + ResultLogs string // expected logs path + } + + binDir, err := filepath.Abs(filepath.Dir(os.Args[0])) + if err != nil { + t.Fatal(err) + } + + tests := []io{ + { + Home: binDir, + Logs: "", + Path: "test", + ResultLogs: filepath.Join(binDir, "logs", "test"), + }, + { + Home: rootDir("/tmp"), + Logs: rootDir("/var"), + Path: "log", + ResultLogs: rootDir("/var/log"), + }, + { + Home: rootDir("tmp"), + Logs: rootDir("root"), + Path: rootDir("/var/log"), + ResultLogs: rootDir("/var/log"), + }, + } + + for _, test := range tests { + cfg := Path{Home: test.Home, Logs: test.Logs} + if err := Paths.initPaths(&cfg); err != nil { + t.Errorf("error on %+v: %v", test, err) + continue + } + + assert.Equal(t, test.ResultLogs, Resolve(Logs, test.Path)) + } +} + +// rootDir builds an OS specific absolute root directory. +func rootDir(path string) string { + if runtime.GOOS == "windows" { + return filepath.Join(`c:\`, path) + } + return filepath.Join("/", path) +}