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

feat(kuma-cp) CA backend stats in Dataplane and Mesh Insights #2562

Merged
merged 6 commits into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
210 changes: 117 additions & 93 deletions api/mesh/v1alpha1/dataplane_insight.pb.go

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions api/mesh/v1alpha1/dataplane_insight.proto
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ message DataplaneInsight {

// Number of certificate regenerations for a Dataplane.
uint32 certificate_regenerations = 3;

// Backend that was used to generate current certificate
string issuedBackend = 4;

// Supported backends (CA).
repeated string supportedBackends = 5;
}
}

Expand Down
4 changes: 3 additions & 1 deletion api/mesh/v1alpha1/dataplane_insight_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (x *DataplaneInsight) GetSubscription(id string) (int, *DiscoverySubscripti
return -1, nil
}

func (x *DataplaneInsight) UpdateCert(generation time.Time, expiration time.Time) error {
func (x *DataplaneInsight) UpdateCert(generation time.Time, expiration time.Time, issuedBackend string, supportedBackends []string) error {
if x.MTLS == nil {
x.MTLS = &DataplaneInsight_MTLS{}
}
Expand All @@ -69,6 +69,8 @@ func (x *DataplaneInsight) UpdateCert(generation time.Time, expiration time.Time
if err := ts.CheckValid(); err != nil {
return err
}
x.MTLS.IssuedBackend = issuedBackend
x.MTLS.SupportedBackends = supportedBackends
x.MTLS.LastCertificateRegeneration = ts
return nil
}
Expand Down
248 changes: 183 additions & 65 deletions api/mesh/v1alpha1/mesh_insight.pb.go

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions api/mesh/v1alpha1/mesh_insight.proto
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,14 @@ message MeshInsight {
map<string, DataplaneStat> envoy = 2;
}
DpVersions dpVersions = 4;

message MTLS {
// Dataplanes grouped by issued backends.
map<string, DataplaneStat> issuedBackends = 1;
// Dataplanes grouped by supported backends.
map<string, DataplaneStat> supportedBackends = 2;
}

// mTLS statistics
MTLS mTLS = 5;
}
28 changes: 27 additions & 1 deletion app/kumactl/cmd/inspect/inspect_dataplanes.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,24 @@ func newInspectDataplanesCmd(pctx *cmd.RootContext) *cobra.Command {

func printDataplaneOverviews(now time.Time, dataplaneOverviews *core_mesh.DataplaneOverviewResourceList, out io.Writer) error {
data := printers.Table{
Headers: []string{"MESH", "NAME", "TAGS", "STATUS", "LAST CONNECTED AGO", "LAST UPDATED AGO", "TOTAL UPDATES", "TOTAL ERRORS", "CERT REGENERATED AGO", "CERT EXPIRATION", "CERT REGENERATIONS", "KUMA-DP VERSION", "ENVOY VERSION", "NOTES"},
Headers: []string{
"MESH",
"NAME",
"TAGS",
"STATUS",
"LAST CONNECTED AGO",
"LAST UPDATED AGO",
"TOTAL UPDATES",
"TOTAL ERRORS",
"CERT REGENERATED AGO",
"CERT EXPIRATION",
"CERT REGENERATIONS",
"CERT BACKEND",
"SUPPORTED CERT BACKENDS",
"KUMA-DP VERSION",
"ENVOY VERSION",
"NOTES",
},
NextRow: func() func() []string {
i := 0
return func() []string {
Expand Down Expand Up @@ -97,6 +114,13 @@ func printDataplaneOverviews(now time.Time, dataplaneOverviews *core_mesh.Datapl
}
dataplaneInsight.GetMTLS().GetCertificateExpirationTime()
certRegenerations := strconv.Itoa(int(dataplaneInsight.GetMTLS().GetCertificateRegenerations()))
certBackend := dataplaneInsight.GetMTLS().GetIssuedBackend()
if dataplaneInsight.GetMTLS() == nil {
certBackend = "-"
} else if dataplaneInsight.GetMTLS().GetIssuedBackend() == "" {
certBackend = "unknown" // backwards compatibility with Kuma 1.2.x
}
supportedBackend := strings.Join(dataplaneInsight.GetMTLS().GetSupportedBackends(), ",")

var kumaDpVersion string
var envoyVersion string
Expand All @@ -121,6 +145,8 @@ func printDataplaneOverviews(now time.Time, dataplaneOverviews *core_mesh.Datapl
table.Ago(lastCertGeneration, now), // CERT REGENERATED AGO
table.Date(certExpiration), // CERT EXPIRATION
certRegenerations, // CERT REGENERATIONS
certBackend, // CERT BACKEND
supportedBackend, // SUPPORTED CERT BACKENDS
kumaDpVersion, // KUMA-DP VERSION
envoyVersion, // ENVOY VERSION
strings.Join(errs, ";"), // NOTES
Expand Down
11 changes: 4 additions & 7 deletions app/kumactl/cmd/inspect/inspect_dataplanes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package inspect_test
import (
"bytes"
"context"
"io/ioutil"
"path/filepath"
"strings"
"time"
Expand All @@ -22,6 +21,7 @@ import (
core_mesh "github.com/kumahq/kuma/pkg/core/resources/apis/mesh"
"github.com/kumahq/kuma/pkg/core/resources/model"
test_kumactl "github.com/kumahq/kuma/pkg/test/kumactl"
"github.com/kumahq/kuma/pkg/test/matchers"
test_model "github.com/kumahq/kuma/pkg/test/resources/model"
util_proto "github.com/kumahq/kuma/pkg/util/proto"
)
Expand Down Expand Up @@ -239,6 +239,8 @@ var _ = Describe("kumactl inspect dataplanes", func() {
Seconds: 1563306488,
},
CertificateRegenerations: 10,
IssuedBackend: "ca-1",
SupportedBackends: []string{"ca-1", "ca-2"},
},
},
},
Expand Down Expand Up @@ -427,15 +429,10 @@ var _ = Describe("kumactl inspect dataplanes", func() {

// when
err := rootCmd.Execute()
// then
Expect(err).ToNot(HaveOccurred())

// when
expected, err := ioutil.ReadFile(filepath.Join("testdata", given.goldenFile))
// then
Expect(err).ToNot(HaveOccurred())
// and
Expect(buf.String()).To(given.matcher(expected))
Expect(buf.String()).To(matchers.MatchGoldenEqual(filepath.Join("testdata", given.goldenFile)))
},
Entry("should support Table output by default", testCase{
outputFormat: "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,12 @@
"mTLS": {
"certificateExpirationTime": "2020-05-08T08:28:22Z",
"lastCertificateRegeneration": "2019-07-16T19:48:08Z",
"certificateRegenerations": 10
"certificateRegenerations": 10,
"issuedBackend": "ca-1",
"supportedBackends": [
"ca-1",
"ca-2"
]
}
}
},
Expand Down
10 changes: 5 additions & 5 deletions app/kumactl/cmd/inspect/testdata/inspect-dataplanes.golden.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
MESH NAME TAGS STATUS LAST CONNECTED AGO LAST UPDATED AGO TOTAL UPDATES TOTAL ERRORS CERT REGENERATED AGO CERT EXPIRATION CERT REGENERATIONS KUMA-DP VERSION ENVOY VERSION NOTES
default experiment kuma.io/service=metrics,mobile version=v1 Online 2h never 30 3 22h 2020-05-08 08:28:22 10 1.0.2 1.16.1
default degraded-dp kuma.io/service=example Partially degraded 2h never 30 3 22h 2020-05-08 08:28:22 10 1.0.2 1.16.1 inbound[port=9001,svc=example] is not ready
default offline-dp kuma.io/service=example Offline 2h never 30 3 22h 2020-05-08 08:28:22 10 1.0.2 1.16.1 inbound[port=8080,svc=example] is not ready;inbound[port=9001,svc=example] is not ready
default example kuma.io/service=example Offline never never 0 0 never - 0
MESH NAME TAGS STATUS LAST CONNECTED AGO LAST UPDATED AGO TOTAL UPDATES TOTAL ERRORS CERT REGENERATED AGO CERT EXPIRATION CERT REGENERATIONS CERT BACKEND SUPPORTED CERT BACKENDS KUMA-DP VERSION ENVOY VERSION NOTES
default experiment kuma.io/service=metrics,mobile version=v1 Online 2h never 30 3 22h 2020-05-08 08:28:22 10 unknown 1.0.2 1.16.1
default degraded-dp kuma.io/service=example Partially degraded 2h never 30 3 22h 2020-05-08 08:28:22 10 ca-1 ca-1,ca-2 1.0.2 1.16.1 inbound[port=9001,svc=example] is not ready
default offline-dp kuma.io/service=example Offline 2h never 30 3 22h 2020-05-08 08:28:22 10 unknown 1.0.2 1.16.1 inbound[port=8080,svc=example] is not ready;inbound[port=9001,svc=example] is not ready
default example kuma.io/service=example Offline never never 0 0 never - 0 -
Loading