Skip to content

Commit 3ee497b

Browse files
committed
added a const and prefix to metrics
1 parent c244424 commit 3ee497b

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

tools/azure-npm-to-cilium-validator/azure-npm-to-cilium-validator.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ import (
1919
"k8s.io/klog/v2"
2020
)
2121

22+
// Note: The operationID is set to a high number so it doesn't conflict with other telemetry
23+
const scriptMetricOperationID = 10000
24+
2225
// Use this tool to validate if your cluster is ready to migrate from Azure Network Policy Manager (NPM) to Cilium.
2326
func main() {
2427
// Parse the kubeconfig flag
@@ -114,32 +117,31 @@ func printMigrationSummary(
114117
ingressEndportNetworkPolicy, egressEndportNetworkPolicy := getEndportNetworkPolicies(policiesByNamespace)
115118

116119
// Send endPort telemetry
117-
// Note: The operationID is set to a high number so it doesn't conflict with other telemetry
118-
metrics.SendLog(10000, fmt.Sprintf("Found %d network policies with endPort", len(ingressEndportNetworkPolicy)+len(egressEndportNetworkPolicy)), metrics.DonotPrint)
120+
metrics.SendLog(scriptMetricOperationID, fmt.Sprintf("[migration script] Found %d network policies with endPort", len(ingressEndportNetworkPolicy)+len(egressEndportNetworkPolicy)), metrics.DonotPrint)
119121

120122
// Get the network policies with cidr
121123
ingressPoliciesWithCIDR, egressPoliciesWithCIDR := getCIDRNetworkPolicies(policiesByNamespace)
122124

123125
// Send cidr telemetry
124-
metrics.SendLog(10000, fmt.Sprintf("Found %d network policies with CIDR", len(ingressPoliciesWithCIDR)+len(egressPoliciesWithCIDR)), metrics.DonotPrint)
126+
metrics.SendLog(scriptMetricOperationID, fmt.Sprintf("[migration script] Found %d network policies with CIDR", len(ingressPoliciesWithCIDR)+len(egressPoliciesWithCIDR)), metrics.DonotPrint)
125127

126128
// Get the named port
127129
ingressPoliciesWithNamedPort, egressPoliciesWithNamedPort := getNamedPortPolicies(policiesByNamespace)
128130

129131
// Send named port telemetry
130-
metrics.SendLog(10000, fmt.Sprintf("Found %d network policies with named port", len(ingressPoliciesWithNamedPort)+len(egressPoliciesWithNamedPort)), metrics.DonotPrint)
132+
metrics.SendLog(scriptMetricOperationID, fmt.Sprintf("[migration script] Found %d network policies with named port", len(ingressPoliciesWithNamedPort)+len(egressPoliciesWithNamedPort)), metrics.DonotPrint)
131133

132134
// Get the network policies with egress (except not egress allow all)
133135
egressPolicies := getEgressPolicies(policiesByNamespace)
134136

135137
// Send egress telemetry
136-
metrics.SendLog(10000, fmt.Sprintf("Found %d network policies with egress", len(egressPolicies)), metrics.DonotPrint)
138+
metrics.SendLog(scriptMetricOperationID, fmt.Sprintf("[migration script] Found %d network policies with egress", len(egressPolicies)), metrics.DonotPrint)
137139

138140
// Get services that have externalTrafficPolicy!=Local that are unsafe (might have traffic disruption)
139141
unsafeServices := getUnsafeExternalTrafficPolicyClusterServices(namespaces, servicesByNamespace, policiesByNamespace)
140142

141143
// Send unsafe services telemetry
142-
metrics.SendLog(10000, fmt.Sprintf("Found %d services with externalTrafficPolicy=Cluster", len(unsafeServices)), metrics.DonotPrint)
144+
metrics.SendLog(scriptMetricOperationID, fmt.Sprintf("[migration script] Found %d services with externalTrafficPolicy=Cluster", len(unsafeServices)), metrics.DonotPrint)
143145

144146
unsafeNetworkPolicesInCluster := false
145147
unsafeServicesInCluster := false
@@ -155,10 +157,10 @@ func printMigrationSummary(
155157

156158
if unsafeNetworkPolicesInCluster || unsafeServicesInCluster {
157159
// Send cluster unsafe telemetry
158-
metrics.SendLog(10000, "Fails some checks. Unsafe to migrate this cluster", metrics.DonotPrint)
160+
metrics.SendLog(scriptMetricOperationID, "[migration script] Fails some checks. Unsafe to migrate this cluster", metrics.DonotPrint)
159161
} else {
160162
// Send cluster safe telemetry
161-
metrics.SendLog(10000, "Passes all checks. Safe to migrate this cluster", metrics.DonotPrint)
163+
metrics.SendLog(scriptMetricOperationID, "[migration script] Passes all checks. Safe to migrate this cluster", metrics.DonotPrint)
162164
}
163165

164166
// Close the metrics before table is rendered and wait one second to prevent formatting issues

0 commit comments

Comments
 (0)