Skip to content

Commit

Permalink
koordlet: fix GetAllPods error and wrong tsdb prometheus registry (ko…
Browse files Browse the repository at this point in the history
…ordinator-sh#1944)

Signed-off-by: saintube <saintube@foxmail.com>
  • Loading branch information
saintube authored and ls-2018 committed Mar 25, 2024
1 parent ac55145 commit eb080d9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
4 changes: 3 additions & 1 deletion pkg/koordlet/metriccache/tsdb_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
promstorage "github.com/prometheus/prometheus/storage"
"github.com/prometheus/prometheus/tsdb"
"k8s.io/klog/v2"

"github.com/koordinator-sh/koordinator/pkg/koordlet/metrics"
)

// TSDBStorage defines time-series type DB, providing insert and query interface
Expand Down Expand Up @@ -122,7 +124,7 @@ func NewTSDBStorage(conf *Config) (TSDBStorage, error) {

var promReg prometheus.Registerer
if conf.TSDBEnablePromMetrics {
promReg = prometheus.DefaultRegisterer
promReg = metrics.ExternalRegistry
}
db, err := tsdb.Open(conf.TSDBPath, nil, promReg, tsdbOpt, nil)
if err != nil {
Expand Down
17 changes: 10 additions & 7 deletions pkg/koordlet/statesinformer/impl/kubelet_stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,24 @@ func NewKubeletStub(addr string, port int, scheme string, timeout time.Duration,

func (k *kubeletStub) GetAllPods() (corev1.PodList, error) {
path := "/pods/"
url := url.URL{
podsURL := url.URL{
Scheme: k.scheme,
Host: net.JoinHostPort(k.addr, strconv.Itoa(k.port)),
Path: path,
}
podList := corev1.PodList{}
start := time.Now()
rsp, err := k.httpClient.Get(url.String())
metrics.RecordKubeletRequestDuration(metrics.HTTPVerbGet, path, strconv.Itoa(rsp.StatusCode), metrics.SinceInSeconds(start))

rsp, err := k.httpClient.Get(podsURL.String())
if rsp != nil {
metrics.RecordKubeletRequestDuration(metrics.HTTPVerbGet, path, strconv.Itoa(rsp.StatusCode), metrics.SinceInSeconds(start))
}
if err != nil {
return podList, err
}
defer rsp.Body.Close()

if rsp.StatusCode != http.StatusOK {
return podList, fmt.Errorf("request %s failed, code %d", url.String(), rsp.StatusCode)
return podList, fmt.Errorf("request %s failed, code %d", podsURL.String(), rsp.StatusCode)
}

body, err := io.ReadAll(rsp.Body)
Expand Down Expand Up @@ -116,8 +118,9 @@ func (k *kubeletStub) GetKubeletConfiguration() (*kubeletconfiginternal.KubeletC
}
start := time.Now()
rsp, err := k.httpClient.Get(configzURL.String())
metrics.RecordKubeletRequestDuration(metrics.HTTPVerbGet, path, strconv.Itoa(rsp.StatusCode), metrics.SinceInSeconds(start))

if rsp != nil {
metrics.RecordKubeletRequestDuration(metrics.HTTPVerbGet, path, strconv.Itoa(rsp.StatusCode), metrics.SinceInSeconds(start))
}
if err != nil {
return nil, err
}
Expand Down

0 comments on commit eb080d9

Please sign in to comment.