Skip to content

Commit b86a3a3

Browse files
kmavromationcilla
authored andcommitted
svc-mgmt: add health endpoint to control service - opensource implementation
Add implementation for the /health endpoint on the open source control service. GitOrigin-RevId: a47b33c6f3e052fb2b871b0cbcc4edd6bd6a357a
1 parent 82db040 commit b86a3a3

32 files changed

+1374
-129
lines changed

go/cs/BUILD.bazel

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ go_library(
1919
"//go/cs/segreg/grpc:go_default_library",
2020
"//go/cs/segreq:go_default_library",
2121
"//go/cs/segreq/grpc:go_default_library",
22+
"//go/lib/addr:go_default_library",
2223
"//go/lib/common:go_default_library",
2324
"//go/lib/infra/infraenv:go_default_library",
2425
"//go/lib/infra/modules/segfetcher/grpc:go_default_library",
@@ -44,6 +45,7 @@ go_library(
4445
"//go/pkg/command:go_default_library",
4546
"//go/pkg/cs:go_default_library",
4647
"//go/pkg/cs/api:go_default_library",
48+
"//go/pkg/cs/trust:go_default_library",
4749
"//go/pkg/cs/trust/grpc:go_default_library",
4850
"//go/pkg/cs/trust/metrics:go_default_library",
4951
"//go/pkg/discovery:go_default_library",

go/cs/main.go

+45
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import (
4242
segreggrpc "github.com/scionproto/scion/go/cs/segreg/grpc"
4343
"github.com/scionproto/scion/go/cs/segreq"
4444
segreqgrpc "github.com/scionproto/scion/go/cs/segreq/grpc"
45+
"github.com/scionproto/scion/go/lib/addr"
4546
"github.com/scionproto/scion/go/lib/common"
4647
"github.com/scionproto/scion/go/lib/infra/infraenv"
4748
segfetchergrpc "github.com/scionproto/scion/go/lib/infra/modules/segfetcher/grpc"
@@ -67,6 +68,7 @@ import (
6768
"github.com/scionproto/scion/go/pkg/command"
6869
"github.com/scionproto/scion/go/pkg/cs"
6970
"github.com/scionproto/scion/go/pkg/cs/api"
71+
cstrust "github.com/scionproto/scion/go/pkg/cs/trust"
7072
cstrustgrpc "github.com/scionproto/scion/go/pkg/cs/trust/grpc"
7173
cstrustmetrics "github.com/scionproto/scion/go/pkg/cs/trust/metrics"
7274
"github.com/scionproto/scion/go/pkg/discovery"
@@ -563,6 +565,11 @@ func realMain(ctx context.Context) error {
563565
LogLevel: service.NewLogLevelStatusPage().Handler,
564566
Signer: signer,
565567
Topology: topo.HandleHTTP,
568+
Healther: &healther{
569+
Signer: signer,
570+
TrustDB: trustDB,
571+
ISD: topo.IA().I,
572+
},
566573
}
567574
log.Info("Exposing API", "addr", globalCfg.API.Addr)
568575
s := http.Server{
@@ -709,3 +716,41 @@ func adaptInterfaceMap(in map[common.IFIDType]topology.IFInfo) map[uint16]ifstat
709716
}
710717
return converted
711718
}
719+
720+
type healther struct {
721+
Signer cstrust.RenewingSigner
722+
TrustDB storage.TrustDB
723+
ISD addr.ISD
724+
}
725+
726+
func (h *healther) GetSignerHealth(ctx context.Context) api.SignerHealthData {
727+
signer, err := h.Signer.SignerGen.Generate(ctx)
728+
if err != nil {
729+
return api.SignerHealthData{
730+
SignerMissing: true,
731+
SignerMissingDetail: err.Error(),
732+
}
733+
}
734+
return api.SignerHealthData{
735+
Expiration: signer.Expiration,
736+
InGrace: signer.InGrace,
737+
}
738+
}
739+
740+
func (h *healther) GetTRCHealth(ctx context.Context) api.TRCHealthData {
741+
trc, err := h.TrustDB.SignedTRC(ctx, cppki.TRCID{ISD: h.ISD})
742+
if err != nil {
743+
return api.TRCHealthData{
744+
TRCNotFound: true,
745+
TRCNotFoundDetail: err.Error(),
746+
}
747+
}
748+
if trc.IsZero() {
749+
return api.TRCHealthData{
750+
TRCNotFound: true,
751+
}
752+
}
753+
return api.TRCHealthData{
754+
TRCID: trc.TRC.ID,
755+
}
756+
}

go/pkg/api/health/api/BUILD.bazel

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
load("//lint:go.bzl", "go_library")
2+
load("@com_github_scionproto_scion//rules_openapi:defs.bzl", "openapi_generate_go")
3+
4+
openapi_generate_go(
5+
name = "api_generated",
6+
src = "//spec:health",
7+
server = True,
8+
spec = False,
9+
)
10+
11+
# exclude the *.gen.go files in the workspace it's only for editor compatibility.
12+
# gazelle:exclude *.gen.go
13+
go_library(
14+
name = "go_default_library",
15+
srcs = [
16+
"helpers.go",
17+
":api_generated", # keep
18+
],
19+
importpath = "github.com/scionproto/scion/go/pkg/api/health/api",
20+
visibility = ["//visibility:public"],
21+
deps = [
22+
"@com_github_go_chi_chi_v5//:go_default_library", # keep
23+
"@com_github_pkg_errors//:go_default_library", # keep
24+
],
25+
)

go/pkg/api/health/api/client.gen.go

+242
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/pkg/api/health/api/helpers.go

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2021 Anapaya Systems
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package api
16+
17+
// AggregateHealthStatus returns the least healthy status of the input.
18+
func AggregateHealthStatus(checksStatus []Status) Status {
19+
lowestStatus := StatusPassing
20+
for _, checkStatus := range checksStatus {
21+
switch checkStatus {
22+
case StatusFailing:
23+
return StatusFailing
24+
case StatusDegraded:
25+
lowestStatus = StatusDegraded
26+
}
27+
}
28+
return lowestStatus
29+
}

0 commit comments

Comments
 (0)