-
Notifications
You must be signed in to change notification settings - Fork 30
feat(worker-visibility): extend worker table with 5 fields #772
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
Changes from 8 commits
bd25ad9
a38c69f
723e453
5483e0f
fdb8cb8
822800a
98691a5
540d7d0
55dba0a
11f5a1e
e1f128c
56f3e25
b9ae9af
49ca50d
e5e7c08
e8eda6a
4d79db4
6073481
b4f39c4
3f60d07
2e22e2f
1d36eb7
99541ac
b2707d9
d3dd14f
a79873a
8640cd0
c648ab8
999a1db
56aea85
60996b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ import ( | |
| "github.com/gin-gonic/gin" | ||
| "github.com/go-vela/server/database" | ||
| "github.com/go-vela/server/queue" | ||
| "github.com/go-vela/types/constants" | ||
| "github.com/prometheus/client_golang/prometheus" | ||
| "github.com/prometheus/client_golang/prometheus/promauto" | ||
| "github.com/prometheus/client_golang/prometheus/promhttp" | ||
|
|
@@ -56,6 +57,19 @@ type MetricsQueryParameters struct { | |
| ActiveWorkerCount bool `form:"active_worker_count"` | ||
| // InactiveWorkerCount represents total number of inactive workers | ||
| InactiveWorkerCount bool `form:"inactive_worker_count"` | ||
|
|
||
| // UnregisteredWorkerCount represents total number of workers with a status of unregistered | ||
| UnregisteredWorkerCount bool `form:"unregistered_worker_count"` | ||
| // AvailableWorkerCount represents total number of workers with a status of available, | ||
| // where worker RunningBuildIDs.length < worker BuildLimit | ||
| AvailableWorkerCount bool `form:"available_worker_count"` | ||
| // BusyWorkerCount represents total number of workers with a status of busy, | ||
| // where worker BuildLimit == worker RunningBuildIDs.length | ||
| BusyWorkerCount bool `form:"busy_worker_count"` | ||
| // BusyWorkerCount represents total number of workers with a status of maintenance | ||
| MaintenanceWorkerCount bool `form:"maintenance_worker_count"` | ||
| // ErrorWorkerCount represents total number of workers with a status of error | ||
| ErrorWorkerCount bool `form:"error_worker_count"` | ||
| } | ||
|
|
||
| // predefine Prometheus metrics else they will be regenerated | ||
|
|
@@ -175,6 +189,31 @@ var ( | |
| // description: Indicates a request for inactive worker count | ||
| // type: boolean | ||
| // default: false | ||
| // - in: query | ||
| // name: unregistered_worker_count | ||
| // description: Indicates a request for unregistered worker count | ||
| // type: boolean | ||
| // default: false | ||
| // - in: query | ||
| // name: available_worker_count | ||
| // description: Indicates a request for available worker count | ||
| // type: boolean | ||
| // default: false | ||
| // - in: query | ||
| // name: busy_worker_count | ||
| // description: Indicates a request for busy worker count | ||
| // type: boolean | ||
| // default: false | ||
| // - in: query | ||
| // name: maintenance_worker_count | ||
| // description: Indicates a request for maintenance worker count | ||
| // type: boolean | ||
| // default: false | ||
| // - in: query | ||
| // name: error_worker_count | ||
| // description: Indicates a request for error worker count | ||
| // type: boolean | ||
| // default: false | ||
| // responses: | ||
| // '200': | ||
| // description: Successfully retrieved the Vela metrics | ||
|
|
@@ -370,14 +409,19 @@ func recordGauges(c *gin.Context) { | |
|
|
||
| // add worker metrics | ||
| var ( | ||
| buildLimit int64 | ||
| activeWorkers int64 | ||
| inactiveWorkers int64 | ||
| buildLimit int64 | ||
| activeWorkers int64 | ||
| inactiveWorkers int64 | ||
| unregisteredWorkers int64 | ||
| availableWorkers int64 | ||
| busyWorkers int64 | ||
| maintenanceWorkers int64 | ||
| errorWorkers int64 | ||
| ) | ||
|
|
||
| // get worker metrics based on request query parameters | ||
| // worker_build_limit, active_worker_count, inactive_worker_count | ||
| if q.WorkerBuildLimit || q.ActiveWorkerCount || q.InactiveWorkerCount { | ||
| // worker_build_limit, active_worker_count, inactive_worker_count, unregistered_worker_count, available_worker_count, busy_worker_count, maintenance_worker_count, error_worker_count | ||
| if q.WorkerBuildLimit || q.ActiveWorkerCount || q.InactiveWorkerCount || q.UnregisteredWorkerCount || q.AvailableWorkerCount || q.BusyWorkerCount || q.MaintenanceWorkerCount || q.ErrorWorkerCount { | ||
| // send API call to capture the workers | ||
| workers, err := database.FromContext(c).ListWorkers() | ||
| if err != nil { | ||
|
|
@@ -386,6 +430,8 @@ func recordGauges(c *gin.Context) { | |
|
|
||
| // get the unix time from worker_active_interval ago | ||
| before := time.Now().UTC().Add(-c.Value("worker_active_interval").(time.Duration)).Unix() | ||
|
|
||
| // active, inactive counts | ||
| for _, worker := range workers { | ||
| // check if the worker checked in within the last worker_active_interval | ||
| if worker.GetLastCheckedIn() >= before { | ||
|
|
@@ -396,6 +442,31 @@ func recordGauges(c *gin.Context) { | |
| } | ||
| } | ||
|
|
||
| // available, busy, maintenance, error counts | ||
| for _, worker := range workers { | ||
| // check if the worker checked in within the last worker_active_interval | ||
| if worker.GetLastCheckedIn() >= before { | ||
|
|
||
| switch worker.GetStatus() { | ||
KellyMerrick marked this conversation as resolved.
Show resolved
Hide resolved
KellyMerrick marked this conversation as resolved.
Show resolved
Hide resolved
ecrupper marked this conversation as resolved.
Show resolved
Hide resolved
ecrupper marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| case constants.WorkerStatusUnregistered: | ||
KellyMerrick marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
KellyMerrick marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| availableWorkers++ | ||
| case constants.WorkerStatusBusy: | ||
KellyMerrick marked this conversation as resolved.
Show resolved
Hide resolved
KellyMerrick marked this conversation as resolved.
Show resolved
Hide resolved
ecrupper marked this conversation as resolved.
Show resolved
Hide resolved
ecrupper marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| busyWorkers++ | ||
| case constants.WorkerStatusMaintenance: | ||
KellyMerrick marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
KellyMerrick marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| maintenanceWorkers++ | ||
| case constants.WorkerStatusError: | ||
KellyMerrick marked this conversation as resolved.
Show resolved
Hide resolved
KellyMerrick marked this conversation as resolved.
Show resolved
Hide resolved
ecrupper marked this conversation as resolved.
Show resolved
Hide resolved
KellyMerrick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| errorWorkers++ | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // unregistered count | ||
| for _, worker := range workers { | ||
| if worker.GetStatus() == constants.WorkerStatusUnregistered { | ||
|
||
| unregisteredWorkers++ | ||
| } | ||
| } | ||
|
|
||
| // apply metrics based on request query parameters | ||
| // worker_build_limit | ||
| if q.WorkerBuildLimit { | ||
|
|
@@ -411,5 +482,30 @@ func recordGauges(c *gin.Context) { | |
| if q.InactiveWorkerCount { | ||
| totals.WithLabelValues("worker", "count", "inactive").Set(float64(inactiveWorkers)) | ||
| } | ||
|
|
||
| // unregistered_worker_count | ||
| if q.UnregisteredWorkerCount { | ||
| totals.WithLabelValues("worker", "count", "unregistered").Set(float64(unregisteredWorkers)) | ||
| } | ||
|
|
||
| // available_worker_count | ||
| if q.AvailableWorkerCount { | ||
| totals.WithLabelValues("worker", "count", "available").Set(float64(availableWorkers)) | ||
| } | ||
|
|
||
| // busy_worker_count | ||
| if q.BusyWorkerCount { | ||
| totals.WithLabelValues("worker", "count", "busy").Set(float64(busyWorkers)) | ||
| } | ||
|
|
||
| // maintenance_worker_count | ||
| if q.MaintenanceWorkerCount { | ||
| totals.WithLabelValues("worker", "count", "maintenance").Set(float64(maintenanceWorkers)) | ||
| } | ||
|
|
||
| // error_worker_count | ||
| if q.ErrorWorkerCount { | ||
| totals.WithLabelValues("worker", "count", "error").Set(float64(errorWorkers)) | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -323,6 +323,31 @@ func UpdateWorker(c *gin.Context) { | |
| w.SetActive(input.GetActive()) | ||
| } | ||
|
|
||
| if len(input.GetStatus()) > 0 { | ||
|
||
| // update status if set | ||
| w.SetStatus(input.GetStatus()) | ||
|
||
| } | ||
|
|
||
| if input.GetLastStatusUpdateAt() > 0 { | ||
|
||
| // update LastStatusUpdateAt if set | ||
| w.SetLastStatusUpdateAt(input.GetLastStatusUpdateAt()) | ||
|
||
| } | ||
|
|
||
| if len(input.GetRunningBuildIDs()) > 0 { | ||
|
||
| // update RunningBuildIDs if set | ||
| w.SetRunningBuildIDs(input.GetRunningBuildIDs()) | ||
|
||
| } | ||
|
|
||
| if input.GetLastBuildFinishedAt() > 0 { | ||
|
||
| // update LastBuildFinishedAt if set | ||
| w.SetLastBuildFinishedAt(input.GetLastBuildFinishedAt()) | ||
|
||
| } | ||
|
|
||
| if input.GetLastCheckedIn() > 0 { | ||
| // update LastCheckedIn if set | ||
| w.SetLastCheckedIn(input.GetLastCheckedIn()) | ||
| } | ||
|
|
||
| // send API call to update the worker | ||
| err = database.FromContext(c).UpdateWorker(w) | ||
| if err != nil { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -170,12 +170,16 @@ func testSqlite(t *testing.T) *engine { | |
| // Worker type with all fields set to their zero values. | ||
| func testWorker() *library.Worker { | ||
| return &library.Worker{ | ||
| ID: new(int64), | ||
| Hostname: new(string), | ||
| Address: new(string), | ||
| Routes: new([]string), | ||
| Active: new(bool), | ||
| BuildLimit: new(int64), | ||
| LastCheckedIn: new(int64), | ||
| ID: new(int64), | ||
| Hostname: new(string), | ||
| Address: new(string), | ||
| Routes: new([]string), | ||
| Active: new(bool), | ||
| Status: new(string), | ||
|
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. 🚫 [golangci] reported by reviewdog 🐶 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. 🚫 [golangci] reported by reviewdog 🐶 |
||
| LastStatusUpdateAt: new(int64), | ||
|
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. 🚫 [golangci] reported by reviewdog 🐶
KellyMerrick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| RunningBuildIDs: new([]string), | ||
|
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. 🚫 [golangci] reported by reviewdog 🐶
KellyMerrick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| LastBuildFinishedAt: new(int64), | ||
KellyMerrick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| LastCheckedIn: new(int64), | ||
| BuildLimit: new(int64), | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.