mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-15 16:30:55 +01:00
lib/promscrape/discovery/kubernetes: properly check for nil pointer inside interface
See https://mangatmodi.medium.com/go-check-nil-interface-the-right-way-d142776edef1 This fixes a panic when the ScrapeWork is filtered out in swcFunc. Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1108
This commit is contained in:
parent
ff5b8346d4
commit
25f453ce1a
@ -12,6 +12,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -380,7 +381,8 @@ func getScrapeWorkObjectsForLabels(swcFunc ScrapeWorkConstructorFunc, labelss []
|
|||||||
swos := make([]interface{}, 0, len(labelss))
|
swos := make([]interface{}, 0, len(labelss))
|
||||||
for _, labels := range labelss {
|
for _, labels := range labelss {
|
||||||
swo := swcFunc(labels)
|
swo := swcFunc(labels)
|
||||||
if swo != nil {
|
// The reflect check is needed because of https://mangatmodi.medium.com/go-check-nil-interface-the-right-way-d142776edef1
|
||||||
|
if swo != nil && !reflect.ValueOf(swo).IsNil() {
|
||||||
swos = append(swos, swo)
|
swos = append(swos, swo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user