-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[ws-manager-mk2] Refactor metrics with EverReady condition #17114
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
Merged
Merged
Changes from all commits
Commits
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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -20,16 +20,30 @@ import ( | |
const ( | ||
workspaceStartupSeconds string = "workspace_startup_seconds" | ||
workspaceStartFailuresTotal string = "workspace_starts_failure_total" | ||
workspaceFailuresTotal string = "workspace_failure_total" | ||
workspaceStopsTotal string = "workspace_stops_total" | ||
workspaceBackupsTotal string = "workspace_backups_total" | ||
workspaceBackupFailuresTotal string = "workspace_backups_failure_total" | ||
workspaceRestoresTotal string = "workspace_restores_total" | ||
workspaceRestoresFailureTotal string = "workspace_restores_failure_total" | ||
) | ||
|
||
type StopReason string | ||
|
||
const ( | ||
StopReasonFailed = "failed" | ||
StopReasonStartFailure = "start-failure" | ||
StopReasonAborted = "aborted" | ||
StopReasonOutOfSpace = "out-of-space" | ||
StopReasonTimeout = "timeout" | ||
StopReasonTabClosed = "tab-closed" | ||
StopReasonRegular = "regular-stop" | ||
) | ||
|
||
type controllerMetrics struct { | ||
startupTimeHistVec *prometheus.HistogramVec | ||
totalStartsFailureCounterVec *prometheus.CounterVec | ||
totalFailuresCounterVec *prometheus.CounterVec | ||
totalStopsCounterVec *prometheus.CounterVec | ||
|
||
totalBackupCounterVec *prometheus.CounterVec | ||
|
@@ -64,6 +78,12 @@ func newControllerMetrics(r *WorkspaceReconciler) (*controllerMetrics, error) { | |
Name: workspaceStartFailuresTotal, | ||
Help: "total number of workspaces that failed to start", | ||
}, []string{"type", "class"}), | ||
totalFailuresCounterVec: prometheus.NewCounterVec(prometheus.CounterOpts{ | ||
Namespace: metricsNamespace, | ||
Subsystem: metricsWorkspaceSubsystem, | ||
Name: workspaceFailuresTotal, | ||
Help: "total number of workspaces that had a failed condition", | ||
}, []string{"type", "class"}), | ||
totalStopsCounterVec: prometheus.NewCounterVec(prometheus.CounterOpts{ | ||
Namespace: metricsNamespace, | ||
Subsystem: metricsWorkspaceSubsystem, | ||
|
@@ -126,11 +146,42 @@ func (m *controllerMetrics) countWorkspaceStartFailures(log *logr.Logger, ws *wo | |
counter.Inc() | ||
} | ||
|
||
func (m *controllerMetrics) countWorkspaceFailure(log *logr.Logger, ws *workspacev1.Workspace) { | ||
class := ws.Spec.Class | ||
tpe := string(ws.Spec.Type) | ||
|
||
counter, err := m.totalFailuresCounterVec.GetMetricWithLabelValues(tpe, class) | ||
if err != nil { | ||
log.Error(err, "could not count workspace failure", "type", tpe, "class", class) | ||
} | ||
|
||
counter.Inc() | ||
} | ||
|
||
func (m *controllerMetrics) countWorkspaceStop(log *logr.Logger, ws *workspacev1.Workspace) { | ||
var reason string | ||
if c := wsk8s.GetCondition(ws.Status.Conditions, string(workspacev1.WorkspaceConditionFailed)); c != nil { | ||
reason = StopReasonFailed | ||
if !wsk8s.ConditionPresentAndTrue(ws.Status.Conditions, string(workspacev1.WorkspaceConditionEverReady)) { | ||
// Don't record 'failed' if there was a start failure. | ||
reason = StopReasonStartFailure | ||
} else if strings.Contains(c.Message, "Pod ephemeral local storage usage exceeds the total limit of containers") { | ||
reason = StopReasonOutOfSpace | ||
} | ||
} else if wsk8s.ConditionPresentAndTrue(ws.Status.Conditions, string(workspacev1.WorkspaceConditionAborted)) { | ||
reason = StopReasonAborted | ||
} else if wsk8s.ConditionPresentAndTrue(ws.Status.Conditions, string(workspacev1.WorkspaceConditionTimeout)) { | ||
reason = StopReasonTimeout | ||
} else if wsk8s.ConditionPresentAndTrue(ws.Status.Conditions, string(workspacev1.WorkspaceConditionClosed)) { | ||
reason = StopReasonTabClosed | ||
} else { | ||
reason = StopReasonRegular | ||
} | ||
Comment on lines
+163
to
+179
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. re-ordered these checks compared to mk1, to e.g. check for |
||
|
||
class := ws.Spec.Class | ||
tpe := string(ws.Spec.Type) | ||
|
||
counter, err := m.totalStopsCounterVec.GetMetricWithLabelValues("unknown", tpe, class) | ||
counter, err := m.totalStopsCounterVec.GetMetricWithLabelValues(reason, tpe, class) | ||
if err != nil { | ||
log.Error(err, "could not count workspace stop", "reason", "unknown", "type", tpe, "class", class) | ||
} | ||
|
@@ -210,6 +261,7 @@ type metricState struct { | |
recordedStartTime bool | ||
recordedInitFailure bool | ||
recordedStartFailure bool | ||
recordedFailure bool | ||
recordedContentReady bool | ||
recordedBackupFailed bool | ||
recordedBackupCompleted bool | ||
|
@@ -223,7 +275,8 @@ func newMetricState(ws *workspacev1.Workspace) metricState { | |
// each workspace. | ||
recordedStartTime: ws.Status.Phase == workspacev1.WorkspacePhaseRunning, | ||
recordedInitFailure: wsk8s.ConditionWithStatusAndReason(ws.Status.Conditions, string(workspacev1.WorkspaceConditionContentReady), false, workspacev1.ReasonInitializationFailure), | ||
recordedStartFailure: wsk8s.ConditionPresentAndTrue(ws.Status.Conditions, string(workspacev1.WorkspaceConditionFailed)), | ||
recordedStartFailure: ws.Status.Phase == workspacev1.WorkspacePhaseStopped && !wsk8s.ConditionPresentAndTrue(ws.Status.Conditions, string(workspacev1.WorkspaceConditionEverReady)), | ||
recordedFailure: wsk8s.ConditionPresentAndTrue(ws.Status.Conditions, string(workspacev1.WorkspaceConditionFailed)), | ||
recordedContentReady: wsk8s.ConditionPresentAndTrue(ws.Status.Conditions, string(workspacev1.WorkspaceConditionContentReady)), | ||
recordedBackupFailed: wsk8s.ConditionPresentAndTrue(ws.Status.Conditions, string(workspacev1.WorkspaceConditionBackupFailure)), | ||
recordedBackupCompleted: wsk8s.ConditionPresentAndTrue(ws.Status.Conditions, string(workspacev1.WorkspaceConditionBackupComplete)), | ||
|
@@ -245,6 +298,7 @@ func (m *controllerMetrics) Describe(ch chan<- *prometheus.Desc) { | |
m.startupTimeHistVec.Describe(ch) | ||
m.totalStopsCounterVec.Describe(ch) | ||
m.totalStartsFailureCounterVec.Describe(ch) | ||
m.totalFailuresCounterVec.Describe(ch) | ||
|
||
m.totalBackupCounterVec.Describe(ch) | ||
m.totalBackupFailureCounterVec.Describe(ch) | ||
|
@@ -260,6 +314,7 @@ func (m *controllerMetrics) Collect(ch chan<- prometheus.Metric) { | |
m.startupTimeHistVec.Collect(ch) | ||
m.totalStopsCounterVec.Collect(ch) | ||
m.totalStartsFailureCounterVec.Collect(ch) | ||
m.totalFailuresCounterVec.Collect(ch) | ||
|
||
m.totalBackupCounterVec.Collect(ch) | ||
m.totalBackupFailureCounterVec.Collect(ch) | ||
|
This file contains hidden or 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 hidden or 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
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.
different from MK1: instead of not incrementing the stop metric when there was a start failure, we increment it now but with its own unique reason.