forked from nginx/nginx-gateway-fabric
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_test.go
116 lines (105 loc) · 3.87 KB
/
data_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package telemetry
import (
"testing"
tel "github.com./nginxinc/telemetry-exporter/pkg/telemetry"
. "github.com./onsi/gomega"
"go.opentelemetry.io/otel/attribute"
)
func TestDataAttributes(t *testing.T) {
data := Data{
ImageSource: "local",
Data: tel.Data{
ProjectName: "NGF",
ProjectVersion: "edge",
ProjectArchitecture: "arm64",
ClusterID: "1",
ClusterVersion: "1.23",
ClusterPlatform: "test",
InstallationID: "123",
ClusterNodeCount: 3,
},
FlagNames: []string{"test-flag"},
FlagValues: []string{"test-value"},
NGFResourceCounts: NGFResourceCounts{
GatewayCount: 1,
GatewayClassCount: 2,
HTTPRouteCount: 3,
SecretCount: 4,
ServiceCount: 5,
EndpointCount: 6,
GRPCRouteCount: 7,
TLSRouteCount: 5,
BackendTLSPolicyCount: 8,
GatewayAttachedClientSettingsPolicyCount: 9,
RouteAttachedClientSettingsPolicyCount: 10,
ObservabilityPolicyCount: 11,
NginxProxyCount: 12,
},
NGFReplicaCount: 3,
}
expected := []attribute.KeyValue{
attribute.String("dataType", "ngf-product-telemetry"),
attribute.String("ImageSource", "local"),
attribute.String("ProjectName", "NGF"),
attribute.String("ProjectVersion", "edge"),
attribute.String("ProjectArchitecture", "arm64"),
attribute.String("ClusterID", "1"),
attribute.String("ClusterVersion", "1.23"),
attribute.String("ClusterPlatform", "test"),
attribute.String("InstallationID", "123"),
attribute.Int64("ClusterNodeCount", 3),
attribute.StringSlice("FlagNames", []string{"test-flag"}),
attribute.StringSlice("FlagValues", []string{"test-value"}),
attribute.Int64("GatewayCount", 1),
attribute.Int64("GatewayClassCount", 2),
attribute.Int64("HTTPRouteCount", 3),
attribute.Int64("TLSRouteCount", 5),
attribute.Int64("SecretCount", 4),
attribute.Int64("ServiceCount", 5),
attribute.Int64("EndpointCount", 6),
attribute.Int64("GRPCRouteCount", 7),
attribute.Int64("BackendTLSPolicyCount", 8),
attribute.Int64("GatewayAttachedClientSettingsPolicyCount", 9),
attribute.Int64("RouteAttachedClientSettingsPolicyCount", 10),
attribute.Int64("ObservabilityPolicyCount", 11),
attribute.Int64("NginxProxyCount", 12),
attribute.Int64("NGFReplicaCount", 3),
}
result := data.Attributes()
g := NewWithT(t)
g.Expect(result).To(Equal(expected))
}
func TestDataAttributesWithEmptyData(t *testing.T) {
data := Data{}
expected := []attribute.KeyValue{
attribute.String("dataType", "ngf-product-telemetry"),
attribute.String("ImageSource", ""),
attribute.String("ProjectName", ""),
attribute.String("ProjectVersion", ""),
attribute.String("ProjectArchitecture", ""),
attribute.String("ClusterID", ""),
attribute.String("ClusterVersion", ""),
attribute.String("ClusterPlatform", ""),
attribute.String("InstallationID", ""),
attribute.Int64("ClusterNodeCount", 0),
attribute.StringSlice("FlagNames", nil),
attribute.StringSlice("FlagValues", nil),
attribute.Int64("GatewayCount", 0),
attribute.Int64("GatewayClassCount", 0),
attribute.Int64("HTTPRouteCount", 0),
attribute.Int64("TLSRouteCount", 0),
attribute.Int64("SecretCount", 0),
attribute.Int64("ServiceCount", 0),
attribute.Int64("EndpointCount", 0),
attribute.Int64("GRPCRouteCount", 0),
attribute.Int64("BackendTLSPolicyCount", 0),
attribute.Int64("GatewayAttachedClientSettingsPolicyCount", 0),
attribute.Int64("RouteAttachedClientSettingsPolicyCount", 0),
attribute.Int64("ObservabilityPolicyCount", 0),
attribute.Int64("NginxProxyCount", 0),
attribute.Int64("NGFReplicaCount", 0),
}
result := data.Attributes()
g := NewWithT(t)
g.Expect(result).To(Equal(expected))
}