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

Feature/health check #55

Merged
merged 2 commits into from
Jan 14, 2025
Merged
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
17 changes: 10 additions & 7 deletions api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ paths:
tags:
- other
summary: Get the health status.
security: []
description: Retrieve information about the status of openEm components.
operationId: OtherController_getHealth
responses:
Expand Down Expand Up @@ -467,15 +468,17 @@ 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:
- status
- scicatStatus
- globusStatus
GetExtractorResponse:
type: object
properties:
Expand Down
5 changes: 5 additions & 0 deletions cmd/openem-ingestor-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 6 additions & 8 deletions internal/core/globus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions internal/core/scicathealth.go
Original file line number Diff line number Diff line change
@@ -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
}
104 changes: 49 additions & 55 deletions internal/webserver/api.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 27 additions & 2 deletions internal/webserver/other.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package webserver

import "context"
import (
"context"

"github.com/SwissOpenEM/Ingestor/internal/core"
)

func (i *IngestorWebServerImplemenation) OtherControllerGetVersion(ctx context.Context, request OtherControllerGetVersionRequestObject) (OtherControllerGetVersionResponseObject, error) {
return OtherControllerGetVersion200JSONResponse{
Expand All @@ -9,5 +13,26 @@ func (i *IngestorWebServerImplemenation) OtherControllerGetVersion(ctx context.C
}

func (i *IngestorWebServerImplemenation) OtherControllerGetHealth(ctx context.Context, request OtherControllerGetHealthRequestObject) (OtherControllerGetHealthResponseObject, error) {
return nil, 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
}
}
Loading