chore: Remove `revive:unhandled-error` - `errcheck` is more flexible (#13008)
This commit is contained in:
parent
b75fa42d75
commit
c76f319b84
|
|
@ -76,6 +76,13 @@ linters-settings:
|
||||||
- "**/testutil/**"
|
- "**/testutil/**"
|
||||||
- "**/tools/**"
|
- "**/tools/**"
|
||||||
- "**/*_test.go"
|
- "**/*_test.go"
|
||||||
|
errcheck:
|
||||||
|
# List of functions to exclude from checking, where each entry is a single function to exclude.
|
||||||
|
# See https://github.com/kisielk/errcheck#excluding-functions for details.
|
||||||
|
exclude-functions:
|
||||||
|
- "(*hash/maphash.Hash).Write"
|
||||||
|
- "(*hash/maphash.Hash).WriteByte"
|
||||||
|
- "(*hash/maphash.Hash).WriteString"
|
||||||
gosec:
|
gosec:
|
||||||
# To select a subset of rules to run.
|
# To select a subset of rules to run.
|
||||||
# Available rules: https://github.com/securego/gosec#available-rules
|
# Available rules: https://github.com/securego/gosec#available-rules
|
||||||
|
|
@ -153,8 +160,6 @@ linters-settings:
|
||||||
- name: time-naming
|
- name: time-naming
|
||||||
- name: unconditional-recursion
|
- name: unconditional-recursion
|
||||||
- name: unexported-naming
|
- name: unexported-naming
|
||||||
- name: unhandled-error
|
|
||||||
arguments: [ "fmt.Printf", "fmt.Println", "fmt.Print", "fmt.Fprintf", "fmt.Fprint", "fmt.Fprintln" ]
|
|
||||||
- name: unnecessary-stmt
|
- name: unnecessary-stmt
|
||||||
- name: unreachable-code
|
- name: unreachable-code
|
||||||
- name: unused-parameter
|
- name: unused-parameter
|
||||||
|
|
@ -213,7 +218,6 @@ issues:
|
||||||
- don't use an underscore in package name
|
- don't use an underscore in package name
|
||||||
# EXC0001 errcheck: Almost all programs ignore errors on these functions and in most cases it's ok
|
# EXC0001 errcheck: Almost all programs ignore errors on these functions and in most cases it's ok
|
||||||
- Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked
|
- Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked
|
||||||
- Unhandled error in call to function ((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv)
|
|
||||||
# EXC0013 revive: Annoying issue about not having a comment. The rare codebase has such comments
|
# EXC0013 revive: Annoying issue about not having a comment. The rare codebase has such comments
|
||||||
- package comment should be of the form "(.+)...
|
- package comment should be of the form "(.+)...
|
||||||
# EXC0015 revive: Annoying issue about not having a comment. The rare codebase has such comments
|
# EXC0015 revive: Annoying issue about not having a comment. The rare codebase has such comments
|
||||||
|
|
|
||||||
|
|
@ -262,13 +262,13 @@ func (m *metric) Copy() telegraf.Metric {
|
||||||
|
|
||||||
func (m *metric) HashID() uint64 {
|
func (m *metric) HashID() uint64 {
|
||||||
h := fnv.New64a()
|
h := fnv.New64a()
|
||||||
h.Write([]byte(m.name)) //nolint:revive // all Write() methods for hash in fnv.go returns nil err
|
h.Write([]byte(m.name))
|
||||||
h.Write([]byte("\n")) //nolint:revive // all Write() methods for hash in fnv.go returns nil err
|
h.Write([]byte("\n"))
|
||||||
for _, tag := range m.tags {
|
for _, tag := range m.tags {
|
||||||
h.Write([]byte(tag.Key)) //nolint:revive // all Write() methods for hash in fnv.go returns nil err
|
h.Write([]byte(tag.Key))
|
||||||
h.Write([]byte("\n")) //nolint:revive // all Write() methods for hash in fnv.go returns nil err
|
h.Write([]byte("\n"))
|
||||||
h.Write([]byte(tag.Value)) //nolint:revive // all Write() methods for hash in fnv.go returns nil err
|
h.Write([]byte(tag.Value))
|
||||||
h.Write([]byte("\n")) //nolint:revive // all Write() methods for hash in fnv.go returns nil err
|
h.Write([]byte("\n"))
|
||||||
}
|
}
|
||||||
return h.Sum64()
|
return h.Sum64()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -87,20 +87,20 @@ func groupID(seed maphash.Seed, measurement string, taglist []*telegraf.Tag, tm
|
||||||
var mh maphash.Hash
|
var mh maphash.Hash
|
||||||
mh.SetSeed(seed)
|
mh.SetSeed(seed)
|
||||||
|
|
||||||
mh.WriteString(measurement) //nolint:errcheck,revive // all Write***() methods for hash in maphash.go returns nil err
|
mh.WriteString(measurement)
|
||||||
mh.WriteByte(0) //nolint:errcheck,revive // all Write***() methods for hash in maphash.go returns nil err
|
mh.WriteByte(0)
|
||||||
|
|
||||||
for _, tag := range taglist {
|
for _, tag := range taglist {
|
||||||
mh.WriteString(tag.Key) //nolint:errcheck,revive // all Write***() methods for hash in maphash.go returns nil err
|
mh.WriteString(tag.Key)
|
||||||
mh.WriteByte(0) //nolint:errcheck,revive // all Write***() methods for hash in maphash.go returns nil err
|
mh.WriteByte(0)
|
||||||
mh.WriteString(tag.Value) //nolint:errcheck,revive // all Write***() methods for hash in maphash.go returns nil err
|
mh.WriteString(tag.Value)
|
||||||
mh.WriteByte(0) //nolint:errcheck,revive // all Write***() methods for hash in maphash.go returns nil err
|
mh.WriteByte(0)
|
||||||
}
|
}
|
||||||
mh.WriteByte(0) //nolint:errcheck,revive // all Write***() methods for hash in maphash.go returns nil err
|
mh.WriteByte(0)
|
||||||
|
|
||||||
var tsBuf [8]byte
|
var tsBuf [8]byte
|
||||||
binary.BigEndian.PutUint64(tsBuf[:], uint64(tm.UnixNano()))
|
binary.BigEndian.PutUint64(tsBuf[:], uint64(tm.UnixNano()))
|
||||||
mh.Write(tsBuf[:]) //nolint:errcheck,revive // all Write***() methods for hash in maphash.go returns nil err
|
mh.Write(tsBuf[:])
|
||||||
|
|
||||||
return mh.Sum64()
|
return mh.Sum64()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ func BenchmarkRunningOutputAddWrite(b *testing.B) {
|
||||||
|
|
||||||
for n := 0; n < b.N; n++ {
|
for n := 0; n < b.N; n++ {
|
||||||
ro.AddMetric(testutil.TestMetric(101, "metric1"))
|
ro.AddMetric(testutil.TestMetric(101, "metric1"))
|
||||||
ro.Write() //nolint: errcheck,revive // skip checking err for benchmark tests
|
ro.Write() //nolint: errcheck // skip checking err for benchmark tests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -56,7 +56,7 @@ func BenchmarkRunningOutputAddWriteEvery100(b *testing.B) {
|
||||||
for n := 0; n < b.N; n++ {
|
for n := 0; n < b.N; n++ {
|
||||||
ro.AddMetric(testutil.TestMetric(101, "metric1"))
|
ro.AddMetric(testutil.TestMetric(101, "metric1"))
|
||||||
if n%100 == 0 {
|
if n%100 == 0 {
|
||||||
ro.Write() //nolint: errcheck,revive // skip checking err for benchmark tests
|
ro.Write() //nolint: errcheck // skip checking err for benchmark tests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -198,11 +198,11 @@ func newMP(n *NodeMetricMapping) metricParts {
|
||||||
var sb strings.Builder
|
var sb strings.Builder
|
||||||
for i, key := range keys {
|
for i, key := range keys {
|
||||||
if i != 0 {
|
if i != 0 {
|
||||||
sb.WriteString(", ") //nolint:revive // writes to a string-builder will always succeed
|
sb.WriteString(", ")
|
||||||
}
|
}
|
||||||
sb.WriteString(key) //nolint:revive // writes to a string-builder will always succeed
|
sb.WriteString(key)
|
||||||
sb.WriteString("=") //nolint:revive // writes to a string-builder will always succeed
|
sb.WriteString("=")
|
||||||
sb.WriteString(n.MetricTags[key]) //nolint:revive // writes to a string-builder will always succeed
|
sb.WriteString(n.MetricTags[key])
|
||||||
}
|
}
|
||||||
x := metricParts{
|
x := metricParts{
|
||||||
metricName: n.metricName,
|
metricName: n.metricName,
|
||||||
|
|
|
||||||
|
|
@ -19,17 +19,17 @@ type FieldDict struct {
|
||||||
|
|
||||||
func (d FieldDict) String() string {
|
func (d FieldDict) String() string {
|
||||||
buf := new(strings.Builder)
|
buf := new(strings.Builder)
|
||||||
buf.WriteString("{") //nolint:revive // from builder.go: "It returns the length of r and a nil error."
|
buf.WriteString("{")
|
||||||
sep := ""
|
sep := ""
|
||||||
for _, item := range d.Items() {
|
for _, item := range d.Items() {
|
||||||
k, v := item[0], item[1]
|
k, v := item[0], item[1]
|
||||||
buf.WriteString(sep) //nolint:revive // from builder.go: "It returns the length of r and a nil error."
|
buf.WriteString(sep)
|
||||||
buf.WriteString(k.String()) //nolint:revive // from builder.go: "It returns the length of r and a nil error."
|
buf.WriteString(k.String())
|
||||||
buf.WriteString(": ") //nolint:revive // from builder.go: "It returns the length of r and a nil error."
|
buf.WriteString(": ")
|
||||||
buf.WriteString(v.String()) //nolint:revive // from builder.go: "It returns the length of r and a nil error."
|
buf.WriteString(v.String())
|
||||||
sep = ", "
|
sep = ", "
|
||||||
}
|
}
|
||||||
buf.WriteString("}") //nolint:revive // from builder.go: "It returns the length of r and a nil error."
|
buf.WriteString("}")
|
||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,15 +37,15 @@ func (m *Metric) Unwrap() telegraf.Metric {
|
||||||
// it behaves more like the repr function would in Python.
|
// it behaves more like the repr function would in Python.
|
||||||
func (m *Metric) String() string {
|
func (m *Metric) String() string {
|
||||||
buf := new(strings.Builder)
|
buf := new(strings.Builder)
|
||||||
buf.WriteString("Metric(") //nolint:revive // from builder.go: "It returns the length of r and a nil error."
|
buf.WriteString("Metric(")
|
||||||
buf.WriteString(m.Name().String()) //nolint:revive // from builder.go: "It returns the length of r and a nil error."
|
buf.WriteString(m.Name().String())
|
||||||
buf.WriteString(", tags=") //nolint:revive // from builder.go: "It returns the length of r and a nil error."
|
buf.WriteString(", tags=")
|
||||||
buf.WriteString(m.Tags().String()) //nolint:revive // from builder.go: "It returns the length of r and a nil error."
|
buf.WriteString(m.Tags().String())
|
||||||
buf.WriteString(", fields=") //nolint:revive // from builder.go: "It returns the length of r and a nil error."
|
buf.WriteString(", fields=")
|
||||||
buf.WriteString(m.Fields().String()) //nolint:revive // from builder.go: "It returns the length of r and a nil error."
|
buf.WriteString(m.Fields().String())
|
||||||
buf.WriteString(", time=") //nolint:revive // from builder.go: "It returns the length of r and a nil error."
|
buf.WriteString(", time=")
|
||||||
buf.WriteString(m.Time().String()) //nolint:revive // from builder.go: "It returns the length of r and a nil error."
|
buf.WriteString(m.Time().String())
|
||||||
buf.WriteString(")") //nolint:revive // from builder.go: "It returns the length of r and a nil error."
|
buf.WriteString(")")
|
||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,17 +18,17 @@ type TagDict struct {
|
||||||
|
|
||||||
func (d TagDict) String() string {
|
func (d TagDict) String() string {
|
||||||
buf := new(strings.Builder)
|
buf := new(strings.Builder)
|
||||||
buf.WriteString("{") //nolint:revive // from builder.go: "It returns the length of r and a nil error."
|
buf.WriteString("{")
|
||||||
sep := ""
|
sep := ""
|
||||||
for _, item := range d.Items() {
|
for _, item := range d.Items() {
|
||||||
k, v := item[0], item[1]
|
k, v := item[0], item[1]
|
||||||
buf.WriteString(sep) //nolint:revive // from builder.go: "It returns the length of r and a nil error."
|
buf.WriteString(sep)
|
||||||
buf.WriteString(k.String()) //nolint:revive // from builder.go: "It returns the length of r and a nil error."
|
buf.WriteString(k.String())
|
||||||
buf.WriteString(": ") //nolint:revive // from builder.go: "It returns the length of r and a nil error."
|
buf.WriteString(": ")
|
||||||
buf.WriteString(v.String()) //nolint:revive // from builder.go: "It returns the length of r and a nil error."
|
buf.WriteString(v.String())
|
||||||
sep = ", "
|
sep = ", "
|
||||||
}
|
}
|
||||||
buf.WriteString("}") //nolint:revive // from builder.go: "It returns the length of r and a nil error."
|
buf.WriteString("}")
|
||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ func getHTTPServer() *httptest.Server {
|
||||||
body, code := getResponseJSON(r.RequestURI)
|
body, code := getResponseJSON(r.RequestURI)
|
||||||
w.WriteHeader(code)
|
w.WriteHeader(code)
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.Write(body) //nolint:errcheck,revive // ignore the returned error as the test will fail anyway
|
w.Write(body) //nolint:errcheck // ignore the returned error as the test will fail anyway
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -61,7 +61,7 @@ func getHTTPServerBasicAuth() *httptest.Server {
|
||||||
body, code := getResponseJSON(r.RequestURI)
|
body, code := getResponseJSON(r.RequestURI)
|
||||||
w.WriteHeader(code)
|
w.WriteHeader(code)
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.Write(body) //nolint:errcheck,revive // ignore the returned error as the test will fail anyway
|
w.Write(body) //nolint:errcheck // ignore the returned error as the test will fail anyway
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -222,9 +222,9 @@ func (m *metric) name() string {
|
||||||
buf := bytes.Buffer{}
|
buf := bytes.Buffer{}
|
||||||
for i := len(m.pathStack) - 1; i >= 0; i-- {
|
for i := len(m.pathStack) - 1; i >= 0; i-- {
|
||||||
if buf.Len() > 0 {
|
if buf.Len() > 0 {
|
||||||
buf.WriteString(".") //nolint:revive // should never return an error
|
buf.WriteString(".")
|
||||||
}
|
}
|
||||||
buf.WriteString(m.pathStack[i]) //nolint:revive // should never return an error
|
buf.WriteString(m.pathStack[i])
|
||||||
}
|
}
|
||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -136,8 +136,7 @@ func (p *PubSubPush) Start(acc telegraf.Accumulator) error {
|
||||||
// Stop cleans up all resources
|
// Stop cleans up all resources
|
||||||
func (p *PubSubPush) Stop() {
|
func (p *PubSubPush) Stop() {
|
||||||
p.cancel()
|
p.cancel()
|
||||||
//nolint:errcheck,revive // we cannot do anything if the shutdown fails
|
p.server.Shutdown(p.ctx) //nolint:errcheck // we cannot do anything if the shutdown fails
|
||||||
p.server.Shutdown(p.ctx)
|
|
||||||
p.wg.Wait()
|
p.wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -83,10 +83,10 @@ func (d *DiskIO) diskInfo(devName string) (map[string]string, error) {
|
||||||
}
|
}
|
||||||
if l[:2] == "S:" {
|
if l[:2] == "S:" {
|
||||||
if devlinks.Len() > 0 {
|
if devlinks.Len() > 0 {
|
||||||
devlinks.WriteString(" ") //nolint:revive // this will never fail
|
devlinks.WriteString(" ")
|
||||||
}
|
}
|
||||||
devlinks.WriteString("/dev/") //nolint:revive // this will never fail
|
devlinks.WriteString("/dev/")
|
||||||
devlinks.WriteString(l[2:]) //nolint:revive // this will never fail
|
devlinks.WriteString(l[2:])
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if l[:2] != "E:" {
|
if l[:2] != "E:" {
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,7 @@ func (c CommandRunner) truncate(buf bytes.Buffer) bytes.Buffer {
|
||||||
buf.Truncate(i)
|
buf.Truncate(i)
|
||||||
}
|
}
|
||||||
if didTruncate {
|
if didTruncate {
|
||||||
buf.WriteString("...") //nolint:revive // will always return nil or panic
|
buf.WriteString("...")
|
||||||
}
|
}
|
||||||
return buf
|
return buf
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,8 +34,7 @@ func (s statServer) serverSocket(l net.Listener) {
|
||||||
|
|
||||||
data := buf[:n]
|
data := buf[:n]
|
||||||
if string(data) == "show stat\n" {
|
if string(data) == "show stat\n" {
|
||||||
//nolint:errcheck,revive // we return anyway
|
c.Write(csvOutputSample) //nolint:errcheck // we return anyway
|
||||||
c.Write(csvOutputSample)
|
|
||||||
}
|
}
|
||||||
}(conn)
|
}(conn)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,7 @@ func setUpTestMux() http.Handler {
|
||||||
fmt.Fprintf(w, "hit the good page!")
|
fmt.Fprintf(w, "hit the good page!")
|
||||||
})
|
})
|
||||||
mux.HandleFunc("/invalidUTF8", func(w http.ResponseWriter, req *http.Request) {
|
mux.HandleFunc("/invalidUTF8", func(w http.ResponseWriter, req *http.Request) {
|
||||||
w.Write([]byte{0xff, 0xfe, 0xfd}) //nolint:errcheck,revive // ignore the returned error as the test will fail anyway
|
w.Write([]byte{0xff, 0xfe, 0xfd}) //nolint:errcheck // ignore the returned error as the test will fail anyway
|
||||||
})
|
})
|
||||||
mux.HandleFunc("/noheader", func(w http.ResponseWriter, req *http.Request) {
|
mux.HandleFunc("/noheader", func(w http.ResponseWriter, req *http.Request) {
|
||||||
fmt.Fprintf(w, "hit the good page!")
|
fmt.Fprintf(w, "hit the good page!")
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,7 @@ func (h mockHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Write(b) //nolint:errcheck,revive // ignore the returned error as the tests will fail anyway
|
w.Write(b) //nolint:errcheck // ignore the returned error as the tests will fail anyway
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGatherNodeData(t *testing.T) {
|
func TestGatherNodeData(t *testing.T) {
|
||||||
|
|
|
||||||
|
|
@ -288,7 +288,7 @@ func TestMain(m *testing.M) {
|
||||||
masterRouter.HandleFunc("/metrics/snapshot", func(w http.ResponseWriter, r *http.Request) {
|
masterRouter.HandleFunc("/metrics/snapshot", func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
json.NewEncoder(w).Encode(masterMetrics) //nolint:errcheck,revive // ignore the returned error as we cannot do anything about it anyway
|
json.NewEncoder(w).Encode(masterMetrics) //nolint:errcheck // ignore the returned error as we cannot do anything about it anyway
|
||||||
})
|
})
|
||||||
masterTestServer = httptest.NewServer(masterRouter)
|
masterTestServer = httptest.NewServer(masterRouter)
|
||||||
|
|
||||||
|
|
@ -296,7 +296,7 @@ func TestMain(m *testing.M) {
|
||||||
slaveRouter.HandleFunc("/metrics/snapshot", func(w http.ResponseWriter, r *http.Request) {
|
slaveRouter.HandleFunc("/metrics/snapshot", func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
json.NewEncoder(w).Encode(slaveMetrics) //nolint:errcheck,revive // ignore the returned error as we cannot do anything about it anyway
|
json.NewEncoder(w).Encode(slaveMetrics) //nolint:errcheck // ignore the returned error as we cannot do anything about it anyway
|
||||||
})
|
})
|
||||||
slaveTestServer = httptest.NewServer(slaveRouter)
|
slaveTestServer = httptest.NewServer(slaveRouter)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -291,7 +291,7 @@ func (c *child) serveRequest(req *request, body io.ReadCloser) {
|
||||||
// some sort of abort request to the host, so the host
|
// some sort of abort request to the host, so the host
|
||||||
// can properly cut off the client sending all the data.
|
// can properly cut off the client sending all the data.
|
||||||
// For now just bound it a little and
|
// For now just bound it a little and
|
||||||
io.CopyN(io.Discard, body, 100<<20) //nolint:errcheck,revive // ignore the returned error as we cannot do anything about it anyway
|
io.CopyN(io.Discard, body, 100<<20) //nolint:errcheck // ignore the returned error as we cannot do anything about it anyway
|
||||||
body.Close()
|
body.Close()
|
||||||
|
|
||||||
if !req.keepConn {
|
if !req.keepConn {
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ func (s statServer) serverSocket(l net.Listener) {
|
||||||
|
|
||||||
data := buf[:n]
|
data := buf[:n]
|
||||||
if string(data) == "show * \n" {
|
if string(data) == "show * \n" {
|
||||||
c.Write([]byte(metrics)) //nolint:errcheck,revive // ignore the returned error as we need to close the socket anyway
|
c.Write([]byte(metrics)) //nolint:errcheck // ignore the returned error as we need to close the socket anyway
|
||||||
c.Close()
|
c.Close()
|
||||||
}
|
}
|
||||||
}(conn)
|
}(conn)
|
||||||
|
|
|
||||||
|
|
@ -127,7 +127,7 @@ func TestV1PowerdnsRecursorGeneratesMetrics(t *testing.T) {
|
||||||
|
|
||||||
data := buf[:n]
|
data := buf[:n]
|
||||||
if string(data) == "get-all\n" {
|
if string(data) == "get-all\n" {
|
||||||
socket.WriteToUnix([]byte(metrics), remote) //nolint:errcheck,revive // ignore the returned error as we need to close the socket anyway
|
socket.WriteToUnix([]byte(metrics), remote) //nolint:errcheck // ignore the returned error as we need to close the socket anyway
|
||||||
socket.Close()
|
socket.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -189,8 +189,8 @@ func TestV2PowerdnsRecursorGeneratesMetrics(t *testing.T) {
|
||||||
|
|
||||||
data := buf[:n]
|
data := buf[:n]
|
||||||
if string(data) == "get-all" {
|
if string(data) == "get-all" {
|
||||||
socket.WriteToUnix([]byte{0, 0, 0, 0}, remote) //nolint:errcheck,revive // ignore the returned error as we need to close the socket anyway
|
socket.WriteToUnix([]byte{0, 0, 0, 0}, remote) //nolint:errcheck // ignore the returned error as we need to close the socket anyway
|
||||||
socket.WriteToUnix([]byte(metrics), remote) //nolint:errcheck,revive // ignore the returned error as we need to close the socket anyway
|
socket.WriteToUnix([]byte(metrics), remote) //nolint:errcheck // ignore the returned error as we need to close the socket anyway
|
||||||
socket.Close()
|
socket.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -258,10 +258,10 @@ func TestV3PowerdnsRecursorGeneratesMetrics(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if string(buf) == "get-all" {
|
if string(buf) == "get-all" {
|
||||||
conn.Write([]byte{0, 0, 0, 0}) //nolint:errcheck,revive // ignore the returned error as we need to close the socket anyway
|
conn.Write([]byte{0, 0, 0, 0}) //nolint:errcheck // ignore the returned error as we need to close the socket anyway
|
||||||
metrics := []byte(metrics)
|
metrics := []byte(metrics)
|
||||||
writeNativeUIntToConn(conn, uint(len(metrics))) //nolint:errcheck,revive // ignore the returned error as we cannot do anything about it anyway
|
writeNativeUIntToConn(conn, uint(len(metrics))) //nolint:errcheck // ignore the returned error as we cannot do anything about it anyway
|
||||||
conn.Write(metrics) //nolint:errcheck,revive // ignore the returned error as we cannot do anything about it anyway
|
conn.Write(metrics) //nolint:errcheck // ignore the returned error as we cannot do anything about it anyway
|
||||||
socket.Close()
|
socket.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -900,8 +900,8 @@ func (s *Statsd) handler(conn *net.TCPConn, id string) {
|
||||||
|
|
||||||
b := s.bufPool.Get().(*bytes.Buffer)
|
b := s.bufPool.Get().(*bytes.Buffer)
|
||||||
b.Reset()
|
b.Reset()
|
||||||
b.Write(scanner.Bytes()) //nolint:revive // Writes to a bytes buffer always succeed, so do not check the errors here
|
b.Write(scanner.Bytes())
|
||||||
b.WriteByte('\n') //nolint:revive // Writes to a bytes buffer always succeed, so do not check the errors here
|
b.WriteByte('\n')
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case s.in <- input{Buffer: b, Time: time.Now(), Addr: remoteIP}:
|
case s.in <- input{Buffer: b, Time: time.Now(), Addr: remoteIP}:
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,7 @@ func (z *Zipkin) Stop() {
|
||||||
defer z.waitGroup.Wait()
|
defer z.waitGroup.Wait()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
z.server.Shutdown(ctx) //nolint:errcheck,revive // Ignore the returned error as we cannot do anything about it anyway
|
z.server.Shutdown(ctx) //nolint:errcheck // Ignore the returned error as we cannot do anything about it anyway
|
||||||
}
|
}
|
||||||
|
|
||||||
// Listen creates an http server on the zipkin instance it is called with, and
|
// Listen creates an http server on the zipkin instance it is called with, and
|
||||||
|
|
|
||||||
|
|
@ -346,20 +346,20 @@ func (a *AzureMonitor) send(body []byte) error {
|
||||||
|
|
||||||
func hashIDWithTagKeysOnly(m telegraf.Metric) uint64 {
|
func hashIDWithTagKeysOnly(m telegraf.Metric) uint64 {
|
||||||
h := fnv.New64a()
|
h := fnv.New64a()
|
||||||
h.Write([]byte(m.Name())) //nolint:revive // from hash.go: "It never returns an error"
|
h.Write([]byte(m.Name()))
|
||||||
h.Write([]byte("\n")) //nolint:revive // from hash.go: "It never returns an error"
|
h.Write([]byte("\n"))
|
||||||
for _, tag := range m.TagList() {
|
for _, tag := range m.TagList() {
|
||||||
if tag.Key == "" || tag.Value == "" {
|
if tag.Key == "" || tag.Value == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
h.Write([]byte(tag.Key)) //nolint:revive // from hash.go: "It never returns an error"
|
h.Write([]byte(tag.Key))
|
||||||
h.Write([]byte("\n")) //nolint:revive // from hash.go: "It never returns an error"
|
h.Write([]byte("\n"))
|
||||||
}
|
}
|
||||||
b := make([]byte, binary.MaxVarintLen64)
|
b := make([]byte, binary.MaxVarintLen64)
|
||||||
n := binary.PutUvarint(b, uint64(m.Time().UnixNano()))
|
n := binary.PutUvarint(b, uint64(m.Time().UnixNano()))
|
||||||
h.Write(b[:n]) //nolint:revive // from hash.go: "It never returns an error"
|
h.Write(b[:n])
|
||||||
h.Write([]byte("\n")) //nolint:revive // from hash.go: "It never returns an error"
|
h.Write([]byte("\n"))
|
||||||
return h.Sum64()
|
return h.Sum64()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -553,10 +553,10 @@ func hashIDWithField(id uint64, fk string) uint64 {
|
||||||
h := fnv.New64a()
|
h := fnv.New64a()
|
||||||
b := make([]byte, binary.MaxVarintLen64)
|
b := make([]byte, binary.MaxVarintLen64)
|
||||||
n := binary.PutUvarint(b, id)
|
n := binary.PutUvarint(b, id)
|
||||||
h.Write(b[:n]) //nolint:revive // from hash.go: "It never returns an error"
|
h.Write(b[:n])
|
||||||
h.Write([]byte("\n")) //nolint:revive // from hash.go: "It never returns an error"
|
h.Write([]byte("\n"))
|
||||||
h.Write([]byte(fk)) //nolint:revive // from hash.go: "It never returns an error"
|
h.Write([]byte(fk))
|
||||||
h.Write([]byte("\n")) //nolint:revive // from hash.go: "It never returns an error"
|
h.Write([]byte("\n"))
|
||||||
return h.Sum64()
|
return h.Sum64()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -202,7 +202,7 @@ func escapeString(s string, quote string) string {
|
||||||
// [1] https://github.com/influxdata/telegraf/pull/3210#discussion_r148411201
|
// [1] https://github.com/influxdata/telegraf/pull/3210#discussion_r148411201
|
||||||
func hashID(m telegraf.Metric) int64 {
|
func hashID(m telegraf.Metric) int64 {
|
||||||
h := sha512.New()
|
h := sha512.New()
|
||||||
h.Write([]byte(m.Name())) //nolint:revive // from hash.go: "It never returns an error"
|
h.Write([]byte(m.Name()))
|
||||||
tags := m.Tags()
|
tags := m.Tags()
|
||||||
tmp := make([]string, 0, len(tags))
|
tmp := make([]string, 0, len(tags))
|
||||||
for k, v := range tags {
|
for k, v := range tags {
|
||||||
|
|
@ -211,7 +211,7 @@ func hashID(m telegraf.Metric) int64 {
|
||||||
sort.Strings(tmp)
|
sort.Strings(tmp)
|
||||||
|
|
||||||
for _, s := range tmp {
|
for _, s := range tmp {
|
||||||
h.Write([]byte(s)) //nolint:revive // from hash.go: "It never returns an error"
|
h.Write([]byte(s))
|
||||||
}
|
}
|
||||||
sum := h.Sum(nil)
|
sum := h.Sum(nil)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,8 +37,7 @@ func fakeDatadog() *Datadog {
|
||||||
func TestUriOverride(t *testing.T) {
|
func TestUriOverride(t *testing.T) {
|
||||||
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.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
//nolint:errcheck,revive // Ignore the returned error as the test will fail anyway
|
json.NewEncoder(w).Encode(`{"status":"ok"}`) //nolint:errcheck // Ignore the returned error as the test will fail anyway
|
||||||
json.NewEncoder(w).Encode(`{"status":"ok"}`)
|
|
||||||
}))
|
}))
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
||||||
|
|
@ -53,8 +52,7 @@ func TestUriOverride(t *testing.T) {
|
||||||
func TestCompressionOverride(t *testing.T) {
|
func TestCompressionOverride(t *testing.T) {
|
||||||
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.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
//nolint:errcheck,revive // Ignore the returned error as the test will fail anyway
|
json.NewEncoder(w).Encode(`{"status":"ok"}`) //nolint:errcheck // Ignore the returned error as the test will fail anyway
|
||||||
json.NewEncoder(w).Encode(`{"status":"ok"}`)
|
|
||||||
}))
|
}))
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -237,9 +237,9 @@ func GetPointID(m telegraf.Metric) string {
|
||||||
var buffer bytes.Buffer
|
var buffer bytes.Buffer
|
||||||
//Timestamp(ns),measurement name and Series Hash for compute the final SHA256 based hash ID
|
//Timestamp(ns),measurement name and Series Hash for compute the final SHA256 based hash ID
|
||||||
|
|
||||||
buffer.WriteString(strconv.FormatInt(m.Time().Local().UnixNano(), 10)) //nolint:revive // from buffer.go: "err is always nil"
|
buffer.WriteString(strconv.FormatInt(m.Time().Local().UnixNano(), 10))
|
||||||
buffer.WriteString(m.Name()) //nolint:revive // from buffer.go: "err is always nil"
|
buffer.WriteString(m.Name())
|
||||||
buffer.WriteString(strconv.FormatUint(m.HashID(), 10)) //nolint:revive // from buffer.go: "err is always nil"
|
buffer.WriteString(strconv.FormatUint(m.HashID(), 10))
|
||||||
|
|
||||||
return fmt.Sprintf("%x", sha256.Sum256(buffer.Bytes()))
|
return fmt.Sprintf("%x", sha256.Sum256(buffer.Bytes()))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ func (e *Exec) Write(metrics []telegraf.Metric) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
buffer.Write(serializedMetrics) //nolint:revive // from buffer.go: "err is always nil"
|
buffer.Write(serializedMetrics)
|
||||||
|
|
||||||
if buffer.Len() <= 0 {
|
if buffer.Len() <= 0 {
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -141,7 +141,7 @@ func (c *CommandRunner) truncate(buf bytes.Buffer) string {
|
||||||
buf.Truncate(i)
|
buf.Truncate(i)
|
||||||
}
|
}
|
||||||
if didTruncate {
|
if didTruncate {
|
||||||
buf.WriteString("...") //nolint:revive // from buffer.go: "err is always nil"
|
buf.WriteString("...")
|
||||||
}
|
}
|
||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -164,29 +164,29 @@ func (g *gelfUDP) createChunkedMessage(index int, chunkCountInt int, id []byte,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return packet, err
|
return packet, err
|
||||||
}
|
}
|
||||||
packet.Write(b) //nolint:revive // from buffer.go: "err is always nil"
|
packet.Write(b)
|
||||||
|
|
||||||
b, err = g.intToBytes(15)
|
b, err = g.intToBytes(15)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return packet, err
|
return packet, err
|
||||||
}
|
}
|
||||||
packet.Write(b) //nolint:revive // from buffer.go: "err is always nil"
|
packet.Write(b)
|
||||||
|
|
||||||
packet.Write(id) //nolint:revive // from buffer.go: "err is always nil"
|
packet.Write(id)
|
||||||
|
|
||||||
b, err = g.intToBytes(index)
|
b, err = g.intToBytes(index)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return packet, err
|
return packet, err
|
||||||
}
|
}
|
||||||
packet.Write(b) //nolint:revive // from buffer.go: "err is always nil"
|
packet.Write(b)
|
||||||
|
|
||||||
b, err = g.intToBytes(chunkCountInt)
|
b, err = g.intToBytes(chunkCountInt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return packet, err
|
return packet, err
|
||||||
}
|
}
|
||||||
packet.Write(b) //nolint:revive // from buffer.go: "err is always nil"
|
packet.Write(b)
|
||||||
|
|
||||||
packet.Write(compressed.Next(chunksize)) //nolint:revive // from buffer.go: "err is always nil"
|
packet.Write(compressed.Next(chunksize))
|
||||||
|
|
||||||
return packet, nil
|
return packet, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@ func TestUDP_Simple(t *testing.T) {
|
||||||
DialContextF: func(network, address string) (influxdb.Conn, error) {
|
DialContextF: func(network, address string) (influxdb.Conn, error) {
|
||||||
conn := &MockConn{
|
conn := &MockConn{
|
||||||
WriteF: func(b []byte) (n int, err error) {
|
WriteF: func(b []byte) (n int, err error) {
|
||||||
buffer.Write(b) //nolint:revive // MockConn with always-success return
|
buffer.Write(b)
|
||||||
return 0, nil
|
return 0, nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -384,8 +384,8 @@ func (cols Columns) Fields() Columns {
|
||||||
func (cols Columns) Hash() string {
|
func (cols Columns) Hash() string {
|
||||||
hash := fnv.New32a()
|
hash := fnv.New32a()
|
||||||
for _, tc := range cols.Sorted() {
|
for _, tc := range cols.Sorted() {
|
||||||
hash.Write([]byte(tc.Name)) //nolint:revive // all Write() methods for hash in fnv.go returns nil err
|
hash.Write([]byte(tc.Name))
|
||||||
hash.Write([]byte{0}) //nolint:revive // all Write() methods for hash in fnv.go returns nil err
|
hash.Write([]byte{0})
|
||||||
}
|
}
|
||||||
return strings.ToLower(base32.StdEncoding.WithPadding(base32.NoPadding).EncodeToString(hash.Sum(nil)))
|
return strings.ToLower(base32.StdEncoding.WithPadding(base32.NoPadding).EncodeToString(hash.Sum(nil)))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ func NewTableSources(p *Postgresql, metrics []telegraf.Metric) map[string]*Table
|
||||||
|
|
||||||
func NewTableSource(postgresql *Postgresql, name string) *TableSource {
|
func NewTableSource(postgresql *Postgresql, name string) *TableSource {
|
||||||
h := fnv.New64a()
|
h := fnv.New64a()
|
||||||
h.Write([]byte(name)) //nolint:revive // all Write() methods for hash in fnv.go returns nil err
|
h.Write([]byte(name))
|
||||||
|
|
||||||
tsrc := &TableSource{
|
tsrc := &TableSource{
|
||||||
postgresql: postgresql,
|
postgresql: postgresql,
|
||||||
|
|
|
||||||
|
|
@ -71,10 +71,10 @@ func (l PGXLogger) Log(_ context.Context, level pgx.LogLevel, msg string, data m
|
||||||
func GetTagID(metric telegraf.Metric) int64 {
|
func GetTagID(metric telegraf.Metric) int64 {
|
||||||
hash := fnv.New64a()
|
hash := fnv.New64a()
|
||||||
for _, tag := range metric.TagList() {
|
for _, tag := range metric.TagList() {
|
||||||
hash.Write([]byte(tag.Key)) //nolint:revive // all Write() methods for hash in fnv.go returns nil err
|
hash.Write([]byte(tag.Key))
|
||||||
hash.Write([]byte{0}) //nolint:revive // all Write() methods for hash in fnv.go returns nil err
|
hash.Write([]byte{0})
|
||||||
hash.Write([]byte(tag.Value)) //nolint:revive // all Write() methods for hash in fnv.go returns nil err
|
hash.Write([]byte(tag.Value))
|
||||||
hash.Write([]byte{0}) //nolint:revive // all Write() methods for hash in fnv.go returns nil err
|
hash.Write([]byte{0})
|
||||||
}
|
}
|
||||||
// Convert to int64 as postgres does not support uint64
|
// Convert to int64 as postgres does not support uint64
|
||||||
return int64(hash.Sum64())
|
return int64(hash.Sum64())
|
||||||
|
|
|
||||||
|
|
@ -114,15 +114,15 @@ type timeSeriesBuckets map[uint64][]*monitoringpb.TimeSeries
|
||||||
|
|
||||||
func (tsb timeSeriesBuckets) Add(m telegraf.Metric, f *telegraf.Field, ts *monitoringpb.TimeSeries) {
|
func (tsb timeSeriesBuckets) Add(m telegraf.Metric, f *telegraf.Field, ts *monitoringpb.TimeSeries) {
|
||||||
h := fnv.New64a()
|
h := fnv.New64a()
|
||||||
h.Write([]byte(m.Name())) //nolint:revive // from hash.go: "It never returns an error"
|
h.Write([]byte(m.Name()))
|
||||||
h.Write([]byte{'\n'}) //nolint:revive // from hash.go: "It never returns an error"
|
h.Write([]byte{'\n'})
|
||||||
h.Write([]byte(f.Key)) //nolint:revive // from hash.go: "It never returns an error"
|
h.Write([]byte(f.Key))
|
||||||
h.Write([]byte{'\n'}) //nolint:revive // from hash.go: "It never returns an error"
|
h.Write([]byte{'\n'})
|
||||||
for key, value := range m.Tags() {
|
for key, value := range m.Tags() {
|
||||||
h.Write([]byte(key)) //nolint:revive // from hash.go: "It never returns an error"
|
h.Write([]byte(key))
|
||||||
h.Write([]byte{'\n'}) //nolint:revive // from hash.go: "It never returns an error"
|
h.Write([]byte{'\n'})
|
||||||
h.Write([]byte(value)) //nolint:revive // from hash.go: "It never returns an error"
|
h.Write([]byte(value))
|
||||||
h.Write([]byte{'\n'}) //nolint:revive // from hash.go: "It never returns an error"
|
h.Write([]byte{'\n'})
|
||||||
}
|
}
|
||||||
k := h.Sum64()
|
k := h.Sum64()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,7 @@ func (p *Parser) Parse(buf []byte) ([]telegraf.Metric, error) {
|
||||||
metrics = append(metrics, ms...)
|
metrics = append(metrics, ms...)
|
||||||
fallthrough
|
fallthrough
|
||||||
case 1:
|
case 1:
|
||||||
msg.Write(bytes.TrimSpace(parts[0])) //nolint:revive // from buffer.go: "err is always nil"
|
msg.Write(bytes.TrimSpace(parts[0]))
|
||||||
default:
|
default:
|
||||||
return nil, errors.New("illegal output format")
|
return nil, errors.New("illegal output format")
|
||||||
}
|
}
|
||||||
|
|
@ -145,9 +145,9 @@ func (p *Parser) Parse(buf []byte) ([]telegraf.Metric, error) {
|
||||||
if bytes.Contains(s.Bytes(), []byte{'|'}) {
|
if bytes.Contains(s.Bytes(), []byte{'|'}) {
|
||||||
parts := bytes.Split(s.Bytes(), []byte{'|'})
|
parts := bytes.Split(s.Bytes(), []byte{'|'})
|
||||||
if longmsg.Len() != 0 {
|
if longmsg.Len() != 0 {
|
||||||
longmsg.WriteByte('\n') //nolint:revive // from buffer.go: "err is always nil"
|
longmsg.WriteByte('\n')
|
||||||
}
|
}
|
||||||
longmsg.Write(bytes.TrimSpace(parts[0])) //nolint:revive // from buffer.go: "err is always nil"
|
longmsg.Write(bytes.TrimSpace(parts[0]))
|
||||||
|
|
||||||
ms, err := parsePerfData(string(parts[1]), ts)
|
ms, err := parsePerfData(string(parts[1]), ts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -157,9 +157,9 @@ func (p *Parser) Parse(buf []byte) ([]telegraf.Metric, error) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if longmsg.Len() != 0 {
|
if longmsg.Len() != 0 {
|
||||||
longmsg.WriteByte('\n') //nolint:revive // from buffer.go: "err is always nil"
|
longmsg.WriteByte('\n')
|
||||||
}
|
}
|
||||||
longmsg.Write(bytes.TrimSpace(s.Bytes())) //nolint:revive // from buffer.go: "err is always nil"
|
longmsg.Write(bytes.TrimSpace(s.Bytes()))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse extra performance data.
|
// Parse extra performance data.
|
||||||
|
|
|
||||||
|
|
@ -204,7 +204,7 @@ func (p *PointParser) unscanTokens(n int) {
|
||||||
func (p *PointParser) reset(buf []byte) {
|
func (p *PointParser) reset(buf []byte) {
|
||||||
// reset the scan buffer and write new byte
|
// reset the scan buffer and write new byte
|
||||||
p.scanBuf.Reset()
|
p.scanBuf.Reset()
|
||||||
p.scanBuf.Write(buf) //nolint:revive // from buffer.go: "err is always nil"
|
p.scanBuf.Write(buf)
|
||||||
|
|
||||||
if p.s == nil {
|
if p.s == nil {
|
||||||
p.s = NewScanner(&p.scanBuf)
|
p.s = NewScanner(&p.scanBuf)
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ func (s *Serializer) Serialize(metric telegraf.Metric) ([]byte, error) {
|
||||||
func (s *Serializer) SerializeBatch(metrics []telegraf.Metric) ([]byte, error) {
|
func (s *Serializer) SerializeBatch(metrics []telegraf.Metric) ([]byte, error) {
|
||||||
var batch bytes.Buffer
|
var batch bytes.Buffer
|
||||||
for _, metric := range metrics {
|
for _, metric := range metrics {
|
||||||
batch.Write(s.createObject(metric)) //nolint:revive // from buffer.go: "err is always nil"
|
batch.Write(s.createObject(metric))
|
||||||
}
|
}
|
||||||
return batch.Bytes(), nil
|
return batch.Bytes(), nil
|
||||||
}
|
}
|
||||||
|
|
@ -83,27 +83,27 @@ func (s *Serializer) createObject(metric telegraf.Metric) []byte {
|
||||||
|
|
||||||
switch metricsFormat {
|
switch metricsFormat {
|
||||||
case Carbon2FormatFieldSeparate:
|
case Carbon2FormatFieldSeparate:
|
||||||
m.WriteString(serializeMetricFieldSeparate(name, fieldName)) //nolint:revive // from buffer.go: "err is always nil"
|
m.WriteString(serializeMetricFieldSeparate(name, fieldName))
|
||||||
|
|
||||||
case Carbon2FormatMetricIncludesField:
|
case Carbon2FormatMetricIncludesField:
|
||||||
m.WriteString(serializeMetricIncludeField(name, fieldName)) //nolint:revive // from buffer.go: "err is always nil"
|
m.WriteString(serializeMetricIncludeField(name, fieldName))
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tag := range metric.TagList() {
|
for _, tag := range metric.TagList() {
|
||||||
m.WriteString(strings.ReplaceAll(tag.Key, " ", "_")) //nolint:revive // from buffer.go: "err is always nil"
|
m.WriteString(strings.ReplaceAll(tag.Key, " ", "_"))
|
||||||
m.WriteString("=") //nolint:revive // from buffer.go: "err is always nil"
|
m.WriteString("=")
|
||||||
value := tag.Value
|
value := tag.Value
|
||||||
if len(value) == 0 {
|
if len(value) == 0 {
|
||||||
value = "null"
|
value = "null"
|
||||||
}
|
}
|
||||||
m.WriteString(strings.ReplaceAll(value, " ", "_")) //nolint:revive // from buffer.go: "err is always nil"
|
m.WriteString(strings.ReplaceAll(value, " ", "_"))
|
||||||
m.WriteString(" ") //nolint:revive // from buffer.go: "err is always nil"
|
m.WriteString(" ")
|
||||||
}
|
}
|
||||||
m.WriteString(" ") //nolint:revive // from buffer.go: "err is always nil"
|
m.WriteString(" ")
|
||||||
m.WriteString(formatValue(fieldValue)) //nolint:revive // from buffer.go: "err is always nil"
|
m.WriteString(formatValue(fieldValue))
|
||||||
m.WriteString(" ") //nolint:revive // from buffer.go: "err is always nil"
|
m.WriteString(" ")
|
||||||
m.WriteString(strconv.FormatInt(metric.Time().Unix(), 10)) //nolint:revive // from buffer.go: "err is always nil"
|
m.WriteString(strconv.FormatInt(metric.Time().Unix(), 10))
|
||||||
m.WriteString("\n") //nolint:revive // from buffer.go: "err is always nil"
|
m.WriteString("\n")
|
||||||
}
|
}
|
||||||
return m.Bytes()
|
return m.Bytes()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -87,10 +87,10 @@ type MetricKey uint64
|
||||||
func MakeMetricKey(labels []LabelPair) MetricKey {
|
func MakeMetricKey(labels []LabelPair) MetricKey {
|
||||||
h := fnv.New64a()
|
h := fnv.New64a()
|
||||||
for _, label := range labels {
|
for _, label := range labels {
|
||||||
h.Write([]byte(label.Name)) //nolint:revive // from hash.go: "It never returns an error"
|
h.Write([]byte(label.Name))
|
||||||
h.Write([]byte("\x00")) //nolint:revive // from hash.go: "It never returns an error"
|
h.Write([]byte("\x00"))
|
||||||
h.Write([]byte(label.Value)) //nolint:revive // from hash.go: "It never returns an error"
|
h.Write([]byte(label.Value))
|
||||||
h.Write([]byte("\x00")) //nolint:revive // from hash.go: "It never returns an error"
|
h.Write([]byte("\x00"))
|
||||||
}
|
}
|
||||||
return MetricKey(h.Sum64())
|
return MetricKey(h.Sum64())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -90,13 +90,13 @@ func sanitize(name string, table Table) (string, bool) {
|
||||||
switch {
|
switch {
|
||||||
case i == 0:
|
case i == 0:
|
||||||
if unicode.In(r, table.First) {
|
if unicode.In(r, table.First) {
|
||||||
b.WriteRune(r) //nolint:revive // from builder.go: "It returns the length of r and a nil error."
|
b.WriteRune(r)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
if unicode.In(r, table.Rest) {
|
if unicode.In(r, table.Rest) {
|
||||||
b.WriteRune(r) //nolint:revive // from builder.go: "It returns the length of r and a nil error."
|
b.WriteRune(r)
|
||||||
} else {
|
} else {
|
||||||
b.WriteString("_") //nolint:revive // from builder.go: "It returns the length of s and a nil error."
|
b.WriteString("_")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -239,7 +239,7 @@ func (s *Serializer) SerializeBatch(metrics []telegraf.Metric) ([]byte, error) {
|
||||||
return nil, fmt.Errorf("unable to marshal protobuf: %w", err)
|
return nil, fmt.Errorf("unable to marshal protobuf: %w", err)
|
||||||
}
|
}
|
||||||
encoded := snappy.Encode(nil, data)
|
encoded := snappy.Encode(nil, data)
|
||||||
buf.Write(encoded) //nolint:revive // from buffer.go: "err is always nil"
|
buf.Write(encoded)
|
||||||
return buf.Bytes(), nil
|
return buf.Bytes(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -318,10 +318,10 @@ func (s *Serializer) createLabels(metric telegraf.Metric) []prompb.Label {
|
||||||
func MakeMetricKey(labels []prompb.Label) MetricKey {
|
func MakeMetricKey(labels []prompb.Label) MetricKey {
|
||||||
h := fnv.New64a()
|
h := fnv.New64a()
|
||||||
for _, label := range labels {
|
for _, label := range labels {
|
||||||
h.Write([]byte(label.Name)) //nolint:revive // from hash.go: "It never returns an error"
|
h.Write([]byte(label.Name))
|
||||||
h.Write([]byte("\x00")) //nolint:revive // from hash.go: "It never returns an error"
|
h.Write([]byte("\x00"))
|
||||||
h.Write([]byte(label.Value)) //nolint:revive // from hash.go: "It never returns an error"
|
h.Write([]byte(label.Value))
|
||||||
h.Write([]byte("\x00")) //nolint:revive // from hash.go: "It never returns an error"
|
h.Write([]byte("\x00"))
|
||||||
}
|
}
|
||||||
return MetricKey(h.Sum64())
|
return MetricKey(h.Sum64())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -175,7 +175,7 @@ func (r *Registry) set(key uint64, s Stat) {
|
||||||
|
|
||||||
func key(measurement string, tags map[string]string) uint64 {
|
func key(measurement string, tags map[string]string) uint64 {
|
||||||
h := fnv.New64a()
|
h := fnv.New64a()
|
||||||
h.Write([]byte(measurement)) //nolint:revive // all Write() methods for hash in fnv.go returns nil err
|
h.Write([]byte(measurement))
|
||||||
|
|
||||||
tmp := make([]string, 0, len(tags))
|
tmp := make([]string, 0, len(tags))
|
||||||
for k, v := range tags {
|
for k, v := range tags {
|
||||||
|
|
@ -184,7 +184,7 @@ func key(measurement string, tags map[string]string) uint64 {
|
||||||
sort.Strings(tmp)
|
sort.Strings(tmp)
|
||||||
|
|
||||||
for _, s := range tmp {
|
for _, s := range tmp {
|
||||||
h.Write([]byte(s)) //nolint:revive // all Write() methods for hash in fnv.go returns nil err
|
h.Write([]byte(s))
|
||||||
}
|
}
|
||||||
|
|
||||||
return h.Sum64()
|
return h.Sum64()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue