Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Worker busy and active pod metrics (#4823)
Signed-off-by: Simon Behar <simbeh7@gmail.com>
- Loading branch information
Showing
13 changed files
with
224 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package indexes | ||
|
||
import ( | ||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
func PodPhaseIndexFunc(obj interface{}) ([]string, error) { | ||
pod, ok := obj.(*corev1.Pod) | ||
|
||
if !ok { | ||
return nil, nil | ||
} | ||
return []string{string(pod.Status.Phase)}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package indexes | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
func TestMetaPodPhaseIndexFunc(t *testing.T) { | ||
t.Run("NoPhase", func(t *testing.T) { | ||
values, err := PodPhaseIndexFunc(&corev1.Pod{}) | ||
assert.NoError(t, err) | ||
assert.Equal(t, []string{""}, values) | ||
}) | ||
t.Run("Phase", func(t *testing.T) { | ||
values, err := PodPhaseIndexFunc(&corev1.Pod{ | ||
Status: corev1.PodStatus{Phase: corev1.PodRunning}, | ||
}) | ||
assert.NoError(t, err) | ||
assert.ElementsMatch(t, values, []string{string(corev1.PodRunning)}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package metrics | ||
|
||
import "k8s.io/client-go/util/workqueue" | ||
|
||
type workersBusyRateLimiterWorkQueue struct { | ||
workqueue.RateLimitingInterface | ||
workerType string | ||
metrics *Metrics | ||
} | ||
|
||
func (m *Metrics) RateLimiterWithBusyWorkers(workQueue workqueue.RateLimiter, queueName string) workqueue.RateLimitingInterface { | ||
m.newWorker(queueName) | ||
return workersBusyRateLimiterWorkQueue{ | ||
RateLimitingInterface: workqueue.NewNamedRateLimitingQueue(workQueue, queueName), | ||
workerType: queueName, | ||
metrics: m, | ||
} | ||
} | ||
|
||
func (m *Metrics) newWorker(workerType string) { | ||
m.mutex.Lock() | ||
defer m.mutex.Unlock() | ||
|
||
m.workersBusy[workerType] = getWorkersBusy(workerType) | ||
} | ||
|
||
func (m *Metrics) workerBusy(workerType string) { | ||
m.mutex.Lock() | ||
defer m.mutex.Unlock() | ||
|
||
m.workersBusy[workerType].Inc() | ||
} | ||
|
||
func (m *Metrics) workerFree(workerType string) { | ||
m.mutex.Lock() | ||
defer m.mutex.Unlock() | ||
|
||
m.workersBusy[workerType].Dec() | ||
} | ||
|
||
func (w workersBusyRateLimiterWorkQueue) Get() (interface{}, bool) { | ||
item, shutdown := w.RateLimitingInterface.Get() | ||
w.metrics.workerBusy(w.workerType) | ||
return item, shutdown | ||
|
||
} | ||
|
||
func (w workersBusyRateLimiterWorkQueue) Done(item interface{}) { | ||
w.RateLimitingInterface.Done(item) | ||
w.metrics.workerFree(w.workerType) | ||
} |
Oops, something went wrong.