Skip to content
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

Fetch detailed pod resource usage and requets #715

Merged
merged 26 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ build: $(BINS)
mocks: bootstrap
mockgen -source ./api/buildstatus/models/buildstatus.go -destination ./api/test/mock/buildstatus_mock.go -package mock
mockgen -source ./api/deployments/deployment_handler.go -destination ./api/deployments/mock/deployment_handler_mock.go -package mock
mockgen -source ./api/metrics/prometheus_handler.go -destination ./api/metrics/mock/prometheus_handler_mock.go -package mock
mockgen -source ./api/metrics/prometheus_client.go -destination ./api/metrics/mock/prometheus_client_mock.go -package mock
mockgen -source ./api/metrics/prometheus/prometheus_client.go -destination ./api/metrics/prometheus/mock/prometheus_client_mock.go -package mock
mockgen -source ./api/metrics/metrics_handler.go -destination ./api/metrics/mock/metrics_handler_mock.go -package mock
mockgen -source ./api/environments/job_handler.go -destination ./api/environments/mock/job_handler_mock.go -package mock
mockgen -source ./api/environments/environment_handler.go -destination ./api/environments/mock/environment_handler_mock.go -package mock
mockgen -source ./api/utils/tlsvalidation/interface.go -destination ./api/utils/tlsvalidation/mock/tls_secret_validator_mock.go -package mock
Expand Down
86 changes: 56 additions & 30 deletions api/applications/applications_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ type applicationController struct {
*models.DefaultController
hasAccessToRR
applicationHandlerFactory ApplicationHandlerFactory
prometheusHandler metrics.PrometheusHandler
metricsHandler *metrics.Handler
}

// NewApplicationController Constructor
func NewApplicationController(hasAccessTo hasAccessToRR, applicationHandlerFactory ApplicationHandlerFactory, prometheusHandler metrics.PrometheusHandler) models.Controller {
func NewApplicationController(hasAccessTo hasAccessToRR, applicationHandlerFactory ApplicationHandlerFactory, metricsHandler *metrics.Handler) models.Controller {
if hasAccessTo == nil {
hasAccessTo = hasAccess
}

return &applicationController{
hasAccessToRR: hasAccessTo,
applicationHandlerFactory: applicationHandlerFactory,
prometheusHandler: prometheusHandler,
metricsHandler: metricsHandler,
}
}

Expand Down Expand Up @@ -137,9 +137,14 @@ func (ac *applicationController) GetRoutes() models.Routes {
HandlerFunc: ac.RegenerateDeployKeyHandler,
},
models.Route{
Path: appPath + "/resources",
Path: appPath + "/utilization",
Method: "GET",
HandlerFunc: ac.GetUsedResources,
HandlerFunc: ac.GetApplicationResourcesUtilization,
},
models.Route{
Path: appPath + "/environments/{envName}/utilization",
Method: "GET",
HandlerFunc: ac.GetEnvironmentResourcesUtilization,
},
}

Expand Down Expand Up @@ -1001,37 +1006,61 @@ func (ac *applicationController) TriggerPipelinePromote(accounts models.Accounts
ac.JSONResponse(w, r, &jobSummary)
}

// GetUsedResources Gets used resources for the application
func (ac *applicationController) GetUsedResources(accounts models.Accounts, w http.ResponseWriter, r *http.Request) {
// swagger:operation GET /applications/{appName}/resources application getResources
// GetApplicationResourcesUtilization Gets used resources for the application
func (ac *applicationController) GetApplicationResourcesUtilization(_ models.Accounts, w http.ResponseWriter, r *http.Request) {
// swagger:operation GET /applications/{appName}/utilization application GetApplicationResourcesUtilization
// ---
// summary: Gets used resources for the application
// summary: Gets max resources used by the application
// parameters:
// - name: appName
// in: path
// description: Name of the application
// type: string
// required: true
// - name: environment
// in: query
// description: Name of the application environment
// - name: Impersonate-User
// in: header
// description: Works only with custom setup of cluster. Allow impersonation of test users (Required if Impersonate-Group is set)
// type: string
// required: false
// - name: component
// in: query
// description: Name of the application component in an environment
// - name: Impersonate-Group
// in: header
// description: Works only with custom setup of cluster. Allow impersonation of a comma-seperated list of test groups (Required if Impersonate-User is set)
// type: string
// required: false
// - name: duration
// in: query
// description: Duration of the period, default is 30d (30 days). Example 10m, 1h, 2d, 3w, where m-minutes, h-hours, d-days, w-weeks
// responses:
// "200":
// description: Successful trigger pipeline
// schema:
// "$ref": "#/definitions/ReplicaResourcesUtilizationResponse"
// "404":
// description: "Not found"
appName := mux.Vars(r)["appName"]

utilization, err := ac.metricsHandler.GetReplicaResourcesUtilization(r.Context(), appName, "")
if err != nil {
ac.ErrorResponse(w, r, err)
return
}

ac.JSONResponse(w, r, &utilization)
}

// GetEnvironmentResourcesUtilization Gets used resources for the application
func (ac *applicationController) GetEnvironmentResourcesUtilization(_ models.Accounts, w http.ResponseWriter, r *http.Request) {
// swagger:operation GET /applications/{appName}/environments/{envName}/utilization environment GetEnvironmentResourcesUtilization
// ---
// summary: Gets max resources used by the application
// parameters:
// - name: appName
// in: path
// description: Name of the application
// type: string
// required: false
// - name: since
// in: query
// description: End time-point of the period in the past, default is now. Example 10m, 1h, 2d, 3w, where m-minutes, h-hours, d-days, w-weeks
// required: true
// - name: envName
// in: path
// description: Name of the application environment
// type: string
// required: false
// required: true
// - name: Impersonate-User
// in: header
// description: Works only with custom setup of cluster. Allow impersonation of test users (Required if Impersonate-Group is set)
Expand All @@ -1046,20 +1075,17 @@ func (ac *applicationController) GetUsedResources(accounts models.Accounts, w ht
// "200":
// description: Successful trigger pipeline
// schema:
// "$ref": "#/definitions/UsedResources"
// "$ref": "#/definitions/ReplicaResourcesUtilizationResponse"
// "404":
// description: "Not found"
appName := mux.Vars(r)["appName"]
envName := r.FormValue("environment")
componentName := r.FormValue("component")
duration := r.FormValue("duration")
since := r.FormValue("since")
envName := mux.Vars(r)["envName"]

usedResources, err := ac.prometheusHandler.GetUsedResources(r.Context(), accounts.UserAccount.RadixClient, appName, envName, componentName, duration, since)
utilization, err := ac.metricsHandler.GetReplicaResourcesUtilization(r.Context(), appName, envName)
if err != nil {
ac.ErrorResponse(w, r, err)
return
}

ac.JSONResponse(w, r, &usedResources)
ac.JSONResponse(w, r, &utilization)
}
Loading
Loading