-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Automatic switch to emergency mode when metrics unavailable #424
Open
randytqwjp
wants to merge
37
commits into
main
Choose a base branch
from
kubebuilder-inplace
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 29 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
438f653
upgrade kubebuilder to plugin/v4
randytqwjp df7b7b8
add test utils
randytqwjp 52780ef
fix controller test
randytqwjp 9c153b5
fix gha test
randytqwjp f4454f4
chmod tortoisectl test
randytqwjp bba0747
edit tortoisectl
randytqwjp a968c7a
fix lint
randytqwjp 691c4f4
fix lint
randytqwjp e28d881
add lint-fix to ci
randytqwjp 192fecf
go mod tidy
randytqwjp 4343ea9
add make dependencies
randytqwjp 93556df
remove lint-fix
randytqwjp 5cda06c
upgrade tools
randytqwjp 0fbfff5
lint-fix
randytqwjp ae2334a
add tool chain version
randytqwjp 28080e3
change toolchain to 1.22
randytqwjp ca36611
add timeout
randytqwjp 5677abc
remove lint-fix
randytqwjp a6b0318
edit licenses
randytqwjp e8454e9
remove chmod
randytqwjp 3725788
Merge branch 'main' of github.com:mercari/tortoise into kubebuilder-i…
randytqwjp ba4351e
automatic emergency mode trigger when kube metrics unavailable for hpa
randytqwjp 11d8cb8
add return statement
randytqwjp c056d82
clean up code
randytqwjp b47578c
clean up code
randytqwjp 7d07efd
add hpa test and try to fix controller test
randytqwjp 12c7b05
fix old controller tests
randytqwjp ed22342
add controller test and fix checkHPAStatus function
randytqwjp bddb139
clean up code
randytqwjp 0dc2749
remove autoemergency phase and use emergency instead
randytqwjp dd7c10a
fix lint
randytqwjp 2e261c4
refactor tortoisephase change into tortoise service and write unit tests
randytqwjp 7c0e997
fix lint
randytqwjp 5be0c1a
fix lint
randytqwjp d8ae58d
fix review comments
randytqwjp 46d71a9
fix nits
randytqwjp e41aab4
fix nits
randytqwjp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
30 changes: 30 additions & 0 deletions
30
...ontroller/testdata/reconcile-automatic-emergency-mode-hpa-condition/after/deployment.yaml
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,30 @@ | ||
metadata: | ||
name: mercari-app | ||
namespace: default | ||
spec: | ||
selector: | ||
matchLabels: | ||
app: mercari | ||
strategy: {} | ||
template: | ||
metadata: | ||
annotations: | ||
kubectl.kubernetes.io/restartedAt: "2023-01-01T00:00:00Z" | ||
creationTimestamp: null | ||
labels: | ||
app: mercari | ||
spec: | ||
containers: | ||
- image: awesome-mercari-app-image | ||
name: app | ||
resources: | ||
requests: | ||
cpu: "10" | ||
memory: 10Gi | ||
- image: awesome-istio-proxy-image | ||
name: istio-proxy | ||
resources: | ||
requests: | ||
cpu: "4" | ||
memory: 4Gi | ||
status: {} |
61 changes: 61 additions & 0 deletions
61
internal/controller/testdata/reconcile-automatic-emergency-mode-hpa-condition/after/hpa.yaml
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,61 @@ | ||
metadata: | ||
annotations: | ||
tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" | ||
name: tortoise-hpa-mercari | ||
namespace: default | ||
spec: | ||
behavior: | ||
scaleDown: | ||
policies: | ||
- periodSeconds: 90 | ||
type: Percent | ||
value: 2 | ||
selectPolicy: Max | ||
scaleUp: | ||
policies: | ||
- periodSeconds: 60 | ||
type: Percent | ||
value: 100 | ||
selectPolicy: Max | ||
stabilizationWindowSeconds: 0 | ||
maxReplicas: 20 | ||
metrics: | ||
- containerResource: | ||
container: app | ||
name: cpu | ||
target: | ||
averageUtilization: 55 | ||
type: Utilization | ||
type: ContainerResource | ||
- containerResource: | ||
container: istio-proxy | ||
name: cpu | ||
target: | ||
averageUtilization: 55 | ||
type: Utilization | ||
type: ContainerResource | ||
minReplicas: 20 | ||
scaleTargetRef: | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
name: mercari-app | ||
status: | ||
conditions: | ||
- status: "True" | ||
type: AbleToScale | ||
message: "recommended size matches current size" | ||
- status: "False" | ||
type: ScalingActive | ||
message: "the HPA was unable to compute the replica count: failed to get cpu utilization" | ||
currentMetrics: | ||
- containerResource: | ||
container: app | ||
name: cpu | ||
current: | ||
value: 0 | ||
- containerResource: | ||
container: istio-proxy | ||
name: cpu | ||
current: | ||
value: 0 | ||
desiredReplicas: 0 |
143 changes: 143 additions & 0 deletions
143
.../controller/testdata/reconcile-automatic-emergency-mode-hpa-condition/after/tortoise.yaml
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,143 @@ | ||
metadata: | ||
finalizers: | ||
- tortoise.autoscaling.mercari.com/finalizer | ||
name: mercari | ||
namespace: default | ||
spec: | ||
targetRefs: | ||
scaleTargetRef: | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
name: mercari-app | ||
updateMode: Auto | ||
status: | ||
autoscalingPolicy: | ||
- containerName: app | ||
policy: | ||
cpu: Horizontal | ||
memory: Vertical | ||
- containerName: istio-proxy | ||
policy: | ||
cpu: Horizontal | ||
memory: Vertical | ||
conditions: | ||
containerRecommendationFromVPA: | ||
- containerName: app | ||
maxRecommendation: | ||
cpu: | ||
quantity: "3" | ||
updatedAt: "2023-01-01T00:00:00Z" | ||
memory: | ||
quantity: 3Gi | ||
updatedAt: "2023-01-01T00:00:00Z" | ||
recommendation: | ||
cpu: | ||
quantity: "3" | ||
updatedAt: "2023-01-01T00:00:00Z" | ||
memory: | ||
quantity: 3Gi | ||
updatedAt: "2023-01-01T00:00:00Z" | ||
- containerName: istio-proxy | ||
maxRecommendation: | ||
cpu: | ||
quantity: "3" | ||
updatedAt: "2023-01-01T00:00:00Z" | ||
memory: | ||
quantity: 3Gi | ||
updatedAt: "2023-01-01T00:00:00Z" | ||
recommendation: | ||
cpu: | ||
quantity: "3" | ||
updatedAt: "2023-01-01T00:00:00Z" | ||
memory: | ||
quantity: 3Gi | ||
updatedAt: "2023-01-01T00:00:00Z" | ||
containerResourceRequests: | ||
- containerName: app | ||
resource: | ||
cpu: "10" | ||
memory: 3Gi | ||
- containerName: istio-proxy | ||
resource: | ||
cpu: "4" | ||
memory: 3Gi | ||
tortoiseConditions: | ||
- lastTransitionTime: "2023-01-01T00:00:00Z" | ||
lastUpdateTime: "2023-01-01T00:00:00Z" | ||
message: the current number of replicas is not bigger than the preferred max | ||
replica number | ||
reason: ScaledUpBasedOnPreferredMaxReplicas | ||
status: "False" | ||
type: ScaledUpBasedOnPreferredMaxReplicas | ||
- lastTransitionTime: "2023-01-01T00:00:00Z" | ||
lastUpdateTime: "2023-01-01T00:00:00Z" | ||
message: HPA target utilization is updated | ||
reason: HPATargetUtilizationUpdated | ||
status: "True" | ||
type: HPATargetUtilizationUpdated | ||
- lastTransitionTime: "2023-01-01T00:00:00Z" | ||
lastUpdateTime: "2023-01-01T00:00:00Z" | ||
message: The recommendation is provided | ||
status: "True" | ||
type: VerticalRecommendationUpdated | ||
- lastTransitionTime: "2023-01-01T00:00:00Z" | ||
lastUpdateTime: "2023-01-01T00:00:00Z" | ||
status: "False" | ||
type: FailedToReconcile | ||
containerResourcePhases: | ||
- containerName: app | ||
resourcePhases: | ||
cpu: | ||
lastTransitionTime: null | ||
phase: Working | ||
memory: | ||
lastTransitionTime: "2023-01-01T00:00:00Z" | ||
phase: Working | ||
- containerName: istio-proxy | ||
resourcePhases: | ||
cpu: | ||
lastTransitionTime: null | ||
phase: Working | ||
memory: | ||
lastTransitionTime: "2023-01-01T00:00:00Z" | ||
phase: Working | ||
recommendations: | ||
horizontal: | ||
maxReplicas: | ||
- from: 0 | ||
timezone: Local | ||
to: 24 | ||
updatedAt: "2023-01-01T00:00:00Z" | ||
value: 20 | ||
minReplicas: | ||
- from: 0 | ||
timezone: Local | ||
to: 24 | ||
updatedAt: "2023-01-01T00:00:00Z" | ||
value: 5 | ||
targetUtilizations: | ||
- containerName: app | ||
targetUtilization: | ||
cpu: 90 | ||
- containerName: istio-proxy | ||
targetUtilization: | ||
cpu: 55 | ||
vertical: | ||
containerResourceRecommendation: | ||
- RecommendedResource: | ||
cpu: "10" | ||
memory: 3Gi | ||
containerName: app | ||
- RecommendedResource: | ||
cpu: "4" | ||
memory: 3Gi | ||
containerName: istio-proxy | ||
targets: | ||
horizontalPodAutoscaler: tortoise-hpa-mercari | ||
scaleTargetRef: | ||
kind: "" | ||
name: "" | ||
verticalPodAutoscalers: | ||
- name: tortoise-monitor-mercari | ||
role: Monitor | ||
tortoisePhase: AutoEmergency |
39 changes: 39 additions & 0 deletions
39
...ntroller/testdata/reconcile-automatic-emergency-mode-hpa-condition/after/vpa-Monitor.yaml
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,39 @@ | ||
metadata: | ||
annotations: | ||
tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" | ||
name: tortoise-monitor-mercari | ||
namespace: default | ||
spec: | ||
targetRef: | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
name: mercari-app | ||
updatePolicy: | ||
updateMode: "Off" | ||
status: | ||
conditions: | ||
- lastTransitionTime: null | ||
status: "True" | ||
type: RecommendationProvided | ||
recommendation: | ||
containerRecommendations: | ||
- containerName: app | ||
lowerBound: | ||
cpu: "3" | ||
memory: 3Gi | ||
target: | ||
cpu: "3" | ||
memory: 3Gi | ||
upperBound: | ||
cpu: "5" | ||
memory: 5Gi | ||
- containerName: istio-proxy | ||
lowerBound: | ||
cpu: "3" | ||
memory: 3Gi | ||
target: | ||
cpu: "3" | ||
memory: 3Gi | ||
upperBound: | ||
cpu: "5" | ||
memory: 5Gi |
27 changes: 27 additions & 0 deletions
27
...ntroller/testdata/reconcile-automatic-emergency-mode-hpa-condition/before/deployment.yaml
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,27 @@ | ||
metadata: | ||
name: mercari-app | ||
namespace: default | ||
spec: | ||
selector: | ||
matchLabels: | ||
app: mercari | ||
strategy: {} | ||
template: | ||
metadata: | ||
annotations: | ||
sidecar.istio.io/inject: "true" | ||
sidecar.istio.io/proxyCPU: "4" | ||
sidecar.istio.io/proxyMemory: "4Gi" | ||
labels: | ||
app: mercari | ||
spec: | ||
containers: | ||
- name: istio-proxy # will be ignored. | ||
image: auto | ||
- image: awesome-mercari-app-image | ||
name: app | ||
resources: | ||
requests: | ||
cpu: "10" | ||
memory: 10Gi | ||
replicas: 10 |
61 changes: 61 additions & 0 deletions
61
...rnal/controller/testdata/reconcile-automatic-emergency-mode-hpa-condition/before/hpa.yaml
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,61 @@ | ||
metadata: | ||
annotations: | ||
tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" | ||
name: tortoise-hpa-mercari | ||
namespace: default | ||
status: | ||
conditions: | ||
- status: "True" | ||
type: AbleToScale | ||
message: "recommended size matches current size" | ||
- status: "False" | ||
type: ScalingActive | ||
message: "the HPA was unable to compute the replica count: failed to get cpu utilization" | ||
currentMetrics: | ||
- containerResource: | ||
container: app | ||
name: cpu | ||
current: | ||
value: 0 | ||
- containerResource: | ||
container: istio-proxy | ||
name: cpu | ||
current: | ||
value: 0 | ||
spec: | ||
behavior: | ||
scaleDown: | ||
policies: | ||
- periodSeconds: 90 | ||
type: Percent | ||
value: 2 | ||
selectPolicy: Max | ||
scaleUp: | ||
policies: | ||
- periodSeconds: 60 | ||
type: Percent | ||
value: 100 | ||
selectPolicy: Max | ||
stabilizationWindowSeconds: 0 | ||
maxReplicas: 15 | ||
metrics: | ||
- containerResource: | ||
container: app | ||
name: cpu | ||
target: | ||
averageUtilization: 30 | ||
type: Utilization | ||
type: ContainerResource | ||
- containerResource: | ||
container: istio-proxy | ||
name: cpu | ||
target: | ||
averageUtilization: 30 | ||
type: Utilization | ||
type: ContainerResource | ||
minReplicas: 3 | ||
scaleTargetRef: | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
name: mercari-app | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, I do not agree adding a new phase. It'll increase our maintenance effort.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will look at it again later i didnt see your comment earlier
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sanposhiho Changed to use only emergency mode. Could you review the new test cases as well? I am also using
currentMetric.ContainerResource.Current.Value.IsZero()
which is the default value for int32 though I am not sure what is supposed to be returned when metrics are down. I assume its the default value for the type but I'm not too familiar with golangThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it's correct to assume HPA to return zero when something goes wrong happens with the metric. Or maybe they just keep the previous values (= they don't clean up the list with zero values when the HPA reconciliation fails).
You have to check HPA controller implementation to make 100% sure.