Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added capability to send metrics through Http API for OpenTSDB #1539

Closed
wants to merge 15 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed current unittest and added a new one.
EricFortin committed Aug 30, 2016
commit 6f63fbcf8e20dff175f27452fa22a396f39434bd
11 changes: 7 additions & 4 deletions plugins/outputs/opentsdb/opentsdb.go
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ package opentsdb
import (
"fmt"
"net"
"sort"
"strconv"
"strings"

@@ -49,12 +50,14 @@ var sampleConfig = `
type TagSet map[string]string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you make this type? just using a map[string]string is more explicit and readable throughout


func (t TagSet) ToLineFormat() string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be a standalone function without receiver that takes a map[string]string as input

var line string
tags := make([]string, len(t))
index := 0
for k, v := range t {
line += fmt.Sprintf(" %s=%s", k, v)
tags[index] = fmt.Sprintf("%s=%s", k, v)
index++
}

return strings.TrimLeft(line, " ")
sort.Strings(tags)
return strings.Join(tags, " ")
}

func (o *OpenTSDB) Connect() error {
48 changes: 37 additions & 11 deletions plugins/outputs/opentsdb/opentsdb_test.go
Original file line number Diff line number Diff line change
@@ -7,34 +7,60 @@ import (
// "github.com/stretchr/testify/require"
)

func TestBuildTagsTelnet(t *testing.T) {
func TestCleanTags(t *testing.T) {
var tagtests = []struct {
ptIn map[string]string
outTags []string
outTags TagSet
}{
{
map[string]string{"one": "two", "three": "four"},
[]string{"one=two", "three=four"},
TagSet{"one": "two", "three": "four"},
},
{
map[string]string{"aaa": "bbb"},
[]string{"aaa=bbb"},
},
{
map[string]string{"one": "two", "aaa": "bbb"},
[]string{"aaa=bbb", "one=two"},
TagSet{"aaa": "bbb"},
},
{
map[string]string{"Sp%ci@l Chars": "g$t repl#ced"},
[]string{"Sp-ci-l_Chars=g-t_repl-ced"},
TagSet{"Sp-ci-l_Chars": "g-t_repl-ced"},
},
{
map[string]string{},
[]string{},
TagSet{},
},
}
for _, tt := range tagtests {
tags := cleanTags(tt.ptIn)
if !reflect.DeepEqual(tags, tt.outTags) {
t.Errorf("\nexpected %+v\ngot %+v\n", tt.outTags, tags)
}
}
}

func TestBuildTagsTelnet(t *testing.T) {
var tagtests = []struct {
ptIn TagSet
outTags string
}{
{
TagSet{"one": "two", "three": "four"},
"one=two three=four",
},
{
TagSet{"aaa": "bbb"},
"aaa=bbb",
},
{
TagSet{"one": "two", "aaa": "bbb"},
"aaa=bbb one=two",
},
{
TagSet{},
"",
},
}
for _, tt := range tagtests {
tags := buildTags(tt.ptIn)
tags := tt.ptIn.ToLineFormat()
if !reflect.DeepEqual(tags, tt.outTags) {
t.Errorf("\nexpected %+v\ngot %+v\n", tt.outTags, tags)
}