Skip to content

Commit 921c11c

Browse files
authored
feat: add metrics for count of known NNC and NCs (#3389)
Signed-off-by: Evan Baker <[email protected]>
1 parent 79048a2 commit 921c11c

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

cns/kubecontroller/nodenetworkconfig/metrics.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,26 @@ var (
2424
Help: "Unused IP count.",
2525
},
2626
)
27+
hasNNC = prometheus.NewGauge(
28+
prometheus.GaugeOpts{
29+
Name: "nnc_has_nodenetworkconfig",
30+
Help: "Has received a NodeNetworkConfig",
31+
},
32+
)
33+
ncs = prometheus.NewGauge(
34+
prometheus.GaugeOpts{
35+
Name: "nnc_ncs",
36+
Help: "Network Container count in the NodeNetworkConfig",
37+
},
38+
)
2739
)
2840

2941
func init() {
3042
metrics.Registry.MustRegister(
3143
allocatedIPs,
3244
requestedIPs,
3345
unusedIPs,
46+
hasNNC,
47+
ncs,
3448
)
3549
}

cns/kubecontroller/nodenetworkconfig/reconciler.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,24 @@ func (r *Reconciler) Reconcile(ctx context.Context, req reconcile.Request) (reco
6464
nnc, err := r.nnccli.Get(ctx, req.NamespacedName)
6565
if err != nil {
6666
if apierrors.IsNotFound(err) {
67+
hasNNC.Set(0)
6768
logger.Printf("[cns-rc] CRD not found, ignoring %v", err)
6869
return reconcile.Result{}, errors.Wrapf(client.IgnoreNotFound(err), "NodeNetworkConfig %v not found", req.NamespacedName)
6970
}
7071
logger.Errorf("[cns-rc] Error retrieving CRD from cache : %v", err)
7172
return reconcile.Result{}, errors.Wrapf(err, "failed to get NodeNetworkConfig %v", req.NamespacedName)
7273
}
73-
74+
hasNNC.Set(1)
7475
logger.Printf("[cns-rc] CRD Spec: %+v", nnc.Spec)
7576

7677
ipAssignments := 0
7778

7879
// during node upgrades, an nnc may be updated with new ncs. at any given time, only the ncs
7980
// that exist in the nnc are valid. any others that may have been previously created and no
8081
// longer exist in the nnc should be considered stale.
81-
validNCIDs := make([]string, len(nnc.Status.NetworkContainers))
82+
ncCount := len(nnc.Status.NetworkContainers)
83+
ncs.Set(float64(ncCount))
84+
validNCIDs := make([]string, ncCount)
8285
for i := range nnc.Status.NetworkContainers {
8386
validNCIDs[i] = nnc.Status.NetworkContainers[i].ID
8487
}

cns/restserver/internalapi.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ func (service *HTTPRestService) syncHostNCVersion(ctx context.Context, channelMo
225225
for _, nc := range ncVersionListResp.Containers {
226226
nmaNCs[strings.ToLower(nc.NetworkContainerID)] = nc.Version
227227
}
228+
hasNC.Set(float64(len(nmaNCs)))
228229
for ncID := range outdatedNCs {
229230
nmaNCVersionStr, ok := nmaNCs[ncID]
230231
if !ok {

cns/restserver/metrics.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ var (
6565
},
6666
[]string{"ok"},
6767
)
68+
hasNC = prometheus.NewGauge(
69+
prometheus.GaugeOpts{
70+
Name: "has_networkcontainer",
71+
Help: "Number of Network Containers retrieved from NMA",
72+
},
73+
)
6874
allocatedIPCount = prometheus.NewGaugeVec(
6975
prometheus.GaugeOpts{
7076
Name: "cx_allocated_ips_v2",
@@ -114,6 +120,7 @@ func init() {
114120
ipConfigStatusStateTransitionTime,
115121
syncHostNCVersionCount,
116122
syncHostNCVersionLatency,
123+
hasNC,
117124
allocatedIPCount,
118125
assignedIPCount,
119126
availableIPCount,

0 commit comments

Comments
 (0)