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 true - Prints OpenTSDB communication
debug = false debug = false
` `
type TagSet map[string]string type TagSet map[string]string
func (t TagSet) ToLineFormat() string { func (t TagSet) ToLineFormat() string {
@ -114,13 +115,13 @@ func (o *OpenTSDB) WriteHttp(metrics []telegraf.Metric) error {
Value: metricValue, Value: metricValue,
} }
if err:= http.sendDataPoint(metric); err != nil { if err := http.sendDataPoint(metric); err != nil {
return err return err
} }
} }
} }
if err:= http.flush(); err != nil { if err := http.flush(); err != nil {
return err return err
} }
@ -149,7 +150,7 @@ func (o *OpenTSDB) WriteTelnet(metrics []telegraf.Metric) error {
} }
messageLine := fmt.Sprintf("put %s %v %s %s\n", 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) now, metricValue, tags)
if o.Debug { if o.Debug {

View File

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

View File

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