Ran go fmt on opentsdb sources.

This commit is contained in:
Eric 2016-07-22 08:29:55 -04:00
parent 71c53841c3
commit 8ab9cc29af
3 changed files with 104 additions and 105 deletions

View File

@ -47,6 +47,7 @@ var sampleConfig = `
## Debug true - Prints OpenTSDB communication
debug = false
`
type TagSet map[string]string
func (t TagSet) ToLineFormat() string {
@ -114,13 +115,13 @@ func (o *OpenTSDB) WriteHttp(metrics []telegraf.Metric) error {
Value: metricValue,
}
if err:= http.sendDataPoint(metric); err != nil {
if err := http.sendDataPoint(metric); err != nil {
return err
}
}
}
if err:= http.flush(); err != nil {
if err := http.flush(); err != nil {
return err
}
@ -149,7 +150,7 @@ func (o *OpenTSDB) WriteTelnet(metrics []telegraf.Metric) error {
}
messageLine := fmt.Sprintf("put %s %v %s %s\n",
sanitizedChars.Replace(fmt.Sprintf("%s%s_%s",o.Prefix, m.Name(), fieldName)),
sanitizedChars.Replace(fmt.Sprintf("%s%s_%s", o.Prefix, m.Name(), fieldName)),
now, metricValue, tags)
if o.Debug {

View File

@ -1,16 +1,16 @@
package opentsdb
import (
"fmt"
"bytes"
"compress/gzip"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"net/http/httputil"
"net/url"
"bytes"
"compress/gzip"
"log"
)
type HttpMetric struct {
@ -20,7 +20,6 @@ type HttpMetric struct {
Tags map[string]string `json:"tags"`
}
type openTSDBHttp struct {
Host string
Port int
@ -118,13 +117,13 @@ func (o *openTSDBHttp) flush() error {
o.body.close()
u := url.URL {
u := url.URL{
Scheme: "http",
Host: fmt.Sprintf("%s:%d", o.Host, o.Port),
Path: "/api/put",
}
if (o.Debug) {
if o.Debug {
u.RawQuery = "details"
}
@ -135,7 +134,7 @@ func (o *openTSDBHttp) flush() error {
req.Header.Set("Content-Type", "applicaton/json")
req.Header.Set("Content-Encoding", "gzip")
if (o.Debug) {
if o.Debug {
dump, err := httputil.DumpRequestOut(req, false)
if err != nil {
return fmt.Errorf("Error when dumping request: %s", err.Error())

View File

@ -1,14 +1,14 @@
package opentsdb
import (
"reflect"
"testing"
"fmt"
"net"
"net/http"
"net/http/httptest"
"net/url"
"reflect"
"strconv"
"testing"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/testutil"
@ -77,13 +77,12 @@ func TestBuildTagsTelnet(t *testing.T) {
func BenchmarkHttpSend(b *testing.B) {
const BatchSize = 50
const MetricsCount = 4*BatchSize
const MetricsCount = 4 * BatchSize
metrics := make([]telegraf.Metric, MetricsCount)
for i:=0; i<MetricsCount; i++ {
for i := 0; i < MetricsCount; i++ {
metrics[i] = testutil.TestMetric(1.0)
}
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
fmt.Fprintln(w, "{}")