diff --git a/cmd/cache/main.go b/cmd/cache/main.go index 98d8c05e68cd6ae517d1fdf5b3240f525beffc18..d7dc8cb9b316635aa9e5ef587858b45b08d34c19 100644 --- a/cmd/cache/main.go +++ b/cmd/cache/main.go @@ -66,7 +66,7 @@ func main() { ) { cacheSvc = cache.New(redis, events, logger) - healthSvc = health.New() + healthSvc = health.New(Version) } // create endpoints diff --git a/design/design.go b/design/design.go index b0de46f5bcda553a1ec8a92b595d368b8b20c097..470b6a6e27c714cd3524267766e900f15f042233 100644 --- a/design/design.go +++ b/design/design.go @@ -20,7 +20,7 @@ var _ = Service("health", func() { Method("Liveness", func() { Payload(Empty) - Result(Empty) + Result(HealthResponse) HTTP(func() { GET("/liveness") Response(StatusOK) @@ -29,7 +29,7 @@ var _ = Service("health", func() { Method("Readiness", func() { Payload(Empty) - Result(Empty) + Result(HealthResponse) HTTP(func() { GET("/readiness") Response(StatusOK) diff --git a/design/types.go b/design/types.go index ae43f342ab8a1aa8037758c977406e4959df9ab6..eee0825d85ed07a661c979e8a5d8ea51edcc2740 100644 --- a/design/types.go +++ b/design/types.go @@ -18,3 +18,10 @@ var CacheSetRequest = Type("CacheSetRequest", func() { Field(5, "ttl", Int) Required("data", "key") }) + +var HealthResponse = Type("HealthResponse", func() { + Field(1, "service", String, "Service name.") + Field(2, "status", String, "Status message.") + Field(3, "version", String, "Service runtime version.") + Required("service", "status", "version") +}) diff --git a/gen/health/client.go b/gen/health/client.go index e981f5517b8f374c6c8da41bbe84fab289299a50..5be9526ea7efd4ec67f77877e460417e16ee17fc 100644 --- a/gen/health/client.go +++ b/gen/health/client.go @@ -28,13 +28,21 @@ func NewClient(liveness, readiness goa.Endpoint) *Client { } // Liveness calls the "Liveness" endpoint of the "health" service. -func (c *Client) Liveness(ctx context.Context) (err error) { - _, err = c.LivenessEndpoint(ctx, nil) - return +func (c *Client) Liveness(ctx context.Context) (res *HealthResponse, err error) { + var ires any + ires, err = c.LivenessEndpoint(ctx, nil) + if err != nil { + return + } + return ires.(*HealthResponse), nil } // Readiness calls the "Readiness" endpoint of the "health" service. -func (c *Client) Readiness(ctx context.Context) (err error) { - _, err = c.ReadinessEndpoint(ctx, nil) - return +func (c *Client) Readiness(ctx context.Context) (res *HealthResponse, err error) { + var ires any + ires, err = c.ReadinessEndpoint(ctx, nil) + if err != nil { + return + } + return ires.(*HealthResponse), nil } diff --git a/gen/health/endpoints.go b/gen/health/endpoints.go index 69ab505ce8234dede2a1cdb360ad330759612f60..4084e47f82a8f980e1205dd1fc08115890d239ed 100644 --- a/gen/health/endpoints.go +++ b/gen/health/endpoints.go @@ -37,7 +37,7 @@ func (e *Endpoints) Use(m func(goa.Endpoint) goa.Endpoint) { // "Liveness" of service "health". func NewLivenessEndpoint(s Service) goa.Endpoint { return func(ctx context.Context, req any) (any, error) { - return nil, s.Liveness(ctx) + return s.Liveness(ctx) } } @@ -45,6 +45,6 @@ func NewLivenessEndpoint(s Service) goa.Endpoint { // "Readiness" of service "health". func NewReadinessEndpoint(s Service) goa.Endpoint { return func(ctx context.Context, req any) (any, error) { - return nil, s.Readiness(ctx) + return s.Readiness(ctx) } } diff --git a/gen/health/service.go b/gen/health/service.go index 31e6a594f3e28291510d6c2884c53476e3c6c4e2..960544a03eff55942552e068ebe0fd1b0513ffda 100644 --- a/gen/health/service.go +++ b/gen/health/service.go @@ -14,9 +14,9 @@ import ( // Health service provides health check endpoints. type Service interface { // Liveness implements Liveness. - Liveness(context.Context) (err error) + Liveness(context.Context) (res *HealthResponse, err error) // Readiness implements Readiness. - Readiness(context.Context) (err error) + Readiness(context.Context) (res *HealthResponse, err error) } // ServiceName is the name of the service as defined in the design. This is the @@ -28,3 +28,13 @@ const ServiceName = "health" // are the same values that are set in the endpoint request contexts under the // MethodKey key. var MethodNames = [2]string{"Liveness", "Readiness"} + +// HealthResponse is the result type of the health service Liveness method. +type HealthResponse struct { + // Service name. + Service string + // Status message. + Status string + // Service runtime version. + Version string +} diff --git a/gen/http/cache/client/cli.go b/gen/http/cache/client/cli.go index 73e49f764da8799c4cd47a13d8896184d260fe4a..4f75bd46a479ad1a576bbd0fac478d8a3298f7ba 100644 --- a/gen/http/cache/client/cli.go +++ b/gen/http/cache/client/cli.go @@ -48,7 +48,7 @@ func BuildSetPayload(cacheSetBody string, cacheSetKey string, cacheSetNamespace { err = json.Unmarshal([]byte(cacheSetBody), &body) if err != nil { - return nil, fmt.Errorf("invalid JSON for body, \nerror: %s, \nexample of valid JSON:\n%s", err, "\"Corporis omnis itaque earum quasi.\"") + return nil, fmt.Errorf("invalid JSON for body, \nerror: %s, \nexample of valid JSON:\n%s", err, "\"Dolorem et quam et illum.\"") } } var key string @@ -99,7 +99,7 @@ func BuildSetExternalPayload(cacheSetExternalBody string, cacheSetExternalKey st { err = json.Unmarshal([]byte(cacheSetExternalBody), &body) if err != nil { - return nil, fmt.Errorf("invalid JSON for body, \nerror: %s, \nexample of valid JSON:\n%s", err, "\"Enim vel.\"") + return nil, fmt.Errorf("invalid JSON for body, \nerror: %s, \nexample of valid JSON:\n%s", err, "\"Quis rerum velit sunt rerum dignissimos at.\"") } } var key string diff --git a/gen/http/cli/cache/cli.go b/gen/http/cli/cache/cli.go index 5b6086b64aea0a9d397860931e6f9c2982583d2a..44fb882cbf558eca3f57bf7e8d0ffe88a836ddaf 100644 --- a/gen/http/cli/cache/cli.go +++ b/gen/http/cli/cache/cli.go @@ -23,15 +23,15 @@ import ( // // command (subcommand1|subcommand2|...) func UsageCommands() string { - return `health (liveness|readiness) -cache (get|set|set-external) + return `cache (get|set|set-external) +health (liveness|readiness) ` } // UsageExamples produces an example of a valid invocation of the CLI tool. func UsageExamples() string { - return os.Args[0] + ` health liveness` + "\n" + - os.Args[0] + ` cache get --key "Sed consequatur rerum occaecati." --namespace "Veritatis exercitationem repudiandae eos." --scope "Sint dolorum occaecati."` + "\n" + + return os.Args[0] + ` cache get --key "Voluptatum modi tenetur tempore quia est ratione." --namespace "Corrupti sunt dolores." --scope "Repellat omnis id ex."` + "\n" + + os.Args[0] + ` health liveness` + "\n" + "" } @@ -45,12 +45,6 @@ func ParseEndpoint( restore bool, ) (goa.Endpoint, any, error) { var ( - healthFlags = flag.NewFlagSet("health", flag.ContinueOnError) - - healthLivenessFlags = flag.NewFlagSet("liveness", flag.ExitOnError) - - healthReadinessFlags = flag.NewFlagSet("readiness", flag.ExitOnError) - cacheFlags = flag.NewFlagSet("cache", flag.ContinueOnError) cacheGetFlags = flag.NewFlagSet("get", flag.ExitOnError) @@ -71,16 +65,22 @@ func ParseEndpoint( cacheSetExternalNamespaceFlag = cacheSetExternalFlags.String("namespace", "", "") cacheSetExternalScopeFlag = cacheSetExternalFlags.String("scope", "", "") cacheSetExternalTTLFlag = cacheSetExternalFlags.String("ttl", "", "") - ) - healthFlags.Usage = healthUsage - healthLivenessFlags.Usage = healthLivenessUsage - healthReadinessFlags.Usage = healthReadinessUsage + healthFlags = flag.NewFlagSet("health", flag.ContinueOnError) + + healthLivenessFlags = flag.NewFlagSet("liveness", flag.ExitOnError) + + healthReadinessFlags = flag.NewFlagSet("readiness", flag.ExitOnError) + ) cacheFlags.Usage = cacheUsage cacheGetFlags.Usage = cacheGetUsage cacheSetFlags.Usage = cacheSetUsage cacheSetExternalFlags.Usage = cacheSetExternalUsage + healthFlags.Usage = healthUsage + healthLivenessFlags.Usage = healthLivenessUsage + healthReadinessFlags.Usage = healthReadinessUsage + if err := flag.CommandLine.Parse(os.Args[1:]); err != nil { return nil, nil, err } @@ -96,10 +96,10 @@ func ParseEndpoint( { svcn = flag.Arg(0) switch svcn { - case "health": - svcf = healthFlags case "cache": svcf = cacheFlags + case "health": + svcf = healthFlags default: return nil, nil, fmt.Errorf("unknown service %q", svcn) } @@ -115,16 +115,6 @@ func ParseEndpoint( { epn = svcf.Arg(0) switch svcn { - case "health": - switch epn { - case "liveness": - epf = healthLivenessFlags - - case "readiness": - epf = healthReadinessFlags - - } - case "cache": switch epn { case "get": @@ -138,6 +128,16 @@ func ParseEndpoint( } + case "health": + switch epn { + case "liveness": + epf = healthLivenessFlags + + case "readiness": + epf = healthReadinessFlags + + } + } } if epf == nil { @@ -158,16 +158,6 @@ func ParseEndpoint( ) { switch svcn { - case "health": - c := healthc.NewClient(scheme, host, doer, enc, dec, restore) - switch epn { - case "liveness": - endpoint = c.Liveness() - data = nil - case "readiness": - endpoint = c.Readiness() - data = nil - } case "cache": c := cachec.NewClient(scheme, host, doer, enc, dec, restore) switch epn { @@ -181,6 +171,16 @@ func ParseEndpoint( endpoint = c.SetExternal() data, err = cachec.BuildSetExternalPayload(*cacheSetExternalBodyFlag, *cacheSetExternalKeyFlag, *cacheSetExternalNamespaceFlag, *cacheSetExternalScopeFlag, *cacheSetExternalTTLFlag) } + case "health": + c := healthc.NewClient(scheme, host, doer, enc, dec, restore) + switch epn { + case "liveness": + endpoint = c.Liveness() + data = nil + case "readiness": + endpoint = c.Readiness() + data = nil + } } } if err != nil { @@ -190,40 +190,6 @@ func ParseEndpoint( return endpoint, data, nil } -// healthUsage displays the usage of the health command and its subcommands. -func healthUsage() { - fmt.Fprintf(os.Stderr, `Health service provides health check endpoints. -Usage: - %[1]s [globalflags] health COMMAND [flags] - -COMMAND: - liveness: Liveness implements Liveness. - readiness: Readiness implements Readiness. - -Additional help: - %[1]s health COMMAND --help -`, os.Args[0]) -} -func healthLivenessUsage() { - fmt.Fprintf(os.Stderr, `%[1]s [flags] health liveness - -Liveness implements Liveness. - -Example: - %[1]s health liveness -`, os.Args[0]) -} - -func healthReadinessUsage() { - fmt.Fprintf(os.Stderr, `%[1]s [flags] health readiness - -Readiness implements Readiness. - -Example: - %[1]s health readiness -`, os.Args[0]) -} - // cacheUsage displays the usage of the cache command and its subcommands. func cacheUsage() { fmt.Fprintf(os.Stderr, `Cache service allows storing and retrieving data from distributed cache. @@ -248,7 +214,7 @@ Get JSON value from the cache. -scope STRING: Example: - %[1]s cache get --key "Sed consequatur rerum occaecati." --namespace "Veritatis exercitationem repudiandae eos." --scope "Sint dolorum occaecati." + %[1]s cache get --key "Voluptatum modi tenetur tempore quia est ratione." --namespace "Corrupti sunt dolores." --scope "Repellat omnis id ex." `, os.Args[0]) } @@ -263,7 +229,7 @@ Set a JSON value in the cache. -ttl INT: Example: - %[1]s cache set --body "Corporis omnis itaque earum quasi." --key "Et eligendi nihil optio natus assumenda." --namespace "Quasi perspiciatis." --scope "Accusantium animi non alias." --ttl 3495630911155968941 + %[1]s cache set --body "Dolorem et quam et illum." --key "Esse inventore ullam placeat aut." --namespace "Omnis itaque." --scope "Quasi ut." --ttl 3100652887298323449 `, os.Args[0]) } @@ -278,6 +244,40 @@ Set an external JSON value in the cache and provide an event for the input. -ttl INT: Example: - %[1]s cache set-external --body "Enim vel." --key "Ut in." --namespace "Ab dolores distinctio quis." --scope "Optio aliquam error nam." --ttl 2227603043401673122 + %[1]s cache set-external --body "Quis rerum velit sunt rerum dignissimos at." --key "Optio aliquam error nam." --namespace "Recusandae illo." --scope "Placeat veniam veritatis doloribus." --ttl 5137048679846705449 +`, os.Args[0]) +} + +// healthUsage displays the usage of the health command and its subcommands. +func healthUsage() { + fmt.Fprintf(os.Stderr, `Health service provides health check endpoints. +Usage: + %[1]s [globalflags] health COMMAND [flags] + +COMMAND: + liveness: Liveness implements Liveness. + readiness: Readiness implements Readiness. + +Additional help: + %[1]s health COMMAND --help +`, os.Args[0]) +} +func healthLivenessUsage() { + fmt.Fprintf(os.Stderr, `%[1]s [flags] health liveness + +Liveness implements Liveness. + +Example: + %[1]s health liveness +`, os.Args[0]) +} + +func healthReadinessUsage() { + fmt.Fprintf(os.Stderr, `%[1]s [flags] health readiness + +Readiness implements Readiness. + +Example: + %[1]s health readiness `, os.Args[0]) } diff --git a/gen/http/health/client/encode_decode.go b/gen/http/health/client/encode_decode.go index cb20154956dedf0e69af4da9145e656b927f4666..952812eaa10aabb2cc9abb8ec90dff5f03895e1d 100644 --- a/gen/http/health/client/encode_decode.go +++ b/gen/http/health/client/encode_decode.go @@ -51,7 +51,20 @@ func DecodeLivenessResponse(decoder func(*http.Response) goahttp.Decoder, restor } switch resp.StatusCode { case http.StatusOK: - return nil, nil + var ( + body LivenessResponseBody + err error + ) + err = decoder(resp).Decode(&body) + if err != nil { + return nil, goahttp.ErrDecodingError("health", "Liveness", err) + } + err = ValidateLivenessResponseBody(&body) + if err != nil { + return nil, goahttp.ErrValidationError("health", "Liveness", err) + } + res := NewLivenessHealthResponseOK(&body) + return res, nil default: body, _ := io.ReadAll(resp.Body) return nil, goahttp.ErrInvalidResponse("health", "Liveness", resp.StatusCode, string(body)) @@ -93,7 +106,20 @@ func DecodeReadinessResponse(decoder func(*http.Response) goahttp.Decoder, resto } switch resp.StatusCode { case http.StatusOK: - return nil, nil + var ( + body ReadinessResponseBody + err error + ) + err = decoder(resp).Decode(&body) + if err != nil { + return nil, goahttp.ErrDecodingError("health", "Readiness", err) + } + err = ValidateReadinessResponseBody(&body) + if err != nil { + return nil, goahttp.ErrValidationError("health", "Readiness", err) + } + res := NewReadinessHealthResponseOK(&body) + return res, nil default: body, _ := io.ReadAll(resp.Body) return nil, goahttp.ErrInvalidResponse("health", "Readiness", resp.StatusCode, string(body)) diff --git a/gen/http/health/client/types.go b/gen/http/health/client/types.go index 409dc360abe9ce472e0e90dd4c12416188c8dab0..b6b3b4ecffc4ffd1b3897c19257a6cfca01494aa 100644 --- a/gen/http/health/client/types.go +++ b/gen/http/health/client/types.go @@ -6,3 +6,84 @@ // $ goa gen gitlab.eclipse.org/eclipse/xfsc/tsa/cache/design package client + +import ( + health "gitlab.eclipse.org/eclipse/xfsc/tsa/cache/gen/health" + goa "goa.design/goa/v3/pkg" +) + +// LivenessResponseBody is the type of the "health" service "Liveness" endpoint +// HTTP response body. +type LivenessResponseBody struct { + // Service name. + Service *string `form:"service,omitempty" json:"service,omitempty" xml:"service,omitempty"` + // Status message. + Status *string `form:"status,omitempty" json:"status,omitempty" xml:"status,omitempty"` + // Service runtime version. + Version *string `form:"version,omitempty" json:"version,omitempty" xml:"version,omitempty"` +} + +// ReadinessResponseBody is the type of the "health" service "Readiness" +// endpoint HTTP response body. +type ReadinessResponseBody struct { + // Service name. + Service *string `form:"service,omitempty" json:"service,omitempty" xml:"service,omitempty"` + // Status message. + Status *string `form:"status,omitempty" json:"status,omitempty" xml:"status,omitempty"` + // Service runtime version. + Version *string `form:"version,omitempty" json:"version,omitempty" xml:"version,omitempty"` +} + +// NewLivenessHealthResponseOK builds a "health" service "Liveness" endpoint +// result from a HTTP "OK" response. +func NewLivenessHealthResponseOK(body *LivenessResponseBody) *health.HealthResponse { + v := &health.HealthResponse{ + Service: *body.Service, + Status: *body.Status, + Version: *body.Version, + } + + return v +} + +// NewReadinessHealthResponseOK builds a "health" service "Readiness" endpoint +// result from a HTTP "OK" response. +func NewReadinessHealthResponseOK(body *ReadinessResponseBody) *health.HealthResponse { + v := &health.HealthResponse{ + Service: *body.Service, + Status: *body.Status, + Version: *body.Version, + } + + return v +} + +// ValidateLivenessResponseBody runs the validations defined on +// LivenessResponseBody +func ValidateLivenessResponseBody(body *LivenessResponseBody) (err error) { + if body.Service == nil { + err = goa.MergeErrors(err, goa.MissingFieldError("service", "body")) + } + if body.Status == nil { + err = goa.MergeErrors(err, goa.MissingFieldError("status", "body")) + } + if body.Version == nil { + err = goa.MergeErrors(err, goa.MissingFieldError("version", "body")) + } + return +} + +// ValidateReadinessResponseBody runs the validations defined on +// ReadinessResponseBody +func ValidateReadinessResponseBody(body *ReadinessResponseBody) (err error) { + if body.Service == nil { + err = goa.MergeErrors(err, goa.MissingFieldError("service", "body")) + } + if body.Status == nil { + err = goa.MergeErrors(err, goa.MissingFieldError("status", "body")) + } + if body.Version == nil { + err = goa.MergeErrors(err, goa.MissingFieldError("version", "body")) + } + return +} diff --git a/gen/http/health/server/encode_decode.go b/gen/http/health/server/encode_decode.go index 1bb4927c1102ec400119a44efb7a2fe75a3bc2fc..1b6dc0e4d005d76b306948ed4b84185e813753e6 100644 --- a/gen/http/health/server/encode_decode.go +++ b/gen/http/health/server/encode_decode.go @@ -11,6 +11,7 @@ import ( "context" "net/http" + health "gitlab.eclipse.org/eclipse/xfsc/tsa/cache/gen/health" goahttp "goa.design/goa/v3/http" ) @@ -18,8 +19,11 @@ import ( // health Liveness endpoint. func EncodeLivenessResponse(encoder func(context.Context, http.ResponseWriter) goahttp.Encoder) func(context.Context, http.ResponseWriter, any) error { return func(ctx context.Context, w http.ResponseWriter, v any) error { + res, _ := v.(*health.HealthResponse) + enc := encoder(ctx, w) + body := NewLivenessResponseBody(res) w.WriteHeader(http.StatusOK) - return nil + return enc.Encode(body) } } @@ -27,7 +31,10 @@ func EncodeLivenessResponse(encoder func(context.Context, http.ResponseWriter) g // health Readiness endpoint. func EncodeReadinessResponse(encoder func(context.Context, http.ResponseWriter) goahttp.Encoder) func(context.Context, http.ResponseWriter, any) error { return func(ctx context.Context, w http.ResponseWriter, v any) error { + res, _ := v.(*health.HealthResponse) + enc := encoder(ctx, w) + body := NewReadinessResponseBody(res) w.WriteHeader(http.StatusOK) - return nil + return enc.Encode(body) } } diff --git a/gen/http/health/server/types.go b/gen/http/health/server/types.go index 5ad49ba49335195a74667666406f9e994c92ab89..48e5d9438769f9c509a51f012e0e85a244f325f3 100644 --- a/gen/http/health/server/types.go +++ b/gen/http/health/server/types.go @@ -6,3 +6,51 @@ // $ goa gen gitlab.eclipse.org/eclipse/xfsc/tsa/cache/design package server + +import ( + health "gitlab.eclipse.org/eclipse/xfsc/tsa/cache/gen/health" +) + +// LivenessResponseBody is the type of the "health" service "Liveness" endpoint +// HTTP response body. +type LivenessResponseBody struct { + // Service name. + Service string `form:"service" json:"service" xml:"service"` + // Status message. + Status string `form:"status" json:"status" xml:"status"` + // Service runtime version. + Version string `form:"version" json:"version" xml:"version"` +} + +// ReadinessResponseBody is the type of the "health" service "Readiness" +// endpoint HTTP response body. +type ReadinessResponseBody struct { + // Service name. + Service string `form:"service" json:"service" xml:"service"` + // Status message. + Status string `form:"status" json:"status" xml:"status"` + // Service runtime version. + Version string `form:"version" json:"version" xml:"version"` +} + +// NewLivenessResponseBody builds the HTTP response body from the result of the +// "Liveness" endpoint of the "health" service. +func NewLivenessResponseBody(res *health.HealthResponse) *LivenessResponseBody { + body := &LivenessResponseBody{ + Service: res.Service, + Status: res.Status, + Version: res.Version, + } + return body +} + +// NewReadinessResponseBody builds the HTTP response body from the result of +// the "Readiness" endpoint of the "health" service. +func NewReadinessResponseBody(res *health.HealthResponse) *ReadinessResponseBody { + body := &ReadinessResponseBody{ + Service: res.Service, + Status: res.Status, + Version: res.Version, + } + return body +} diff --git a/gen/http/openapi.json b/gen/http/openapi.json index db6dba5cfe04622d911f3e0751f9cc4b850e9974..febee9e13843c7696b10226d473cbc0aeeb535e8 100644 --- a/gen/http/openapi.json +++ b/gen/http/openapi.json @@ -1 +1 @@ -{"swagger":"2.0","info":{"title":"Cache Service","description":"The cache service exposes interface for working with Redis.","version":""},"host":"localhost:8083","consumes":["application/json","application/xml","application/gob"],"produces":["application/json","application/xml","application/gob"],"paths":{"/liveness":{"get":{"tags":["health"],"summary":"Liveness health","operationId":"health#Liveness","responses":{"200":{"description":"OK response."}},"schemes":["http"]}},"/readiness":{"get":{"tags":["health"],"summary":"Readiness health","operationId":"health#Readiness","responses":{"200":{"description":"OK response."}},"schemes":["http"]}},"/v1/cache":{"get":{"tags":["cache"],"summary":"Get cache","description":"Get JSON value from the cache.","operationId":"cache#Get","produces":["application/json"],"parameters":[{"name":"x-cache-key","in":"header","description":"Cache entry key","required":true,"type":"string"},{"name":"x-cache-namespace","in":"header","description":"Cache entry namespace","required":false,"type":"string"},{"name":"x-cache-scope","in":"header","description":"Cache entry scope","required":false,"type":"string"}],"responses":{"200":{"description":"OK response.","schema":{"type":"string","format":"binary"}}},"schemes":["http"]},"post":{"tags":["cache"],"summary":"Set cache","description":"Set a JSON value in the cache.","operationId":"cache#Set","parameters":[{"name":"x-cache-key","in":"header","description":"Cache entry key","required":true,"type":"string"},{"name":"x-cache-namespace","in":"header","description":"Cache entry namespace","required":false,"type":"string"},{"name":"x-cache-scope","in":"header","description":"Cache entry scope","required":false,"type":"string"},{"name":"x-cache-ttl","in":"header","description":"Cache entry TTL in seconds","required":false,"type":"integer"},{"name":"any","in":"body","required":true,"schema":{"type":"string","format":"binary"}}],"responses":{"201":{"description":"Created response."}},"schemes":["http"]}},"/v1/external/cache":{"post":{"tags":["cache"],"summary":"SetExternal cache","description":"Set an external JSON value in the cache and provide an event for the input.","operationId":"cache#SetExternal","parameters":[{"name":"x-cache-key","in":"header","description":"Cache entry key","required":true,"type":"string"},{"name":"x-cache-namespace","in":"header","description":"Cache entry namespace","required":false,"type":"string"},{"name":"x-cache-scope","in":"header","description":"Cache entry scope","required":false,"type":"string"},{"name":"x-cache-ttl","in":"header","description":"Cache entry TTL in seconds","required":false,"type":"integer"},{"name":"any","in":"body","required":true,"schema":{"type":"string","format":"binary"}}],"responses":{"200":{"description":"OK response."}},"schemes":["http"]}}}} \ No newline at end of file +{"swagger":"2.0","info":{"title":"Cache Service","description":"The cache service exposes interface for working with Redis.","version":""},"host":"localhost:8083","consumes":["application/json","application/xml","application/gob"],"produces":["application/json","application/xml","application/gob"],"paths":{"/liveness":{"get":{"tags":["health"],"summary":"Liveness health","operationId":"health#Liveness","responses":{"200":{"description":"OK response.","schema":{"$ref":"#/definitions/HealthLivenessResponseBody","required":["service","status","version"]}}},"schemes":["http"]}},"/readiness":{"get":{"tags":["health"],"summary":"Readiness health","operationId":"health#Readiness","responses":{"200":{"description":"OK response.","schema":{"$ref":"#/definitions/HealthReadinessResponseBody","required":["service","status","version"]}}},"schemes":["http"]}},"/v1/cache":{"get":{"tags":["cache"],"summary":"Get cache","description":"Get JSON value from the cache.","operationId":"cache#Get","produces":["application/json"],"parameters":[{"name":"x-cache-key","in":"header","description":"Cache entry key","required":true,"type":"string"},{"name":"x-cache-namespace","in":"header","description":"Cache entry namespace","required":false,"type":"string"},{"name":"x-cache-scope","in":"header","description":"Cache entry scope","required":false,"type":"string"}],"responses":{"200":{"description":"OK response.","schema":{"type":"string","format":"binary"}}},"schemes":["http"]},"post":{"tags":["cache"],"summary":"Set cache","description":"Set a JSON value in the cache.","operationId":"cache#Set","parameters":[{"name":"x-cache-key","in":"header","description":"Cache entry key","required":true,"type":"string"},{"name":"x-cache-namespace","in":"header","description":"Cache entry namespace","required":false,"type":"string"},{"name":"x-cache-scope","in":"header","description":"Cache entry scope","required":false,"type":"string"},{"name":"x-cache-ttl","in":"header","description":"Cache entry TTL in seconds","required":false,"type":"integer"},{"name":"any","in":"body","required":true,"schema":{"type":"string","format":"binary"}}],"responses":{"201":{"description":"Created response."}},"schemes":["http"]}},"/v1/external/cache":{"post":{"tags":["cache"],"summary":"SetExternal cache","description":"Set an external JSON value in the cache and provide an event for the input.","operationId":"cache#SetExternal","parameters":[{"name":"x-cache-key","in":"header","description":"Cache entry key","required":true,"type":"string"},{"name":"x-cache-namespace","in":"header","description":"Cache entry namespace","required":false,"type":"string"},{"name":"x-cache-scope","in":"header","description":"Cache entry scope","required":false,"type":"string"},{"name":"x-cache-ttl","in":"header","description":"Cache entry TTL in seconds","required":false,"type":"integer"},{"name":"any","in":"body","required":true,"schema":{"type":"string","format":"binary"}}],"responses":{"200":{"description":"OK response."}},"schemes":["http"]}}},"definitions":{"HealthLivenessResponseBody":{"title":"HealthLivenessResponseBody","type":"object","properties":{"service":{"type":"string","description":"Service name.","example":"Laborum reprehenderit rerum est et ut dolores."},"status":{"type":"string","description":"Status message.","example":"Consequatur porro qui est dolor a."},"version":{"type":"string","description":"Service runtime version.","example":"Ad dolor."}},"example":{"service":"Fugiat voluptatem vel et.","status":"Sint tempore est nam iusto.","version":"Ipsam quidem aut velit vitae est."},"required":["service","status","version"]},"HealthReadinessResponseBody":{"title":"HealthReadinessResponseBody","type":"object","properties":{"service":{"type":"string","description":"Service name.","example":"Repellat qui totam et recusandae."},"status":{"type":"string","description":"Status message.","example":"Dolores at qui aliquam ullam."},"version":{"type":"string","description":"Service runtime version.","example":"Omnis ex fugit corporis."}},"example":{"service":"Minima sed et.","status":"Veniam optio qui.","version":"Suscipit velit aliquid et."},"required":["service","status","version"]}}} \ No newline at end of file diff --git a/gen/http/openapi.yaml b/gen/http/openapi.yaml index 318deff9c50515a43c6516246403fc4ae8b59da5..3648e0c82368173c51c7c1ff87e89388b3fb8042 100644 --- a/gen/http/openapi.yaml +++ b/gen/http/openapi.yaml @@ -22,6 +22,12 @@ paths: responses: "200": description: OK response. + schema: + $ref: '#/definitions/HealthLivenessResponseBody' + required: + - service + - status + - version schemes: - http /readiness: @@ -33,6 +39,12 @@ paths: responses: "200": description: OK response. + schema: + $ref: '#/definitions/HealthReadinessResponseBody' + required: + - service + - status + - version schemes: - http /v1/cache: @@ -145,3 +157,52 @@ paths: description: OK response. schemes: - http +definitions: + HealthLivenessResponseBody: + title: HealthLivenessResponseBody + type: object + properties: + service: + type: string + description: Service name. + example: Laborum reprehenderit rerum est et ut dolores. + status: + type: string + description: Status message. + example: Consequatur porro qui est dolor a. + version: + type: string + description: Service runtime version. + example: Ad dolor. + example: + service: Fugiat voluptatem vel et. + status: Sint tempore est nam iusto. + version: Ipsam quidem aut velit vitae est. + required: + - service + - status + - version + HealthReadinessResponseBody: + title: HealthReadinessResponseBody + type: object + properties: + service: + type: string + description: Service name. + example: Repellat qui totam et recusandae. + status: + type: string + description: Status message. + example: Dolores at qui aliquam ullam. + version: + type: string + description: Service runtime version. + example: Omnis ex fugit corporis. + example: + service: Minima sed et. + status: Veniam optio qui. + version: Suscipit velit aliquid et. + required: + - service + - status + - version diff --git a/gen/http/openapi3.json b/gen/http/openapi3.json index 5ca1b4375609d2baac7a6b758f36b94141c1e3a2..605856bfa27850eb6f1bf81f1b1101d5742ed5ec 100644 --- a/gen/http/openapi3.json +++ b/gen/http/openapi3.json @@ -1 +1 @@ -{"openapi":"3.0.3","info":{"title":"Cache Service","description":"The cache service exposes interface for working with Redis.","version":"1.0"},"servers":[{"url":"http://localhost:8083","description":"Cache Server"}],"paths":{"/liveness":{"get":{"tags":["health"],"summary":"Liveness health","operationId":"health#Liveness","responses":{"200":{"description":"OK response."}}}},"/readiness":{"get":{"tags":["health"],"summary":"Readiness health","operationId":"health#Readiness","responses":{"200":{"description":"OK response."}}}},"/v1/cache":{"get":{"tags":["cache"],"summary":"Get cache","description":"Get JSON value from the cache.","operationId":"cache#Get","parameters":[{"name":"x-cache-key","in":"header","description":"Cache entry key","allowEmptyValue":true,"required":true,"schema":{"type":"string","description":"Cache entry key","example":"did:web:example.com"},"example":"did:web:example.com"},{"name":"x-cache-namespace","in":"header","description":"Cache entry namespace","allowEmptyValue":true,"schema":{"type":"string","description":"Cache entry namespace","example":"Login"},"example":"Login"},{"name":"x-cache-scope","in":"header","description":"Cache entry scope","allowEmptyValue":true,"schema":{"type":"string","description":"Cache entry scope","example":"administration"},"example":"administration"}],"responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"type":"string","example":"Delectus quaerat molestiae placeat nemo.","format":"binary"},"example":"Quia dolores rem."}}}}},"post":{"tags":["cache"],"summary":"Set cache","description":"Set a JSON value in the cache.","operationId":"cache#Set","parameters":[{"name":"x-cache-key","in":"header","description":"Cache entry key","allowEmptyValue":true,"required":true,"schema":{"type":"string","description":"Cache entry key","example":"did:web:example.com"},"example":"did:web:example.com"},{"name":"x-cache-namespace","in":"header","description":"Cache entry namespace","allowEmptyValue":true,"schema":{"type":"string","description":"Cache entry namespace","example":"Login"},"example":"Login"},{"name":"x-cache-scope","in":"header","description":"Cache entry scope","allowEmptyValue":true,"schema":{"type":"string","description":"Cache entry scope","example":"administration"},"example":"administration"},{"name":"x-cache-ttl","in":"header","description":"Cache entry TTL in seconds","allowEmptyValue":true,"schema":{"type":"integer","description":"Cache entry TTL in seconds","example":60,"format":"int64"},"example":60}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"string","example":"Quis rerum velit sunt rerum dignissimos at.","format":"binary"},"example":"Est illum."}}},"responses":{"201":{"description":"Created response."}}}},"/v1/external/cache":{"post":{"tags":["cache"],"summary":"SetExternal cache","description":"Set an external JSON value in the cache and provide an event for the input.","operationId":"cache#SetExternal","parameters":[{"name":"x-cache-key","in":"header","description":"Cache entry key","allowEmptyValue":true,"required":true,"schema":{"type":"string","description":"Cache entry key","example":"did:web:example.com"},"example":"did:web:example.com"},{"name":"x-cache-namespace","in":"header","description":"Cache entry namespace","allowEmptyValue":true,"schema":{"type":"string","description":"Cache entry namespace","example":"Login"},"example":"Login"},{"name":"x-cache-scope","in":"header","description":"Cache entry scope","allowEmptyValue":true,"schema":{"type":"string","description":"Cache entry scope","example":"administration"},"example":"administration"},{"name":"x-cache-ttl","in":"header","description":"Cache entry TTL in seconds","allowEmptyValue":true,"schema":{"type":"integer","description":"Cache entry TTL in seconds","example":60,"format":"int64"},"example":60}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"string","example":"Molestiae minima.","format":"binary"},"example":"Repellendus quo."}}},"responses":{"200":{"description":"OK response."}}}}},"components":{},"tags":[{"name":"health","description":"Health service provides health check endpoints."},{"name":"cache","description":"Cache service allows storing and retrieving data from distributed cache."}]} \ No newline at end of file +{"openapi":"3.0.3","info":{"title":"Cache Service","description":"The cache service exposes interface for working with Redis.","version":"1.0"},"servers":[{"url":"http://localhost:8083","description":"Cache Server"}],"paths":{"/liveness":{"get":{"tags":["health"],"summary":"Liveness health","operationId":"health#Liveness","responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HealthResponse"},"example":{"service":"Molestiae minima.","status":"Quia dolores rem.","version":"Est illum."}}}}}}},"/readiness":{"get":{"tags":["health"],"summary":"Readiness health","operationId":"health#Readiness","responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HealthResponse"},"example":{"service":"Repellendus quo.","status":"Cumque aut.","version":"Sit sint ipsa fugiat et id rem."}}}}}}},"/v1/cache":{"get":{"tags":["cache"],"summary":"Get cache","description":"Get JSON value from the cache.","operationId":"cache#Get","parameters":[{"name":"x-cache-key","in":"header","description":"Cache entry key","allowEmptyValue":true,"required":true,"schema":{"type":"string","description":"Cache entry key","example":"did:web:example.com"},"example":"did:web:example.com"},{"name":"x-cache-namespace","in":"header","description":"Cache entry namespace","allowEmptyValue":true,"schema":{"type":"string","description":"Cache entry namespace","example":"Login"},"example":"Login"},{"name":"x-cache-scope","in":"header","description":"Cache entry scope","allowEmptyValue":true,"schema":{"type":"string","description":"Cache entry scope","example":"administration"},"example":"administration"}],"responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"type":"string","example":"Rerum et qui alias qui.","format":"binary"},"example":"Accusamus ratione voluptatibus."}}}}},"post":{"tags":["cache"],"summary":"Set cache","description":"Set a JSON value in the cache.","operationId":"cache#Set","parameters":[{"name":"x-cache-key","in":"header","description":"Cache entry key","allowEmptyValue":true,"required":true,"schema":{"type":"string","description":"Cache entry key","example":"did:web:example.com"},"example":"did:web:example.com"},{"name":"x-cache-namespace","in":"header","description":"Cache entry namespace","allowEmptyValue":true,"schema":{"type":"string","description":"Cache entry namespace","example":"Login"},"example":"Login"},{"name":"x-cache-scope","in":"header","description":"Cache entry scope","allowEmptyValue":true,"schema":{"type":"string","description":"Cache entry scope","example":"administration"},"example":"administration"},{"name":"x-cache-ttl","in":"header","description":"Cache entry TTL in seconds","allowEmptyValue":true,"schema":{"type":"integer","description":"Cache entry TTL in seconds","example":60,"format":"int64"},"example":60}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"string","example":"Beatae commodi.","format":"binary"},"example":"Quae minus maiores nulla deleniti ipsa."}}},"responses":{"201":{"description":"Created response."}}}},"/v1/external/cache":{"post":{"tags":["cache"],"summary":"SetExternal cache","description":"Set an external JSON value in the cache and provide an event for the input.","operationId":"cache#SetExternal","parameters":[{"name":"x-cache-key","in":"header","description":"Cache entry key","allowEmptyValue":true,"required":true,"schema":{"type":"string","description":"Cache entry key","example":"did:web:example.com"},"example":"did:web:example.com"},{"name":"x-cache-namespace","in":"header","description":"Cache entry namespace","allowEmptyValue":true,"schema":{"type":"string","description":"Cache entry namespace","example":"Login"},"example":"Login"},{"name":"x-cache-scope","in":"header","description":"Cache entry scope","allowEmptyValue":true,"schema":{"type":"string","description":"Cache entry scope","example":"administration"},"example":"administration"},{"name":"x-cache-ttl","in":"header","description":"Cache entry TTL in seconds","allowEmptyValue":true,"schema":{"type":"integer","description":"Cache entry TTL in seconds","example":60,"format":"int64"},"example":60}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"string","example":"Fuga voluptas explicabo et libero.","format":"binary"},"example":"Quidem nihil quis tempore."}}},"responses":{"200":{"description":"OK response."}}}}},"components":{"schemas":{"HealthResponse":{"type":"object","properties":{"service":{"type":"string","description":"Service name.","example":"Illum nam ratione nisi."},"status":{"type":"string","description":"Status message.","example":"Labore vel."},"version":{"type":"string","description":"Service runtime version.","example":"Aut illum."}},"example":{"service":"Itaque vel.","status":"Itaque enim aut consequatur beatae ut.","version":"Et atque impedit nostrum perspiciatis ipsum."},"required":["service","status","version"]}}},"tags":[{"name":"cache","description":"Cache service allows storing and retrieving data from distributed cache."},{"name":"health","description":"Health service provides health check endpoints."}]} \ No newline at end of file diff --git a/gen/http/openapi3.yaml b/gen/http/openapi3.yaml index 5b5d95762fe4893de50198869bb9753df65c4a8f..61ccd2d10543d218a16fb87c715c17cafe1d589b 100644 --- a/gen/http/openapi3.yaml +++ b/gen/http/openapi3.yaml @@ -16,6 +16,14 @@ paths: responses: "200": description: OK response. + content: + application/json: + schema: + $ref: '#/components/schemas/HealthResponse' + example: + service: Molestiae minima. + status: Quia dolores rem. + version: Est illum. /readiness: get: tags: @@ -25,6 +33,14 @@ paths: responses: "200": description: OK response. + content: + application/json: + schema: + $ref: '#/components/schemas/HealthResponse' + example: + service: Repellendus quo. + status: Cumque aut. + version: Sit sint ipsa fugiat et id rem. /v1/cache: get: tags: @@ -68,9 +84,9 @@ paths: application/json: schema: type: string - example: Delectus quaerat molestiae placeat nemo. + example: Rerum et qui alias qui. format: binary - example: Quia dolores rem. + example: Accusamus ratione voluptatibus. post: tags: - cache @@ -122,9 +138,9 @@ paths: application/json: schema: type: string - example: Quis rerum velit sunt rerum dignissimos at. + example: Beatae commodi. format: binary - example: Est illum. + example: Quae minus maiores nulla deleniti ipsa. responses: "201": description: Created response. @@ -180,15 +196,39 @@ paths: application/json: schema: type: string - example: Molestiae minima. + example: Fuga voluptas explicabo et libero. format: binary - example: Repellendus quo. + example: Quidem nihil quis tempore. responses: "200": description: OK response. -components: {} +components: + schemas: + HealthResponse: + type: object + properties: + service: + type: string + description: Service name. + example: Illum nam ratione nisi. + status: + type: string + description: Status message. + example: Labore vel. + version: + type: string + description: Service runtime version. + example: Aut illum. + example: + service: Itaque vel. + status: Itaque enim aut consequatur beatae ut. + version: Et atque impedit nostrum perspiciatis ipsum. + required: + - service + - status + - version tags: - - name: health - description: Health service provides health check endpoints. - name: cache description: Cache service allows storing and retrieving data from distributed cache. + - name: health + description: Health service provides health check endpoints. diff --git a/internal/service/health/service.go b/internal/service/health/service.go index ffa6d9af3d67b8681ce5464bc555ca38aa6b801e..25177bc15aabf807448f07d17a1497761d7c591d 100644 --- a/internal/service/health/service.go +++ b/internal/service/health/service.go @@ -1,17 +1,31 @@ package health -import "context" +import ( + "context" -type Service struct{} + "gitlab.eclipse.org/eclipse/xfsc/tsa/cache/gen/health" +) -func New() *Service { - return &Service{} +type Service struct { + version string } -func (s *Service) Liveness(ctx context.Context) error { - return nil +func New(version string) *Service { + return &Service{version: version} } -func (s *Service) Readiness(ctx context.Context) error { - return nil +func (s *Service) Liveness(_ context.Context) (*health.HealthResponse, error) { + return &health.HealthResponse{ + Service: "cache", + Status: "up", + Version: s.version, + }, nil +} + +func (s *Service) Readiness(_ context.Context) (*health.HealthResponse, error) { + return &health.HealthResponse{ + Service: "cache", + Status: "up", + Version: s.version, + }, nil }