mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
Merge pull request #22164 from gmarek/metrics
Workaround proxy deadlock in metrics gatherer.
This commit is contained in:
commit
868a883389
@ -18,6 +18,7 @@ package metrics
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"k8s.io/kubernetes/pkg/util/sets"
|
"k8s.io/kubernetes/pkg/util/sets"
|
||||||
|
|
||||||
@ -133,14 +134,27 @@ func parseKubeletMetrics(data string) (KubeletMetrics, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *MetricsGrabber) getMetricsFromNode(nodeName string, kubeletPort int) (string, error) {
|
func (g *MetricsGrabber) getMetricsFromNode(nodeName string, kubeletPort int) (string, error) {
|
||||||
rawOutput, err := g.client.Get().
|
// There's a problem with timing out during proxy. Wrapping this in a goroutine to prevent deadlock.
|
||||||
Prefix("proxy").
|
// Hanging goroutine will be leaked.
|
||||||
Resource("nodes").
|
finished := make(chan struct{})
|
||||||
Name(fmt.Sprintf("%v:%v", nodeName, kubeletPort)).
|
var err error
|
||||||
Suffix("metrics").
|
var rawOutput []byte
|
||||||
Do().Raw()
|
go func() {
|
||||||
if err != nil {
|
rawOutput, err = g.client.Get().
|
||||||
return "", err
|
Prefix("proxy").
|
||||||
|
Resource("nodes").
|
||||||
|
Name(fmt.Sprintf("%v:%v", nodeName, kubeletPort)).
|
||||||
|
Suffix("metrics").
|
||||||
|
Do().Raw()
|
||||||
|
finished <- struct{}{}
|
||||||
|
}()
|
||||||
|
select {
|
||||||
|
case <-time.After(ProxyTimeout):
|
||||||
|
return "", fmt.Errorf("Timed out when waiting for proxy to gather metrics from %v", nodeName)
|
||||||
|
case <-finished:
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return string(rawOutput), nil
|
||||||
}
|
}
|
||||||
return string(rawOutput), nil
|
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ package metrics
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
client "k8s.io/kubernetes/pkg/client/unversioned"
|
client "k8s.io/kubernetes/pkg/client/unversioned"
|
||||||
@ -29,6 +30,10 @@ import (
|
|||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
ProxyTimeout = 2 * time.Minute
|
||||||
|
)
|
||||||
|
|
||||||
type MetricsCollection struct {
|
type MetricsCollection struct {
|
||||||
ApiServerMetrics ApiServerMetrics
|
ApiServerMetrics ApiServerMetrics
|
||||||
ControllerManagerMetrics ControllerManagerMetrics
|
ControllerManagerMetrics ControllerManagerMetrics
|
||||||
|
Loading…
Reference in New Issue
Block a user