From be0cfc2d95a129ffdfe1c8ecc5253c11cbbb9f99 Mon Sep 17 00:00:00 2001 From: Rick Spurgeon Date: Thu, 24 Aug 2023 13:40:23 -0500 Subject: [PATCH] Adds /health route to flights service (#83) --- flight-data/flights/api/flights-server.gen.go | 47 ++++++++++++------- flight-data/flights/api/flights.go | 4 ++ flight-data/flights/openapi.yaml | 25 ++++++++++ 3 files changed, 60 insertions(+), 16 deletions(-) diff --git a/flight-data/flights/api/flights-server.gen.go b/flight-data/flights/api/flights-server.gen.go index 7a7a833..1e0c949 100644 --- a/flight-data/flights/api/flights-server.gen.go +++ b/flight-data/flights/api/flights-server.gen.go @@ -30,6 +30,9 @@ type ServerInterface interface { // Fetch more details about a flight // (GET /flights/{flightNumber}/details) GetFlightDetails(ctx echo.Context, flightNumber string) error + // Health check endpoint for Kubernetes + // (GET /health) + GetHealth(ctx echo.Context) error } // ServerInterfaceWrapper converts echo contexts to parameters. @@ -87,6 +90,15 @@ func (w *ServerInterfaceWrapper) GetFlightDetails(ctx echo.Context) error { return err } +// GetHealth converts echo context to params. +func (w *ServerInterfaceWrapper) GetHealth(ctx echo.Context) error { + var err error + + // Invoke the callback with all the unmarshalled arguments + err = w.Handler.GetHealth(ctx) + return err +} + // This is a simple interface which specifies echo.Route addition functions which // are present on both echo.Echo and echo.Group, since we want to allow using // either of them for path registration @@ -118,28 +130,31 @@ func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL router.GET(baseURL+"/flights", wrapper.GetFlights) router.GET(baseURL+"/flights/:flightNumber", wrapper.GetFlightByNumber) router.GET(baseURL+"/flights/:flightNumber/details", wrapper.GetFlightDetails) + router.GET(baseURL+"/health", wrapper.GetHealth) } // Base64 encoded, gzipped, json marshaled Swagger object var swaggerSpec = []string{ - "H4sIAAAAAAAC/9xWTY/bNhD9K8S0hxaQba2zBRrdUqRugiySYjenrhcGLY1sphKpDEduDUP/vSBF2d6V", - "7HjTHopcbEKcj8eZ9zjcQWrKymjUbCHZgU3XWE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7G7YPQ1iMi/r351J2WR7X8", + "ucD9oJ1o3eGz1ezuDmD3cCZtcbdlB7VrhJPcj1cv84LcVa9n/2HRHlfs98n12Vpd97h+CsVPoLQJnHa3", + "gOsSGtqw1bXjPD4/odxbWPsDRIXG8OXQ6LAevFsf3RuBZ4pYrqzMBmTW5/6i6fHzuYqbZNuBaFB5F0hp", + "wSqlkQVTxhfKOjihcgd11s1a/w+ZPYeO3c5fysqu5P9xdp7CkcPELJCXVBwk4HuZ1UpIYlRwYjpcBH6S", + "C3NnG4AZ4mTNeIiPH9oUL+z7fkXbdDsHMCRwfTn4WfNkfcPwy4QJm2lcx1//cHxWduFfCnMbaZ8KbaVZ", + "WmD6lWHXOj/62wVqiYRBFq57wwdCN0+8/fOj/yzwere6hAQKotokkwmvxfirkssRF3qcKjf5rv8NAAD/", + "/ykOwQQhDwAA", } // GetSwagger returns the content of the embedded swagger specification file diff --git a/flight-data/flights/api/flights.go b/flight-data/flights/api/flights.go index de8efeb..9f83c5b 100644 --- a/flight-data/flights/api/flights.go +++ b/flight-data/flights/api/flights.go @@ -150,6 +150,10 @@ func NewFlightService() *FlightService { return &rv } +func (s *FlightService) GetHealth(ctx echo.Context) error { + return ctx.JSON(http.StatusOK, map[string]string{"status": "OK"}) +} + func (s *FlightService) GetFlights(ctx echo.Context, params models.GetFlightsParams) error { return ctx.JSON(http.StatusOK, s.Flights) } diff --git a/flight-data/flights/openapi.yaml b/flight-data/flights/openapi.yaml index 64691e1..e52f70e 100644 --- a/flight-data/flights/openapi.yaml +++ b/flight-data/flights/openapi.yaml @@ -12,6 +12,31 @@ servers: description: KongAir API Server paths: + /health: + get: + summary: Health check endpoint for Kubernetes + description: Endpoint that returns the service health status. + responses: + '200': + description: Service is healthy + content: + application/json: + schema: + type: object + properties: + status: + type: string + example: "OK" + '500': + description: Service is unhealthy + content: + application/json: + schema: + type: object + properties: + status: + type: string + example: "unhealthy" "/flights": get: summary: Get KongAir planned flights