From dcec8bb684349903a4eb1f6a090d2399c860198b Mon Sep 17 00:00:00 2001 From: consolethinks Date: Wed, 8 Jan 2025 14:43:52 +0100 Subject: [PATCH] implement health check --- api/openapi.yaml | 14 ++-- cmd/openem-ingestor-service/main.go | 5 ++ internal/core/globus.go | 14 ++-- internal/core/scicathealth.go | 26 +++++++ internal/webserver/api.gen.go | 102 +++++++++++++--------------- internal/webserver/other.go | 29 ++++++-- 6 files changed, 116 insertions(+), 74 deletions(-) create mode 100644 internal/core/scicathealth.go diff --git a/api/openapi.yaml b/api/openapi.yaml index dc64be1..81cde65 100644 --- a/api/openapi.yaml +++ b/api/openapi.yaml @@ -468,17 +468,15 @@ components: OtherHealthResponse: type: object properties: - ingestorStatus: + status: type: string description: Status of the ingestor. - scicatStatus: - type: string - description: Status of SciCat. - globusStatus: - type: string - description: Status of Globus. + errors: + type: object + additionalProperties: + type: string required: - - ingestorStatus + - status - scicatStatus - globusStatus GetExtractorResponse: diff --git a/cmd/openem-ingestor-service/main.go b/cmd/openem-ingestor-service/main.go index 9808f88..bd3923b 100644 --- a/cmd/openem-ingestor-service/main.go +++ b/cmd/openem-ingestor-service/main.go @@ -30,6 +30,11 @@ func main() { ctx := context.Background() + // setup globus if we have a refresh token + if config.Transfer.Globus.RefreshToken != "" { + core.GlobusLoginWithRefreshToken(config.Transfer.Globus) + } + tq := core.TaskQueue{ Config: config, AppContext: ctx, diff --git a/internal/core/globus.go b/internal/core/globus.go index 24022c1..a08fba8 100644 --- a/internal/core/globus.go +++ b/internal/core/globus.go @@ -67,6 +67,12 @@ func GlobusIsClientReady() bool { return globusClient.IsClientSet() } +/*func GlobusHealthCheck() error { + // NOTE: this is not a proper health check and takes a long time to finish (~900ms) + _, err := globusClient.TransferGetTaskList(0, 1) + return err +}*/ + func GlobusSetHttpClient(client *http.Client) { globusClient = globus.HttpClientToGlobusClient(client) } @@ -99,14 +105,6 @@ func globusCheckTransfer(globusTaskId string) (bytesTransferred int, filesTransf } func GlobusTransfer(globusConf task.GlobusTransferConfig, task task.IngestionTask, taskCtx context.Context, localTaskId uuid.UUID, datasetFolder string, fileList []datasetIngestor.Datafile, notifier ProgressNotifier) error { - // check if globus client is properly set up, use refresh token if available - if !globusClient.IsClientSet() { - if globusConf.RefreshToken == "" { - return fmt.Errorf("globus: not logged into globus") - } - GlobusLoginWithRefreshToken(globusConf) - } - // transfer given filelist var filePathList []string var fileIsSymlinkList []bool diff --git a/internal/core/scicathealth.go b/internal/core/scicathealth.go new file mode 100644 index 0000000..efdb633 --- /dev/null +++ b/internal/core/scicathealth.go @@ -0,0 +1,26 @@ +package core + +import ( + "errors" + "fmt" + "net/http" +) + +func ScicatHealthTest(APIServer string) error { + // note: there's no function to use the /health endpoint in scicat-cli + // so here's a function that uses it. + resp, err := http.DefaultClient.Get(APIServer + "/health") + if err != nil { + return err + } + defer resp.Body.Close() + + if resp.StatusCode == 503 { + return errors.New("health check failed") + } + if resp.StatusCode != http.StatusOK { + return fmt.Errorf("unexpected status code: %d %s", resp.StatusCode, resp.Status) + } + + return nil +} diff --git a/internal/webserver/api.gen.go b/internal/webserver/api.gen.go index 945d49a..2da6b0c 100644 --- a/internal/webserver/api.gen.go +++ b/internal/webserver/api.gen.go @@ -88,14 +88,10 @@ type MethodItem struct { // OtherHealthResponse defines model for OtherHealthResponse. type OtherHealthResponse struct { - // GlobusStatus Status of Globus. - GlobusStatus string `json:"globusStatus"` + Errors *map[string]string `json:"errors,omitempty"` - // IngestorStatus Status of the ingestor. - IngestorStatus string `json:"ingestorStatus"` - - // ScicatStatus Status of SciCat. - ScicatStatus string `json:"scicatStatus"` + // Status Status of the ingestor. + Status string `json:"status"` } // OtherVersionResponse defines model for OtherVersionResponse. @@ -1188,52 +1184,52 @@ func (sh *strictHandler) OtherControllerGetVersion(ctx *gin.Context) { // Base64 encoded, gzipped, json marshaled Swagger object var swaggerSpec = []string{ - "H4sIAAAAAAAC/+xaW2/byBX+KwdsgSQALbu72z7ozfU6WaFxEsTZAkVsbEbkkT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+XpMRF9/qVFz9CzGrSDThKMb", - "RS7fzZK0DejkL5OLyQV5TlUoWcWTafL95GLyPRE6s4Xzx3nGhCBlHaGii1LCg7MfeZqy41VcQw9qVqJ1", - "GezjrideKg0Fk7ngcun0ZrUtlOa/eW9QqUqlAfIV5rDQqnSL3s5+vIJKqxXPneMdKEjdTYuJUOW2YW51", - "jQcTzq5sjeAOJle371/SmRaz0AuMnUoueNix97TY04oz7/cX3w0B6xSOdgdTZxkas6hFkiYFsjxUB0J5", - "EA+f15hzTTF2SBKKlx8uLnzMSYvSudbiV3teCcZl2/yNPp0elHnBuKBar0aiHy5XTPDc+1dp8Gbbpslf", - "H+/8mbSoJRNwi3qFGnw/1SWZZPrxPk1MXZZMb3YlpqhhS8JsQphEaQNFJPe0x3kg7k4Q7HKM1RxX6AC7", - "UCJHUlPXma01Rt5mK8YFmwvsNTz9aAq550pJq5UQqNvmbBhdY5isqMvrOr4v6DviilCOEtArtuSSxYp5", - "oXTJLHEsl3a0l9h/6C3/7dDBb4YlMFToBMCTjt4Nne8G4GFVJYLbzn81agdCh4rokQ54BGNhSScixQZ0", - "8Hw+SR43omYhanQojxyWG/S+QnsAUxHLEbb32zSplBkB7pVGZhFYfBxQYInSUjMb8odLNpTrYgVDMd1W", - "qUfw67NPC+Ggzt9Vvnk0940Uk9t+1Ue8vH1CAI2VjQcQ1NaGHXb/BvBpqbBfabXdxC9rzS0m99seV3on", - "AgOJ64iUUZgRV2IcvZzGli2CByOWQ9OVIfSakU+PPJurN83g4/8s+mQsOhy7jUDzctfjSpuWRykkIrue", - "jFqNLN8FLVHkIXB1ANxC1kO4cJOF4/ilhoMM7mryuao9J7fdGhXW1yW0thqi1nXhPcT6sUbyhI4am56M", - "+MmviOr0HNTx0LdkrfuxFFh0xexmP0VqBo8KtfTCjDp0JrnlrnVrGo5+a7IQaj303Su0r92+p1T170NV", - "Ttmz19I4BmG27ladj1vpH6uCRVDiYAks1FLV9lAb+NqvOMUYfqlHEuaYpxBVaYYWh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7yZgakhNOojR29sHdGXsddTO7uW64", - "u6MDqTfIfJOjpViOC1YL+2hJPM5+B/nvZ4lfK//1QKdGa6qyJdreW8VmKObWnceO29tEoMVhFRxfnrUN", - "Xf9bpScqW8Y/zfrGM7A9X2WN+CGugYzJDMX/tKV82CDsygkckNHMYDrle3PpfpseGR6wODbCvCka2qmO", - "K5tjxoAFFxZJw2ETOoRc53uV06ZdnTe3R96ZPfqs7BvOxr71LOyUSHiFFppo+AMNWh48aBsAeAJvI3jr", - "0BS2MIP2batVoKTYAJGvkug+PJqMBxSRcOdzlOOj5azWmpLhav+nKseGceErlyefxu1+hzPqstC6R3X+", - "sBM512jwHXHHBnMPAV26S81pwvKSS4/GsPXgVXp0r+m2M52PSAO9NIk+PX2HFutDJj15o5F2v92tHUsP", - "t3tZa7IiqHZbYtclStRMdCfT7X7e7tv77b8DAAD//1o31yrmLQAA", + "H4sIAAAAAAAC/+xaW2/cxhX+KwdsAdsAtXKTtA96cxXFWTRODCspUFhCMss5u5x4OEPPDHe9Cfa/F2cu", + "vCy5F7WSm4c+CNCSw5lz+c53LuTvWaGrWitUzmZXv2e2KLFi/t+vUaLDHw1TdonmHX5s0Dq6URtdo3EC", + "/TKhVmjdnNP/HG1hRO2EVtlVNvd3hFYgODgNbKGNA1ciiHQnyzO3rTG7yqwzQq2y3a69ohe/YuGyXT6S", + "xNZaWXxyUfLMOuYaO97ue9xAuAd6Odxmdp5KN8ZoM9ag0NzrNZKkQmvZaureLs8MfmyEQZ5dvQ87dOvv", + "J85+je5r5phFd9iUPCwIZnVY2Ump4gVmDNv639oxOTbXj3QZVFMt0JDB0uY9WwnlcIVmpE4rR9r8gEI3", + "n5xhhdNH0FGhKzWf8OZ3wrrkxwodozMBw4YEmfAgKFahhUKrpVg1BjkI1XO9NlneWerPBpfZVfanyy66", + "LmNoXb7x280dVv+FCZMyJw3YW3jMfm+i3gfDfCkkvmWunBCtRKC7UDNXJjtalFg45N7XYLDQhs+mQizI", + "9z2rcHrndqNu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AAA==", } // GetSwagger returns the content of the embedded swagger specification file diff --git a/internal/webserver/other.go b/internal/webserver/other.go index b9ce6da..e76b057 100644 --- a/internal/webserver/other.go +++ b/internal/webserver/other.go @@ -2,6 +2,8 @@ package webserver import ( "context" + + "github.com/SwissOpenEM/Ingestor/internal/core" ) func (i *IngestorWebServerImplemenation) OtherControllerGetVersion(ctx context.Context, request OtherControllerGetVersionRequestObject) (OtherControllerGetVersionResponseObject, error) { @@ -11,9 +13,26 @@ func (i *IngestorWebServerImplemenation) OtherControllerGetVersion(ctx context.C } func (i *IngestorWebServerImplemenation) OtherControllerGetHealth(ctx context.Context, request OtherControllerGetHealthRequestObject) (OtherControllerGetHealthResponseObject, error) { - return OtherControllerGetHealth200JSONResponse{ - IngestorStatus: "placeholder", - ScicatStatus: "placeholder", - GlobusStatus: "placeholder", - }, nil + errors := map[string]string{} + + err := core.ScicatHealthTest(i.taskQueue.Config.Scicat.Host) + if err != nil { + errors["scicat"] = err.Error() + } + + /*err = core.GlobusHealthCheck() + if err != nil { + errors["globus"] = err.Error() + }*/ + + if len(errors) > 0 { + return OtherControllerGetHealth200JSONResponse{ + Status: "error", + Errors: &errors, + }, nil + } else { + return OtherControllerGetHealth200JSONResponse{ + Status: "ok", + }, nil + } }