Skip to content

Commit 9de5cb8

Browse files
committed
reduced noise from telemetry runs
1 parent 70556da commit 9de5cb8

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"log"
88
"os"
9+
"time"
910

1011
"github.com/Azure/azure-container-networking/npm/metrics"
1112
"github.com/olekukonko/tablewriter"
@@ -90,11 +91,8 @@ func main() {
9091
}
9192
}
9293

93-
// Start sending metrics
94-
klog.Infof("initializing metrics")
95-
metrics.InitializeAll()
96-
9794
// Create telemetry handle
95+
// Note: npmVersionNum and imageVersion telemetry is not needed for this tool so they are set to abitrary values
9896
err = metrics.CreateTelemetryHandle(0, "", "014c22bd-4107-459e-8475-67909e96edcb")
9997

10098
if err != nil {
@@ -116,31 +114,32 @@ func printMigrationSummary(
116114
ingressEndportNetworkPolicy, egressEndportNetworkPolicy := getEndportNetworkPolicies(policiesByNamespace)
117115

118116
// Send endPort telemetry
119-
metrics.SendLog(0, fmt.Sprintf("Found %d network policies with endPort", len(ingressEndportNetworkPolicy)+len(egressEndportNetworkPolicy)), metrics.DonotPrint)
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)
120119

121120
// Get the network policies with cidr
122121
ingressPoliciesWithCIDR, egressPoliciesWithCIDR := getCIDRNetworkPolicies(policiesByNamespace)
123122

124123
// Send cidr telemetry
125-
metrics.SendLog(0, fmt.Sprintf("Found %d network policies with CIDR", len(ingressPoliciesWithCIDR)+len(egressPoliciesWithCIDR)), metrics.DonotPrint)
124+
metrics.SendLog(10000, fmt.Sprintf("Found %d network policies with CIDR", len(ingressPoliciesWithCIDR)+len(egressPoliciesWithCIDR)), metrics.DonotPrint)
126125

127126
// Get the named port
128127
ingressPoliciesWithNamedPort, egressPoliciesWithNamedPort := getNamedPortPolicies(policiesByNamespace)
129128

130129
// Send named port telemetry
131-
metrics.SendLog(0, fmt.Sprintf("Found %d network policies with named port", len(ingressPoliciesWithNamedPort)+len(egressPoliciesWithNamedPort)), metrics.DonotPrint)
130+
metrics.SendLog(10000, fmt.Sprintf("Found %d network policies with named port", len(ingressPoliciesWithNamedPort)+len(egressPoliciesWithNamedPort)), metrics.DonotPrint)
132131

133132
// Get the network policies with egress (except not egress allow all)
134133
egressPolicies := getEgressPolicies(policiesByNamespace)
135134

136135
// Send egress telemetry
137-
metrics.SendLog(0, fmt.Sprintf("Found %d network policies with egress", len(egressPolicies)), metrics.DonotPrint)
136+
metrics.SendLog(10000, fmt.Sprintf("Found %d network policies with egress", len(egressPolicies)), metrics.DonotPrint)
138137

139138
// Get services that have externalTrafficPolicy!=Local that are unsafe (might have traffic disruption)
140139
unsafeServices := getUnsafeExternalTrafficPolicyClusterServices(namespaces, servicesByNamespace, policiesByNamespace)
141140

142141
// Send unsafe services telemetry
143-
metrics.SendLog(0, fmt.Sprintf("Found %d services with externalTrafficPolicy=Cluster", len(unsafeServices)), metrics.DonotPrint)
142+
metrics.SendLog(10000, fmt.Sprintf("Found %d services with externalTrafficPolicy=Cluster", len(unsafeServices)), metrics.DonotPrint)
144143

145144
unsafeNetworkPolicesInCluster := false
146145
unsafeServicesInCluster := false
@@ -156,14 +155,15 @@ func printMigrationSummary(
156155

157156
if unsafeNetworkPolicesInCluster || unsafeServicesInCluster {
158157
// Send cluster unsafe telemetry
159-
metrics.SendLog(0, "Fails some checks. Unsafe to migrate this cluster", metrics.DonotPrint)
158+
metrics.SendLog(10000, "Fails some checks. Unsafe to migrate this cluster", metrics.DonotPrint)
160159
} else {
161160
// Send cluster safe telemetry
162-
metrics.SendLog(0, "Passes all checks. Safe to migrate this cluster", metrics.DonotPrint)
161+
metrics.SendLog(10000, "Passes all checks. Safe to migrate this cluster", metrics.DonotPrint)
163162
}
164163

165-
// Close the metrics before table is rendered to prevent formatting issues
164+
// Close the metrics before table is rendered and wait one second to prevent formatting issues
166165
metrics.Close()
166+
time.Sleep(time.Second)
167167

168168
// Print the migration summary table
169169
renderMigrationSummaryTable(ingressEndportNetworkPolicy, egressEndportNetworkPolicy, ingressPoliciesWithCIDR, egressPoliciesWithCIDR, ingressPoliciesWithNamedPort, egressPoliciesWithNamedPort, egressPolicies, unsafeServices)

0 commit comments

Comments
 (0)