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(*) aggregate dp stats by type in MeshInsight #2999

Merged
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
329 changes: 213 additions & 116 deletions api/mesh/v1alpha1/mesh_insight.pb.go

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions api/mesh/v1alpha1/mesh_insight.proto
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,11 @@ message MeshInsight {
uint32 external = 3;
}
ServiceStat services = 6;

// DataplanesByType defines statistics splitted by dataplane types
message DataplanesByType {
DataplaneStat standard = 1;
DataplaneStat gateway = 2;
}
DataplanesByType dataplanesByType = 7;
}
Original file line number Diff line number Diff line change
Expand Up @@ -735,4 +735,4 @@ spec:
timeoutSeconds: 1
imagePullSecrets:
- name: kong-enterprise-edition-docker
serviceAccountName: kong-serviceaccount
serviceAccountName: kong-serviceaccount
Original file line number Diff line number Diff line change
Expand Up @@ -735,4 +735,4 @@ spec:
timeoutSeconds: 1
imagePullSecrets:
- name: kong-enterprise-edition-docker
serviceAccountName: kong-serviceaccount
serviceAccountName: kong-serviceaccount
Original file line number Diff line number Diff line change
Expand Up @@ -718,4 +718,4 @@ spec:
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 1
serviceAccountName: kong-serviceaccount
serviceAccountName: kong-serviceaccount
Original file line number Diff line number Diff line change
Expand Up @@ -718,4 +718,4 @@ spec:
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 1
serviceAccountName: kong-serviceaccount
serviceAccountName: kong-serviceaccount
Original file line number Diff line number Diff line change
Expand Up @@ -1006,4 +1006,4 @@ spec:
name: prometheus-alertmanager
- name: storage-volume
persistentVolumeClaim:
claimName: prometheus-alertmanager
claimName: prometheus-alertmanager
20 changes: 17 additions & 3 deletions pkg/insights/resyncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,11 @@ func (r *resyncer) createOrUpdateMeshInsight(mesh string) error {

insight := &mesh_proto.MeshInsight{
Dataplanes: &mesh_proto.MeshInsight_DataplaneStat{},
Policies: map[string]*mesh_proto.MeshInsight_PolicyStat{},
DataplanesByType: &mesh_proto.MeshInsight_DataplanesByType{
Standard: &mesh_proto.MeshInsight_DataplaneStat{},
Gateway: &mesh_proto.MeshInsight_DataplaneStat{},
},
Policies: map[string]*mesh_proto.MeshInsight_PolicyStat{},
DpVersions: &mesh_proto.MeshInsight_DpVersions{
KumaDp: map[string]*mesh_proto.MeshInsight_DataplaneStat{},
Envoy: map[string]*mesh_proto.MeshInsight_DataplaneStat{},
Expand Down Expand Up @@ -313,22 +317,34 @@ func (r *resyncer) createOrUpdateMeshInsight(mesh string) error {
dpSubscription, _ := dpInsight.GetLatestSubscription()
kumaDpVersion := getOrDefault(dpSubscription.GetVersion().GetKumaDp().GetVersion())
envoyVersion := getOrDefault(dpSubscription.GetVersion().GetEnvoy().GetVersion())
networking := dpOverview.Spec.GetDataplane().GetNetworking()

ensureVersionExists(kumaDpVersion, insight.DpVersions.KumaDp)
ensureVersionExists(envoyVersion, insight.DpVersions.Envoy)

status, _ := dpOverview.GetStatus()

statByType := insight.GetDataplanesByType().GetStandard()
if networking.GetGateway() != nil {
statByType = insight.GetDataplanesByType().GetGateway()
}

statByType.Total++

switch status {
case core_mesh.Online:
insight.Dataplanes.Online++
statByType.Online++
insight.DpVersions.KumaDp[kumaDpVersion].Online++
insight.DpVersions.Envoy[envoyVersion].Online++
case core_mesh.PartiallyDegraded:
insight.Dataplanes.PartiallyDegraded++
statByType.PartiallyDegraded++
insight.DpVersions.KumaDp[kumaDpVersion].PartiallyDegraded++
insight.DpVersions.Envoy[envoyVersion].PartiallyDegraded++
case core_mesh.Offline:
insight.Dataplanes.Offline++
statByType.Offline++
insight.DpVersions.KumaDp[kumaDpVersion].Offline++
insight.DpVersions.Envoy[envoyVersion].Offline++
}
Expand All @@ -337,8 +353,6 @@ func (r *resyncer) createOrUpdateMeshInsight(mesh string) error {
updateTotal(envoyVersion, insight.DpVersions.Envoy)
updateMTLS(dpInsight.GetMTLS(), status, insight.MTLS)

networking := dpOverview.Spec.GetDataplane().GetNetworking()

if svc := networking.GetGateway().GetTags()[mesh_proto.ServiceTag]; svc != "" {
internalServices[svc] = struct{}{}
}
Expand Down
84 changes: 84 additions & 0 deletions pkg/insights/resyncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,90 @@ var _ = Describe("Insight Persistence", func() {
Expect(envoy["1.15.0"].Offline).To(Equal(uint32(2)))
})

It("should count dataplanes by type", func() {
// setup
err := rm.Create(context.Background(), core_mesh.NewMeshResource(), store.CreateByKey("mesh-1", model.NoMesh))
Expect(err).ToNot(HaveOccurred())

err = rm.Create(context.Background(), &core_mesh.DataplaneResource{Spec: samples.Dataplane}, store.CreateByKey("dp1", "mesh-1"))
Expect(err).ToNot(HaveOccurred())

dp1 := core_mesh.NewDataplaneInsightResource()
dp1.Spec.Subscriptions = append(dp1.Spec.Subscriptions, &mesh_proto.DiscoverySubscription{
Id: strconv.Itoa(1),
})
err = rm.Create(context.Background(), dp1, store.CreateByKey("dp1", "mesh-1"))
Expect(err).ToNot(HaveOccurred())

err = rm.Create(context.Background(), &core_mesh.DataplaneResource{Spec: samples.Dataplane}, store.CreateByKey("dp2", "mesh-1"))
Expect(err).ToNot(HaveOccurred())

dp2 := core_mesh.NewDataplaneInsightResource()
dp2.Spec.Subscriptions = append(dp2.Spec.Subscriptions, &mesh_proto.DiscoverySubscription{
Id: strconv.Itoa(2),
ConnectTime: &timestamppb.Timestamp{
Seconds: 100,
Nanos: 200,
},
DisconnectTime: &timestamppb.Timestamp{
Seconds: 101,
Nanos: 202,
},
})
err = rm.Create(context.Background(), dp2, store.CreateByKey("dp2", "mesh-1"))
Expect(err).ToNot(HaveOccurred())

err = rm.Create(context.Background(), &core_mesh.DataplaneResource{Spec: samples.Dataplane}, store.CreateByKey("dp3", "mesh-1"))
Expect(err).ToNot(HaveOccurred())

dp3 := core_mesh.NewDataplaneInsightResource()
dp3.Spec.Subscriptions = append(dp3.Spec.Subscriptions, &mesh_proto.DiscoverySubscription{
Id: strconv.Itoa(3),
ConnectTime: &timestamppb.Timestamp{
Seconds: 100,
Nanos: 200,
},
})
err = rm.Create(context.Background(), dp3, store.CreateByKey("dp3", "mesh-1"))
Expect(err).ToNot(HaveOccurred())

err = rm.Create(context.Background(), &core_mesh.DataplaneResource{Spec: samples.GatewayDataplane}, store.CreateByKey("dp4", "mesh-1"))
Expect(err).ToNot(HaveOccurred())

dp4 := core_mesh.NewDataplaneInsightResource()
dp4.Spec.Subscriptions = append(dp4.Spec.Subscriptions, &mesh_proto.DiscoverySubscription{
Id: strconv.Itoa(4),
ConnectTime: &timestamppb.Timestamp{
Seconds: 100,
Nanos: 200,
},
})
err = rm.Create(context.Background(), dp4, store.CreateByKey("dp4", "mesh-1"))
Expect(err).ToNot(HaveOccurred())

nowMtx.Lock()
now = now.Add(60 * time.Second)
nowMtx.Unlock()
tickCh <- now

// when
meshInsight := core_mesh.NewMeshInsightResource()
Eventually(func() error {
return rm.Get(context.Background(), meshInsight, store.GetByKey("mesh-1", model.NoMesh))
}, "10s", "100ms").Should(BeNil())

// then
standardDP := meshInsight.Spec.GetDataplanesByType().GetStandard()
Expect(standardDP.GetTotal()).To(Equal(uint32(3)))
Expect(standardDP.GetOnline()).To(Equal(uint32(1)))
Expect(standardDP.GetOffline()).To(Equal(uint32(2)))

gatewayDP := meshInsight.Spec.GetDataplanesByType().GetGateway()
Expect(gatewayDP.GetTotal()).To(Equal(uint32(1)))
Expect(gatewayDP.GetOffline()).To(Equal(uint32(0)))
Expect(gatewayDP.GetOnline()).To(Equal(uint32(1)))
})

It("should count dataplanes by mTLS backends", func() {
// given mesh
err := rm.Create(context.Background(), core_mesh.NewMeshResource(), store.CreateByKey("mesh-1", model.NoMesh))
Expand Down
20 changes: 20 additions & 0 deletions pkg/test/kds/samples/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,26 @@ var (
},
},
}
GatewayDataplane = &mesh_proto.Dataplane{
Networking: &mesh_proto.Dataplane_Networking{
Gateway: &mesh_proto.Dataplane_Networking_Gateway{
Tags: map[string]string{
mesh_proto.ServiceTag: "gateway",
},
Type: mesh_proto.Dataplane_Networking_Gateway_DELEGATED,
},
Address: "192.168.0.1",
Outbound: []*mesh_proto.Dataplane_Networking_Outbound{
{
Port: 1213,
Tags: map[string]string{
mesh_proto.ServiceTag: "web",
mesh_proto.ProtocolTag: "http",
},
},
},
},
}
DataplaneInsight = &mesh_proto.DataplaneInsight{
MTLS: &mesh_proto.DataplaneInsight_MTLS{
CertificateRegenerations: 3,
Expand Down