Skip to content

Commit

Permalink
Correct timeout check
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Falck committed Jan 15, 2021
1 parent 48a56f5 commit 2935762
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
17 changes: 17 additions & 0 deletions errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package main

import (
"errors"
)

type timeout interface {
Timeout() bool
}

func IsTimeout(err error) bool {
var t timeout
if errors.As(err, &t) && t.Timeout() {
return true
}
return false
}
10 changes: 7 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func discoverNetwork(network string, queue chan func(context.Context), exporter
if port == ExporterExporterPort {
exporters, err = checkExporterExporter(ctx, ip, port)
if err != nil {
if !errors.Is(err, context.DeadlineExceeded) && !os.IsTimeout(err) {
if !errors.Is(err, context.DeadlineExceeded) && !IsTimeout(err) {
logrus.Errorf("error fetching from exporter_exporter: %s", err)
}
logrus.Debugf("%s:%s was not open", ip, port)
Expand Down Expand Up @@ -328,8 +328,8 @@ func getOldGroups(path string) ([]Group, error) {
return oldGroups, err
}

func writeFileSDConfig(config *Config, path string, addresses []Address) error {
path = filepath.Join(config.FileSdPath, path+".json")
func writeFileSDConfig(config *Config, exporterName string, addresses []Address) error {
path := filepath.Join(config.FileSdPath, exporterName+".json")

previous, err := getOldGroups(path)
if err != nil {
Expand All @@ -346,6 +346,10 @@ func writeFileSDConfig(config *Config, path string, addresses []Address) error {
"host": v.Hostname,
},
}
if v.Port == ExporterExporterPort {
group.Labels["__metrics_path__"] = "/proxy"
group.Labels["__param_module"] = exporterName
}
groups = append(groups, group)
}

Expand Down

0 comments on commit 2935762

Please sign in to comment.