Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion cmd/serv.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,19 @@ var serv = &cobra.Command{
time := clock.RealClock{}

eventService := services.NewEventService(prescalingEvents, time)
hpaService := services.NewHPAService(client.Clientset)

eventHandler := handlers.NewEventHandlers(eventService)
statusHandler := handlers.NewStatusHandlers()
hpaHandler := handlers.NewHPAHandlers(hpaService)

collector := exporter.NewPrescalingCollector(
prescaling.NewPrescaling(client, eventService),
)

prometheus.MustRegister(collector)

return server.NewServer(statusHandler, eventHandler).Initialize()
return server.NewServer(statusHandler, eventHandler, hpaHandler).Initialize()
},
}

Expand Down
94 changes: 94 additions & 0 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,52 @@ const docTemplate = `{
}
}
}
},
"/api/v1/hpas": {
"get": {
"description": "Checks if all HPAs in the cluster have at least the minimum number of running pods",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"cluster"
],
"summary": "Check if HPAs meet their required minimums",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/services.HPAMinimumStatus"
}
}
}
}
},
"/api/v1/hpas/check": {
"get": {
"description": "Checks if the platform is correctly scaled and returns HPA details",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"cluster"
],
"summary": "Check the platform scaling status",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/services.PlatformScalingStatus"
}
}
}
}
}
},
"definitions": {
Expand Down Expand Up @@ -302,6 +348,54 @@ const docTemplate = `{
}
}
},
"services.HPAInfo": {
"type": "object",
"properties": {
"hpaMinReplicas": {
"type": "integer"
},
"meetsMinimum": {
"type": "boolean"
},
"minReplicasAnnotation": {
"type": "integer"
},
"name": {
"type": "string"
},
"namespace": {
"type": "string"
},
"targetKind": {
"type": "string"
},
"targetName": {
"type": "string"
}
}
},
"services.HPAMinimumStatus": {
"type": "object",
"properties": {
"allHPAsMeetMinimum": {
"type": "boolean"
},
"hpaInfos": {
"type": "array",
"items": {
"$ref": "#/definitions/services.HPAInfo"
}
}
}
},
"services.PlatformScalingStatus": {
"type": "object",
"properties": {
"isPlatformScaled": {
"type": "boolean"
}
}
},
"services.PrescalingEventOutput": {
"type": "object",
"properties": {
Expand Down
94 changes: 94 additions & 0 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,52 @@
}
}
}
},
"/api/v1/hpas": {
"get": {
"description": "Checks if all HPAs in the cluster have at least the minimum number of running pods",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"cluster"
],
"summary": "Check if HPAs meet their required minimums",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/services.HPAMinimumStatus"
}
}
}
}
},
"/api/v1/hpas/check": {
"get": {
"description": "Checks if the platform is correctly scaled and returns HPA details",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"cluster"
],
"summary": "Check the platform scaling status",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/services.PlatformScalingStatus"
}
}
}
}
}
},
"definitions": {
Expand Down Expand Up @@ -294,6 +340,54 @@
}
}
},
"services.HPAInfo": {
"type": "object",
"properties": {
"hpaMinReplicas": {
"type": "integer"
},
"meetsMinimum": {
"type": "boolean"
},
"minReplicasAnnotation": {
"type": "integer"
},
"name": {
"type": "string"
},
"namespace": {
"type": "string"
},
"targetKind": {
"type": "string"
},
"targetName": {
"type": "string"
}
}
},
"services.HPAMinimumStatus": {
"type": "object",
"properties": {
"allHPAsMeetMinimum": {
"type": "boolean"
},
"hpaInfos": {
"type": "array",
"items": {
"$ref": "#/definitions/services.HPAInfo"
}
}
}
},
"services.PlatformScalingStatus": {
"type": "object",
"properties": {
"isPlatformScaled": {
"type": "boolean"
}
}
},
"services.PrescalingEventOutput": {
"type": "object",
"properties": {
Expand Down
62 changes: 62 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,37 @@ definitions:
example: "20:00:00"
type: string
type: object
services.HPAInfo:
properties:
hpaMinReplicas:
type: integer
meetsMinimum:
type: boolean
minReplicasAnnotation:
type: integer
name:
type: string
namespace:
type: string
targetKind:
type: string
targetName:
type: string
type: object
services.HPAMinimumStatus:
properties:
allHPAsMeetMinimum:
type: boolean
hpaInfos:
items:
$ref: '#/definitions/services.HPAInfo'
type: array
type: object
services.PlatformScalingStatus:
properties:
isPlatformScaled:
type: boolean
type: object
services.PrescalingEventOutput:
properties:
date:
Expand Down Expand Up @@ -218,4 +249,35 @@ paths:
summary: Get current prescaling Event
tags:
- prescalingevent
/api/v1/hpas:
get:
consumes:
- application/json
description: Checks if all HPAs in the cluster have at least the minimum number
of running pods
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/services.HPAMinimumStatus'
summary: Check if HPAs meet their required minimums
tags:
- cluster
/api/v1/hpas/check:
get:
consumes:
- application/json
description: Checks if the platform is correctly scaled and returns HPA details
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/services.PlatformScalingStatus'
summary: Check the platform scaling status
tags:
- cluster
swagger: "2.0"
67 changes: 67 additions & 0 deletions pkg/handlers/hpa_handlers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package handlers

import (
"net/http"

log "github.com/sirupsen/logrus"

"github.com/BedrockStreaming/prescaling-exporter/pkg/services"
"github.com/BedrockStreaming/prescaling-exporter/pkg/utils"
)

// IHPAHandlers defines the interface for HPA handlers
type IHPAHandlers interface {
CheckHPAMinimums(w http.ResponseWriter, r *http.Request)
GetPlatformScalingStatus(w http.ResponseWriter, r *http.Request)
}

// HPAHandlers implements IHPAHandlers
type HPAHandlers struct {
hpaService services.IHPAService
}

// NewHPAHandlers creates a new instance of HPAHandlers
func NewHPAHandlers(hpaService services.IHPAService) IHPAHandlers {
return &HPAHandlers{
hpaService: hpaService,
}
}

// CheckHPAMinimums
// @Summary Check if HPAs meet their required minimums
// @Description Checks if all HPAs in the cluster have at least the minimum number of running pods
// @Tags cluster
// @Accept json
// @Produce json
// @Success 200 {object} services.HPAMinimumStatus
// @Router /api/v1/hpas [get]
func (h *HPAHandlers) CheckHPAMinimums(w http.ResponseWriter, r *http.Request) {
status, err := h.hpaService.CheckHPAMinimums()
if err != nil {
log.Error(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

utils.WriteResponse(w, http.StatusOK, status)
}

// GetPlatformScalingStatus
// @Summary Check the platform scaling status
// @Description Checks if the platform is correctly scaled and returns HPA details
// @Tags cluster
// @Accept json
// @Produce json
// @Success 200 {object} services.PlatformScalingStatus
// @Router /api/v1/hpas/check [get]
func (h *HPAHandlers) GetPlatformScalingStatus(w http.ResponseWriter, r *http.Request) {
status, err := h.hpaService.GetPlatformScalingStatus()
if err != nil {
log.Error(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

// If the platform is not correctly scaled, return a 200 OK status
utils.WriteResponse(w, http.StatusOK, status)
}
Loading