Skip to content

Commit

Permalink
Merge pull request #1925 from bskiba/unsupported-05
Browse files Browse the repository at this point in the history
[cherry-pick] VPA - addmonitoring of VPA object with unsupported config condition.
  • Loading branch information
k8s-ci-robot authored Apr 19, 2019
2 parents ccb7d53 + a01dad8 commit 3757233
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 13 deletions.
5 changes: 5 additions & 0 deletions vertical-pod-autoscaler/pkg/recommender/model/vpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ func (conditionsMap *vpaConditionsMap) AsList() []vpa_types.VerticalPodAutoscale
return conditions
}

func (conditionsMap *vpaConditionsMap) ConditionActive(conditionType vpa_types.VerticalPodAutoscalerConditionType) bool {
condition, found := (*conditionsMap)[conditionType]
return found && condition.Status == apiv1.ConditionTrue
}

// Vpa (Vertical Pod Autoscaler) object is responsible for vertical scaling of
// Pods matching a given label selector.
type Vpa struct {
Expand Down
6 changes: 6 additions & 0 deletions vertical-pod-autoscaler/pkg/recommender/model/vpa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,15 @@ func TestUpdateConditions(t *testing.T) {
assert.Equal(t, condition.Status, actualCondition.Status, "Condition: %v", condition.Type)
assert.Equal(t, condition.Reason, actualCondition.Reason, "Condition: %v", condition.Type)
assert.Equal(t, condition.Message, actualCondition.Message, "Condition: %v", condition.Type)
if condition.Status == core.ConditionTrue {
assert.True(t, vpa.Conditions.ConditionActive(condition.Type))
} else {
assert.False(t, vpa.Conditions.ConditionActive(condition.Type))
}
}
for _, condition := range tc.expectedAbsent {
assert.NotContains(t, vpa.Conditions, condition)
assert.False(t, vpa.Conditions.ConditionActive(condition))
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var (
Namespace: metricsNamespace,
Name: "vpa_objects_count",
Help: "Number of VPA objects present in the cluster.",
}, []string{"update_mode", "has_recommendation", "api", "matches_pods"},
}, []string{"update_mode", "has_recommendation", "api", "matches_pods", "unsupported_config"},
)

recommendationLatency = prometheus.NewHistogram(
Expand All @@ -65,10 +65,11 @@ var (
)

type objectCounterKey struct {
mode string
has bool
matchesPods bool
apiVersion apiVersion
mode string
has bool
matchesPods bool
apiVersion apiVersion
unsupportedConfig bool
}

// ObjectCounter helps split all VPA objects into buckets
Expand Down Expand Up @@ -102,9 +103,17 @@ func NewObjectCounter() *ObjectCounter {
// initialize with empty data so we can clean stale gauge values in Observe
for _, m := range modes {
for _, h := range []bool{false, true} {
for _, mp := range []bool{false, true} {
for _, api := range []apiVersion{v1beta1, v1beta2} {
obj.cnt[objectCounterKey{mode: m, has: h, apiVersion: api, matchesPods: mp}] = 0
for _, api := range []apiVersion{v1beta1, v1beta2} {
for _, mp := range []bool{false, true} {
for _, uc := range []bool{false, true} {
obj.cnt[objectCounterKey{
mode: m,
has: h,
apiVersion: api,
matchesPods: mp,
unsupportedConfig: uc,
}] = 0
}
}
}
}
Expand All @@ -123,11 +132,13 @@ func (oc *ObjectCounter) Add(vpa *model.Vpa) {
if vpa.IsV1Beta1API {
api = v1beta1
}

key := objectCounterKey{
mode: mode,
has: vpa.HasRecommendation(),
apiVersion: api,
matchesPods: vpa.HasMatchedPods(),
mode: mode,
has: vpa.HasRecommendation(),
apiVersion: api,
matchesPods: vpa.HasMatchedPods(),
unsupportedConfig: vpa.Conditions.ConditionActive(vpa_types.ConfigUnsupported),
}
oc.cnt[key]++
}
Expand All @@ -139,6 +150,8 @@ func (oc *ObjectCounter) Observe() {
k.mode,
fmt.Sprintf("%v", k.has),
string(k.apiVersion),
fmt.Sprintf("%v", k.matchesPods)).Set(float64(v))
fmt.Sprintf("%v", k.matchesPods),
fmt.Sprintf("%v", k.unsupportedConfig),
).Set(float64(v))
}
}

0 comments on commit 3757233

Please sign in to comment.