Skip to content

Commit

Permalink
all: change default system tag to SystemTagSet
Browse files Browse the repository at this point in the history
  • Loading branch information
cuonglm committed Oct 17, 2019
1 parent a8f4b7c commit ac8afd5
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ func getConsolidatedConfig(fs afero.Fs, cliConf Config, runner lib.Runner) (conf
// Note that if you add option default value here, also add it in command line argument help text.
func applyDefault(conf Config) Config {
if conf.Options.SystemTags == nil {
conf = conf.Apply(Config{Options: lib.Options{SystemTags: stats.ToSystemTagSet(stats.DefaultSystemTagList)}})
conf = conf.Apply(Config{Options: lib.Options{SystemTags: &stats.DefaultSystemTagSet}})
}
return conf
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/config_consolidation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ func getConfigConsolidationTestCases() []configConsolidationTestCase {

// Test system tags
{opts{}, exp{}, func(t *testing.T, c Config) {
assert.Equal(t, stats.ToSystemTagSet(stats.DefaultSystemTagList), c.Options.SystemTags)
assert.Equal(t, &stats.DefaultSystemTagSet, c.Options.SystemTags)
}},
{opts{cli: []string{"--system-tags", `""`}}, exp{}, func(t *testing.T, c Config) {
assert.Equal(t, stats.SystemTagSet(0), *c.Options.SystemTags)
Expand Down
2 changes: 1 addition & 1 deletion cmd/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func optionFlagSet() *pflag.FlagSet {
// set it to nil here, and add the default in applyDefault() instead.
systemTagsCliHelpText := fmt.Sprintf(
"only include these system tags in metrics (default %s)",
stats.DefaultSystemTagList,
stats.DefaultSystemTagSet,
)
flags.StringSlice("system-tags", nil, systemTagsCliHelpText)
flags.StringSlice("tag", nil, "add a `tag` to be applied to all samples, as `[name]=[value]`")
Expand Down
4 changes: 2 additions & 2 deletions core/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ func TestRunTags(t *testing.T) {
VUsMax: null.IntFrom(2),
Hosts: tb.Dialer.Hosts,
RunTags: runTags,
SystemTags: stats.ToSystemTagSet(stats.DefaultSystemTagList),
SystemTags: &stats.DefaultSystemTagSet,
InsecureSkipTLSVerify: null.BoolFrom(true),
}

Expand Down Expand Up @@ -800,7 +800,7 @@ func TestSetupTeardownThresholds(t *testing.T) {
)
require.NoError(t, err)
runner.SetOptions(runner.GetOptions().Apply(lib.Options{
SystemTags: stats.ToSystemTagSet(stats.DefaultSystemTagList),
SystemTags: &stats.DefaultSystemTagSet,
SetupTimeout: types.NullDurationFrom(3 * time.Second),
TeardownTimeout: types.NullDurationFrom(3 * time.Second),
VUs: null.IntFrom(3),
Expand Down
2 changes: 1 addition & 1 deletion core/local/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ func TestRealTimeAndSetupTeardownMetrics(t *testing.T) {
require.NoError(t, err)

options := lib.Options{
SystemTags: stats.ToSystemTagSet(stats.DefaultSystemTagList),
SystemTags: &stats.DefaultSystemTagSet,
SetupTimeout: types.NullDurationFrom(4 * time.Second),
TeardownTimeout: types.NullDurationFrom(4 * time.Second),
}
Expand Down
2 changes: 1 addition & 1 deletion js/modules/k6/http/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func newRuntime(
MaxRedirects: null.IntFrom(10),
UserAgent: null.StringFrom("TestUserAgent"),
Throw: null.BoolFrom(true),
SystemTags: stats.ToSystemTagSet(stats.DefaultSystemTagList),
SystemTags: &stats.DefaultSystemTagSet,
//HttpDebug: null.StringFrom("full"),
}
samples := make(chan stats.SampleContainer, 1000)
Expand Down
2 changes: 1 addition & 1 deletion js/modules/k6/k6_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func TestCheck(t *testing.T) {
return &lib.State{
Group: root,
Options: lib.Options{
SystemTags: stats.ToSystemTagSet(stats.DefaultSystemTagList),
SystemTags: &stats.DefaultSystemTagSet,
},
Samples: samples,
}, samples
Expand Down
2 changes: 1 addition & 1 deletion js/modules/k6/ws/ws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ func TestErrors(t *testing.T) {
Group: root,
Dialer: tb.Dialer,
Options: lib.Options{
SystemTags: stats.ToSystemTagSet(stats.DefaultSystemTagList),
SystemTags: &stats.DefaultSystemTagSet,
},
Samples: samples,
}
Expand Down
8 changes: 4 additions & 4 deletions lib/archive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func TestArchiveReadWrite(t *testing.T) {
K6Version: consts.Version,
Options: Options{
VUs: null.IntFrom(12345),
SystemTags: stats.ToSystemTagSet(stats.DefaultSystemTagList),
SystemTags: &stats.DefaultSystemTagSet,
},
FilenameURL: &url.URL{Scheme: "file", Path: "/path/to/a.js"},
Data: []byte(`// a contents`),
Expand Down Expand Up @@ -192,7 +192,7 @@ func TestArchiveReadWrite(t *testing.T) {
Type: "js",
Options: Options{
VUs: null.IntFrom(12345),
SystemTags: stats.ToSystemTagSet(stats.DefaultSystemTagList),
SystemTags: &stats.DefaultSystemTagSet,
},
FilenameURL: &url.URL{Scheme: "file", Path: fmt.Sprintf("%s/a.js", entry.Pwd)},
K6Version: consts.Version,
Expand All @@ -215,7 +215,7 @@ func TestArchiveReadWrite(t *testing.T) {
Type: "js",
Options: Options{
VUs: null.IntFrom(12345),
SystemTags: stats.ToSystemTagSet(stats.DefaultSystemTagList),
SystemTags: &stats.DefaultSystemTagSet,
},
FilenameURL: &url.URL{Scheme: "file", Path: fmt.Sprintf("%s/a.js", entry.PwdNormAnon)},
K6Version: consts.Version,
Expand Down Expand Up @@ -344,7 +344,7 @@ func TestStrangePaths(t *testing.T) {
K6Version: consts.Version,
Options: Options{
VUs: null.IntFrom(12345),
SystemTags: stats.ToSystemTagSet(stats.DefaultSystemTagList),
SystemTags: &stats.DefaultSystemTagSet,
},
FilenameURL: &url.URL{Scheme: "file", Path: pathToChange},
Data: []byte(`// ` + pathToChange + ` contents`),
Expand Down
1 change: 1 addition & 0 deletions lib/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ type Options struct {
SummaryTimeUnit null.String `json:"summaryTimeUnit" envconfig:"summary_time_unit"`

// Which system tags to include with metrics ("method", "vu" etc.)
// Use pointer for identifying whether user provide any tag or not.
SystemTags *stats.SystemTagSet `json:"systemTags" envconfig:"system_tags"`

// Tags to be applied to all samples for this running
Expand Down
6 changes: 3 additions & 3 deletions stats/datadog/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (t tagHandler) processTags(tags map[string]string) []string {
type Config struct {
common.Config

TagBlacklist *stats.SystemTagSet `json:"tagBlacklist,omitempty" envconfig:"TAG_BLACKLIST"`
TagBlacklist stats.SystemTagMap `json:"tagBlacklist,omitempty" envconfig:"TAG_BLACKLIST"`
}

// Apply saves config non-zero config values from the passed config in the receiver.
Expand All @@ -61,7 +61,7 @@ func (c Config) Apply(cfg Config) Config {
func NewConfig() Config {
return Config{
Config: common.NewConfig(),
TagBlacklist: stats.ToSystemTagSet([]string{}),
TagBlacklist: stats.SystemTagMap{},
}
}

Expand All @@ -70,6 +70,6 @@ func New(conf Config) (*common.Collector, error) {
return &common.Collector{
Config: conf.Config,
Type: "datadog",
ProcessTags: tagHandler(*conf.TagBlacklist).processTags,
ProcessTags: tagHandler(conf.TagBlacklist.ToTagSet()).processTags,
}, nil
}
6 changes: 3 additions & 3 deletions stats/datadog/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (
)

func TestCollector(t *testing.T) {
var tagSet = stats.ToSystemTagSet([]string{stats.TagProto.String(), stats.TagGroup.String()})
var handler = tagHandler(*tagSet)
var tagMap = stats.SystemTagMap{stats.TagProto.String(): true, stats.TagGroup.String(): true}
var handler = tagHandler(tagMap.ToTagSet())
testutil.BaseTest(t, func(config common.Config) (*common.Collector, error) {
return New(NewConfig().Apply(Config{
TagBlacklist: tagSet,
TagBlacklist: tagMap,
Config: config,
}))
}, func(t *testing.T, containers []stats.SampleContainer, expectedOutput, output string) {
Expand Down
27 changes: 13 additions & 14 deletions stats/system_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,21 @@ const (
TagIP
)

// DefaultSystemTagList includes all of the system tags emitted with metrics by default.
// DefaultSystemTagSet includes all of the system tags emitted with metrics by default.
// Other tags that are not enabled by default include: iter, vu, ocsp_status, ip
//nolint:gochecknoglobals
var DefaultSystemTagList = []string{
TagProto.String(),
TagSubProto.String(),
TagStatus.String(),
TagMethod.String(),
TagURL.String(),
TagName.String(),
TagGroup.String(),
TagCheck.String(),
TagCheck.String(),
TagError.String(),
TagErrorCode.String(),
TagTLSVersion.String(),
var DefaultSystemTagSet = TagProto | TagSubProto | TagStatus | TagMethod | TagURL | TagName | TagGroup |
TagCheck | TagCheck | TagError | TagErrorCode | TagTLSVersion

// ToTagSet converts a system tag map to tag set
func (tm SystemTagMap) ToTagSet() SystemTagSet {
ts := SystemTagSet(0)
for tag, ok := range tm {
if v, err := SystemTagSetString(tag); err == nil && ok {
ts.Add(v)
}
}
return ts
}

// Add adds a tag to tag set.
Expand Down

0 comments on commit ac8afd5

Please sign in to comment.