-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
1,553 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* | ||
* k6 - a next-generation load testing tool | ||
* Copyright (C) 2019 Load Impact | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
package datadog | ||
|
||
import ( | ||
"github.com/loadimpact/k6/lib" | ||
"github.com/loadimpact/k6/stats/statsd/common" | ||
) | ||
|
||
type tagHandler lib.TagSet | ||
|
||
func (t tagHandler) processTags(tags map[string]string) []string { | ||
var res []string | ||
|
||
for key, value := range tags { | ||
if value != "" && !t[key] { | ||
res = append(res, key+":"+value) | ||
} | ||
} | ||
return res | ||
} | ||
|
||
// Config defines the datadog configuration | ||
type Config struct { | ||
common.Config | ||
|
||
TagBlacklist lib.TagSet `json:"tagBlacklist,omitempty" envconfig:"TAG_BLACKLIST"` | ||
} | ||
|
||
// Apply saves config non-zero config values from the passed config in the receiver. | ||
func (c Config) Apply(cfg Config) Config { | ||
c.Config = c.Config.Apply(cfg.Config) | ||
|
||
if cfg.TagBlacklist != nil { | ||
c.TagBlacklist = cfg.TagBlacklist | ||
} | ||
|
||
return c | ||
} | ||
|
||
// NewConfig creates a new Config instance with default values for some fields. | ||
func NewConfig() Config { | ||
return Config{ | ||
Config: common.NewConfig(), | ||
TagBlacklist: lib.GetTagSet(), | ||
} | ||
} | ||
|
||
// New creates a new statsd connector client | ||
func New(conf Config) (*common.Collector, error) { | ||
return &common.Collector{ | ||
Config: conf.Config, | ||
Type: "datadog", | ||
ProcessTags: tagHandler(conf.TagBlacklist).processTags, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package datadog | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/loadimpact/k6/lib" | ||
"github.com/loadimpact/k6/stats" | ||
"github.com/loadimpact/k6/stats/statsd/common" | ||
"github.com/loadimpact/k6/stats/statsd/common/testutil" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestCollector(t *testing.T) { | ||
var tagSet = lib.GetTagSet("tag1", "tag2") | ||
var handler = tagHandler(tagSet) | ||
testutil.BaseTest(t, func(config common.Config) (*common.Collector, error) { | ||
return New(NewConfig().Apply(Config{ | ||
TagBlacklist: tagSet, | ||
Config: config, | ||
})) | ||
}, func(t *testing.T, containers []stats.SampleContainer, expectedOutput, output string) { | ||
var outputLines = strings.Split(output, "\n") | ||
var expectedOutputLines = strings.Split(expectedOutput, "\n") | ||
for i, container := range containers { | ||
for j, sample := range container.GetSamples() { | ||
var ( | ||
expectedTagList = handler.processTags(sample.GetTags().CloneTags()) | ||
expectedOutputLine = expectedOutputLines[i*j+i] | ||
outputLine = outputLines[i*j+i] | ||
outputWithoutTags = outputLine | ||
outputTagList = []string{} | ||
tagSplit = strings.LastIndex(outputLine, "|#") | ||
) | ||
|
||
if tagSplit != -1 { | ||
outputWithoutTags = outputLine[:tagSplit] | ||
outputTagList = strings.Split(outputLine[tagSplit+len("|#"):], ",") | ||
} | ||
require.Equal(t, expectedOutputLine, outputWithoutTags) | ||
require.ElementsMatch(t, expectedTagList, outputTagList) | ||
} | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* | ||
* k6 - a next-generation load testing tool | ||
* Copyright (C) 2019 Load Impact | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
package statsd | ||
|
||
import ( | ||
"github.com/loadimpact/k6/stats/statsd/common" | ||
) | ||
|
||
// New creates a new statsd connector client | ||
func New(conf common.Config) (*common.Collector, error) { | ||
return &common.Collector{ | ||
Config: conf, | ||
Type: "statsd", | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package statsd | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/loadimpact/k6/stats" | ||
"github.com/loadimpact/k6/stats/statsd/common/testutil" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestCollector(t *testing.T) { | ||
testutil.BaseTest(t, New, | ||
func(t *testing.T, _ []stats.SampleContainer, expectedOutput, output string) { | ||
require.Equal(t, expectedOutput, output) | ||
}) | ||
} |
Oops, something went wrong.