chore: Remove usages of github.com/pkg/errors dependency (archived) (#12787)
Co-authored-by: Pawel Zak <Pawel Zak>
This commit is contained in:
parent
dfe8b43e20
commit
d59ea7d0ce
2
go.mod
2
go.mod
|
|
@ -138,7 +138,6 @@ require (
|
||||||
github.com/p4lang/p4runtime v1.3.0
|
github.com/p4lang/p4runtime v1.3.0
|
||||||
github.com/pborman/ansi v1.0.0
|
github.com/pborman/ansi v1.0.0
|
||||||
github.com/pion/dtls/v2 v2.2.4
|
github.com/pion/dtls/v2 v2.2.4
|
||||||
github.com/pkg/errors v0.9.1
|
|
||||||
github.com/prometheus-community/pro-bing v0.1.0
|
github.com/prometheus-community/pro-bing v0.1.0
|
||||||
github.com/prometheus/client_golang v1.14.0
|
github.com/prometheus/client_golang v1.14.0
|
||||||
github.com/prometheus/client_model v0.3.0
|
github.com/prometheus/client_model v0.3.0
|
||||||
|
|
@ -374,6 +373,7 @@ require (
|
||||||
github.com/pion/transport/v2 v2.0.0 // indirect
|
github.com/pion/transport/v2 v2.0.0 // indirect
|
||||||
github.com/pion/udp v0.1.4 // indirect
|
github.com/pion/udp v0.1.4 // indirect
|
||||||
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect
|
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect
|
||||||
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
github.com/pkg/sftp v1.13.5 // indirect
|
github.com/pkg/sftp v1.13.5 // indirect
|
||||||
github.com/pkg/xattr v0.4.9 // indirect
|
github.com/pkg/xattr v0.4.9 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@ import (
|
||||||
"github.com/gopcua/opcua"
|
"github.com/gopcua/opcua"
|
||||||
"github.com/gopcua/opcua/debug"
|
"github.com/gopcua/opcua/debug"
|
||||||
"github.com/gopcua/opcua/ua"
|
"github.com/gopcua/opcua/ua"
|
||||||
"github.com/pkg/errors"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// SELF SIGNED CERT FUNCTIONS
|
// SELF SIGNED CERT FUNCTIONS
|
||||||
|
|
@ -345,6 +344,5 @@ func validateEndpointConfig(endpoints []*ua.EndpointDescription, secPolicy strin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err := errors.Errorf("server does not support an endpoint with security : %s , %s", secPolicy, secMode)
|
return fmt.Errorf("server does not support an endpoint with security: %q, %q", secPolicy, secMode)
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ package aliyuncms
|
||||||
import (
|
import (
|
||||||
_ "embed"
|
_ "embed"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -14,7 +15,6 @@ import (
|
||||||
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials/providers"
|
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials/providers"
|
||||||
"github.com/aliyun/alibaba-cloud-sdk-go/services/cms"
|
"github.com/aliyun/alibaba-cloud-sdk-go/services/cms"
|
||||||
"github.com/jmespath/go-jmespath"
|
"github.com/jmespath/go-jmespath"
|
||||||
"github.com/pkg/errors"
|
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
"github.com/influxdata/telegraf/config"
|
"github.com/influxdata/telegraf/config"
|
||||||
|
|
@ -142,11 +142,11 @@ func (s *AliyunCMS) Init() error {
|
||||||
}
|
}
|
||||||
credential, err := providers.NewChainProvider(credentialProviders).Retrieve()
|
credential, err := providers.NewChainProvider(credentialProviders).Retrieve()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Errorf("failed to retrieve credential: %v", err)
|
return fmt.Errorf("failed to retrieve credential: %w", err)
|
||||||
}
|
}
|
||||||
s.client, err = cms.NewClientWithOptions("", sdk.NewConfig(), credential)
|
s.client, err = cms.NewClientWithOptions("", sdk.NewConfig(), credential)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Errorf("failed to create cms client: %v", err)
|
return fmt.Errorf("failed to create cms client: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
//check metrics dimensions consistency
|
//check metrics dimensions consistency
|
||||||
|
|
@ -162,7 +162,7 @@ func (s *AliyunCMS) Init() error {
|
||||||
err := json.Unmarshal([]byte(metric.Dimensions), &metric.dimensionsUdArr)
|
err := json.Unmarshal([]byte(metric.Dimensions), &metric.dimensionsUdArr)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Errorf("cannot parse dimensions (neither obj, nor array) %q :%v", metric.Dimensions, err)
|
return fmt.Errorf("cannot parse dimensions (neither obj, nor array) %q: %w", metric.Dimensions, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -282,7 +282,7 @@ func (s *AliyunCMS) gatherMetric(acc telegraf.Accumulator, metricName string, me
|
||||||
for more := true; more; {
|
for more := true; more; {
|
||||||
resp, err := s.client.DescribeMetricList(req)
|
resp, err := s.client.DescribeMetricList(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Errorf("failed to query metricName list: %v", err)
|
return fmt.Errorf("failed to query metricName list: %w", err)
|
||||||
}
|
}
|
||||||
if resp.Code != "200" {
|
if resp.Code != "200" {
|
||||||
s.Log.Errorf("failed to query metricName list: %v", resp.Message)
|
s.Log.Errorf("failed to query metricName list: %v", resp.Message)
|
||||||
|
|
@ -291,7 +291,7 @@ func (s *AliyunCMS) gatherMetric(acc telegraf.Accumulator, metricName string, me
|
||||||
|
|
||||||
var datapoints []map[string]interface{}
|
var datapoints []map[string]interface{}
|
||||||
if err := json.Unmarshal([]byte(resp.Datapoints), &datapoints); err != nil {
|
if err := json.Unmarshal([]byte(resp.Datapoints), &datapoints); err != nil {
|
||||||
return errors.Errorf("failed to decode response datapoints: %v", err)
|
return fmt.Errorf("failed to decode response datapoints: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(datapoints) == 0 {
|
if len(datapoints) == 0 {
|
||||||
|
|
@ -356,8 +356,7 @@ func parseTag(tagSpec string, data interface{}) (tagKey string, tagValue string,
|
||||||
|
|
||||||
tagRawValue, err := jmespath.Search(queryPath, data)
|
tagRawValue, err := jmespath.Search(queryPath, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", errors.Errorf("Can't query data from discovery data using query path %q: %v",
|
return "", "", fmt.Errorf("can't query data from discovery data using query path %q: %w", queryPath, err)
|
||||||
queryPath, err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if tagRawValue == nil { //Nothing found
|
if tagRawValue == nil { //Nothing found
|
||||||
|
|
@ -366,8 +365,7 @@ func parseTag(tagSpec string, data interface{}) (tagKey string, tagValue string,
|
||||||
|
|
||||||
tagValue, ok = tagRawValue.(string)
|
tagValue, ok = tagRawValue.(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
return "", "", errors.Errorf("Tag value %v parsed by query %q is not a string value",
|
return "", "", fmt.Errorf("tag value %q parsed by query %q is not a string value", tagRawValue, queryPath)
|
||||||
tagRawValue, queryPath)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return tagKey, tagValue, nil
|
return tagKey, tagValue, nil
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ package aliyuncms
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
@ -12,7 +14,6 @@ import (
|
||||||
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
|
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
|
||||||
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses"
|
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses"
|
||||||
"github.com/aliyun/alibaba-cloud-sdk-go/services/cms"
|
"github.com/aliyun/alibaba-cloud-sdk-go/services/cms"
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
|
|
@ -93,13 +94,13 @@ func getDiscoveryTool(project string, discoverRegions []string) (*discoveryTool,
|
||||||
}
|
}
|
||||||
credential, err = providers.NewChainProvider(credentialProviders).Retrieve()
|
credential, err = providers.NewChainProvider(credentialProviders).Retrieve()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Errorf("failed to retrieve credential: %v", err)
|
return nil, fmt.Errorf("failed to retrieve credential: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
dt, err := newDiscoveryTool(discoverRegions, project, testutil.Logger{Name: inputTitle}, credential, 1, time.Minute*2)
|
dt, err := newDiscoveryTool(discoverRegions, project, testutil.Logger{Name: inputTitle}, credential, 1, time.Minute*2)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Errorf("Can't create discovery tool object: %v", err)
|
return nil, fmt.Errorf("can't create discovery tool object: %w", err)
|
||||||
}
|
}
|
||||||
return dt, nil
|
return dt, nil
|
||||||
}
|
}
|
||||||
|
|
@ -107,7 +108,7 @@ func getDiscoveryTool(project string, discoverRegions []string) (*discoveryTool,
|
||||||
func getMockSdkCli(httpResp *http.Response) (mockAliyunSDKCli, error) {
|
func getMockSdkCli(httpResp *http.Response) (mockAliyunSDKCli, error) {
|
||||||
resp := responses.NewCommonResponse()
|
resp := responses.NewCommonResponse()
|
||||||
if err := responses.Unmarshal(resp, httpResp, "JSON"); err != nil {
|
if err := responses.Unmarshal(resp, httpResp, "JSON"); err != nil {
|
||||||
return mockAliyunSDKCli{}, errors.Errorf("Can't parse response: %v", err)
|
return mockAliyunSDKCli{}, fmt.Errorf("can't parse response: %w", err)
|
||||||
}
|
}
|
||||||
return mockAliyunSDKCli{resp: resp}, nil
|
return mockAliyunSDKCli{resp: resp}, nil
|
||||||
}
|
}
|
||||||
|
|
@ -273,7 +274,7 @@ func TestPluginMetricsInitialize(t *testing.T) {
|
||||||
regions: []string{"cn-shanghai"},
|
regions: []string{"cn-shanghai"},
|
||||||
accessKeyID: "dummy",
|
accessKeyID: "dummy",
|
||||||
accessKeySecret: "dummy",
|
accessKeySecret: "dummy",
|
||||||
expectedErrorString: `cannot parse dimensions (neither obj, nor array) "[" :unexpected end of JSON input`,
|
expectedErrorString: `cannot parse dimensions (neither obj, nor array) "[": unexpected end of JSON input`,
|
||||||
metrics: []*Metric{
|
metrics: []*Metric{
|
||||||
{
|
{
|
||||||
MetricNames: []string{},
|
MetricNames: []string{},
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ package aliyuncms
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -16,7 +18,6 @@ import (
|
||||||
"github.com/aliyun/alibaba-cloud-sdk-go/services/rds"
|
"github.com/aliyun/alibaba-cloud-sdk-go/services/rds"
|
||||||
"github.com/aliyun/alibaba-cloud-sdk-go/services/slb"
|
"github.com/aliyun/alibaba-cloud-sdk-go/services/slb"
|
||||||
"github.com/aliyun/alibaba-cloud-sdk-go/services/vpc"
|
"github.com/aliyun/alibaba-cloud-sdk-go/services/vpc"
|
||||||
"github.com/pkg/errors"
|
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
"github.com/influxdata/telegraf/internal/limiter"
|
"github.com/influxdata/telegraf/internal/limiter"
|
||||||
|
|
@ -58,7 +59,7 @@ type parsedDResp struct {
|
||||||
func getRPCReqFromDiscoveryRequest(req discoveryRequest) (*requests.RpcRequest, error) {
|
func getRPCReqFromDiscoveryRequest(req discoveryRequest) (*requests.RpcRequest, error) {
|
||||||
if reflect.ValueOf(req).Type().Kind() != reflect.Ptr ||
|
if reflect.ValueOf(req).Type().Kind() != reflect.Ptr ||
|
||||||
reflect.ValueOf(req).IsNil() {
|
reflect.ValueOf(req).IsNil() {
|
||||||
return nil, errors.Errorf("unexpected type of the discovery request object: %q, %q", reflect.ValueOf(req).Type(), reflect.ValueOf(req).Kind())
|
return nil, fmt.Errorf("unexpected type of the discovery request object: %q, %q", reflect.ValueOf(req).Type(), reflect.ValueOf(req).Kind())
|
||||||
}
|
}
|
||||||
|
|
||||||
ptrV := reflect.Indirect(reflect.ValueOf(req))
|
ptrV := reflect.Indirect(reflect.ValueOf(req))
|
||||||
|
|
@ -66,19 +67,19 @@ func getRPCReqFromDiscoveryRequest(req discoveryRequest) (*requests.RpcRequest,
|
||||||
for i := 0; i < ptrV.NumField(); i++ {
|
for i := 0; i < ptrV.NumField(); i++ {
|
||||||
if ptrV.Field(i).Type().String() == "*requests.RpcRequest" {
|
if ptrV.Field(i).Type().String() == "*requests.RpcRequest" {
|
||||||
if !ptrV.Field(i).CanInterface() {
|
if !ptrV.Field(i).CanInterface() {
|
||||||
return nil, errors.Errorf("can't get interface of %v", ptrV.Field(i))
|
return nil, fmt.Errorf("can't get interface of %q", ptrV.Field(i))
|
||||||
}
|
}
|
||||||
|
|
||||||
rpcReq, ok := ptrV.Field(i).Interface().(*requests.RpcRequest)
|
rpcReq, ok := ptrV.Field(i).Interface().(*requests.RpcRequest)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.Errorf("can't convert interface of %v to '*requests.RpcRequest' type", ptrV.Field(i).Interface())
|
return nil, fmt.Errorf("can't convert interface of %q to '*requests.RpcRequest' type", ptrV.Field(i).Interface())
|
||||||
}
|
}
|
||||||
|
|
||||||
return rpcReq, nil
|
return rpcReq, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, errors.Errorf("didn't find *requests.RpcRequest embedded struct in %q", ptrV.Type())
|
return nil, fmt.Errorf("didn't find *requests.RpcRequest embedded struct in %q", ptrV.Type())
|
||||||
}
|
}
|
||||||
|
|
||||||
// newDiscoveryTool function returns discovery tool object.
|
// newDiscoveryTool function returns discovery tool object.
|
||||||
|
|
@ -101,7 +102,7 @@ func newDiscoveryTool(
|
||||||
responseRootKey string
|
responseRootKey string
|
||||||
responseObjectIDKey string
|
responseObjectIDKey string
|
||||||
err error
|
err error
|
||||||
noDiscoverySupportErr = errors.Errorf("no discovery support for project %q", project)
|
noDiscoverySupportErr = fmt.Errorf("no discovery support for project %q", project)
|
||||||
)
|
)
|
||||||
|
|
||||||
if len(regions) == 0 {
|
if len(regions) == 0 {
|
||||||
|
|
@ -232,7 +233,7 @@ func newDiscoveryTool(
|
||||||
case "acs_cds":
|
case "acs_cds":
|
||||||
return nil, noDiscoverySupportErr
|
return nil, noDiscoverySupportErr
|
||||||
default:
|
default:
|
||||||
return nil, errors.Errorf("project %q is not recognized by discovery", project)
|
return nil, fmt.Errorf("project %q is not recognized by discovery", project)
|
||||||
}
|
}
|
||||||
|
|
||||||
cli[region], err = sdk.NewClientWithOptions(region, sdk.NewConfig(), credential)
|
cli[region], err = sdk.NewClientWithOptions(region, sdk.NewConfig(), credential)
|
||||||
|
|
@ -242,7 +243,7 @@ func newDiscoveryTool(
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(dscReq) == 0 || len(cli) == 0 {
|
if len(dscReq) == 0 || len(cli) == 0 {
|
||||||
return nil, errors.Errorf("can't build discovery request for project: %q, regions: %v", project, regions)
|
return nil, fmt.Errorf("can't build discovery request for project: %q, regions: %v", project, regions)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &discoveryTool{
|
return &discoveryTool{
|
||||||
|
|
@ -273,7 +274,7 @@ func (dt *discoveryTool) parseDiscoveryResponse(resp *responses.CommonResponse)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := json.Unmarshal(data, &fullOutput); err != nil {
|
if err := json.Unmarshal(data, &fullOutput); err != nil {
|
||||||
return nil, errors.Errorf("can't parse JSON from discovery response: %v", err)
|
return nil, fmt.Errorf("can't parse JSON from discovery response: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for key, val := range fullOutput {
|
for key, val := range fullOutput {
|
||||||
|
|
@ -282,7 +283,7 @@ func (dt *discoveryTool) parseDiscoveryResponse(resp *responses.CommonResponse)
|
||||||
foundRootKey = true
|
foundRootKey = true
|
||||||
rootKeyVal, ok := val.(map[string]interface{})
|
rootKeyVal, ok := val.(map[string]interface{})
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.Errorf("content of root key %q, is not an object: %v", key, val)
|
return nil, fmt.Errorf("content of root key %q, is not an object: %q", key, val)
|
||||||
}
|
}
|
||||||
|
|
||||||
//It should contain the array with discovered data
|
//It should contain the array with discovered data
|
||||||
|
|
@ -292,7 +293,7 @@ func (dt *discoveryTool) parseDiscoveryResponse(resp *responses.CommonResponse)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !foundDataItem {
|
if !foundDataItem {
|
||||||
return nil, errors.Errorf("didn't find array item in root key %q", key)
|
return nil, fmt.Errorf("didn't find array item in root key %q", key)
|
||||||
}
|
}
|
||||||
case "TotalCount", "TotalRecordCount":
|
case "TotalCount", "TotalRecordCount":
|
||||||
pdResp.totalCount = int(val.(float64))
|
pdResp.totalCount = int(val.(float64))
|
||||||
|
|
@ -303,7 +304,7 @@ func (dt *discoveryTool) parseDiscoveryResponse(resp *responses.CommonResponse)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !foundRootKey {
|
if !foundRootKey {
|
||||||
return nil, errors.Errorf("didn't find root key %q in discovery response", dt.respRootKey)
|
return nil, fmt.Errorf("didn't find root key %q in discovery response", dt.respRootKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
return pdResp, nil
|
return pdResp, nil
|
||||||
|
|
@ -371,7 +372,7 @@ func (dt *discoveryTool) getDiscoveryDataAcrossRegions(lmtr chan bool) (map[stri
|
||||||
//which aliyun object type (project) is used
|
//which aliyun object type (project) is used
|
||||||
dscReq, ok := dt.req[region]
|
dscReq, ok := dt.req[region]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.Errorf("error building common discovery request: not valid region %q", region)
|
return nil, fmt.Errorf("error building common discovery request: not valid region %q", region)
|
||||||
}
|
}
|
||||||
|
|
||||||
rpcReq, err := getRPCReqFromDiscoveryRequest(dscReq)
|
rpcReq, err := getRPCReqFromDiscoveryRequest(dscReq)
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/vishvananda/netns"
|
"github.com/vishvananda/netns"
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
|
|
@ -115,8 +114,7 @@ func (e *Ethtool) gatherEthtoolStats(iface NamespacedInterface, acc telegraf.Acc
|
||||||
|
|
||||||
driverName, err := e.command.DriverName(iface)
|
driverName, err := e.command.DriverName(iface)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
driverErr := errors.Wrapf(err, "%s driver", iface.Name)
|
acc.AddError(fmt.Errorf("%q driver: %w", iface.Name, err))
|
||||||
acc.AddError(driverErr)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -125,8 +123,7 @@ func (e *Ethtool) gatherEthtoolStats(iface NamespacedInterface, acc telegraf.Acc
|
||||||
fields := make(map[string]interface{})
|
fields := make(map[string]interface{})
|
||||||
stats, err := e.command.Stats(iface)
|
stats, err := e.command.Stats(iface)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
statsErr := errors.Wrapf(err, "%s stats", iface.Name)
|
acc.AddError(fmt.Errorf("%q stats: %w", iface.Name, err))
|
||||||
acc.AddError(statsErr)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,10 @@
|
||||||
package ethtool
|
package ethtool
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"net"
|
"net"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/influxdata/telegraf/testutil"
|
"github.com/influxdata/telegraf/testutil"
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,13 @@ package filecount
|
||||||
|
|
||||||
import (
|
import (
|
||||||
_ "embed"
|
_ "embed"
|
||||||
|
"errors"
|
||||||
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/karrick/godirwalk"
|
"github.com/karrick/godirwalk"
|
||||||
"github.com/pkg/errors"
|
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
"github.com/influxdata/telegraf/config"
|
"github.com/influxdata/telegraf/config"
|
||||||
|
|
@ -177,7 +178,7 @@ func (fc *FileCount) count(acc telegraf.Accumulator, basedir string, glob globpa
|
||||||
Unsorted: true,
|
Unsorted: true,
|
||||||
FollowSymbolicLinks: fc.FollowSymlinks,
|
FollowSymbolicLinks: fc.FollowSymlinks,
|
||||||
ErrorCallback: func(osPathname string, err error) godirwalk.ErrorAction {
|
ErrorCallback: func(osPathname string, err error) godirwalk.ErrorAction {
|
||||||
if os.IsPermission(errors.Cause(err)) {
|
if errors.Is(err, fs.ErrPermission) {
|
||||||
fc.Log.Debug(err)
|
fc.Log.Debug(err)
|
||||||
return godirwalk.SkipNode
|
return godirwalk.SkipNode
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,11 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
_ "embed"
|
_ "embed"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
"github.com/influxdata/telegraf/config"
|
"github.com/influxdata/telegraf/config"
|
||||||
"github.com/influxdata/telegraf/internal"
|
"github.com/influxdata/telegraf/internal"
|
||||||
|
|
@ -88,7 +88,7 @@ func (s *SumoLogic) SetSerializer(serializer serializers.Serializer) {
|
||||||
s.headers[contentTypeHeader] = prometheusContentType
|
s.headers[contentTypeHeader] = prometheusContentType
|
||||||
|
|
||||||
default:
|
default:
|
||||||
s.err = errors.Errorf("unsupported serializer %T", serializer)
|
s.err = fmt.Errorf("unsupported serializer %T", serializer)
|
||||||
}
|
}
|
||||||
|
|
||||||
s.serializer = serializer
|
s.serializer = serializer
|
||||||
|
|
@ -105,7 +105,7 @@ func (s *SumoLogic) createClient() *http.Client {
|
||||||
|
|
||||||
func (s *SumoLogic) Connect() error {
|
func (s *SumoLogic) Connect() error {
|
||||||
if s.err != nil {
|
if s.err != nil {
|
||||||
return errors.Wrap(s.err, "sumologic: incorrect configuration")
|
return fmt.Errorf("sumologic: incorrect configuration: %w", s.err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.Timeout == 0 {
|
if s.Timeout == 0 {
|
||||||
|
|
@ -123,7 +123,7 @@ func (s *SumoLogic) Close() error {
|
||||||
|
|
||||||
func (s *SumoLogic) Write(metrics []telegraf.Metric) error {
|
func (s *SumoLogic) Write(metrics []telegraf.Metric) error {
|
||||||
if s.err != nil {
|
if s.err != nil {
|
||||||
return errors.Wrap(s.err, "sumologic: incorrect configuration")
|
return fmt.Errorf("sumologic: incorrect configuration: %w", s.err)
|
||||||
}
|
}
|
||||||
if s.serializer == nil {
|
if s.serializer == nil {
|
||||||
return errors.New("sumologic: serializer unset")
|
return errors.New("sumologic: serializer unset")
|
||||||
|
|
@ -193,15 +193,12 @@ func (s *SumoLogic) writeRequestChunk(reqBody []byte) error {
|
||||||
|
|
||||||
resp, err := s.client.Do(req)
|
resp, err := s.client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "sumologic: failed sending request to [%s]", s.URL)
|
return fmt.Errorf("sumologic: failed sending request to %q: %w", s.URL, err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
||||||
return errors.Errorf(
|
return fmt.Errorf("sumologic: when writing to %q received status code: %d", s.URL, resp.StatusCode)
|
||||||
"sumologic: when writing to [%s] received status code: %d",
|
|
||||||
s.URL, resp.StatusCode,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue