@@ -11,6 +11,7 @@ import (
11
11
v1 "k8s.io/api/core/v1"
12
12
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
13
13
"k8s.io/apimachinery/pkg/types"
14
+ k8sversion "k8s.io/apimachinery/pkg/util/version"
14
15
"sigs.k8s.io/controller-runtime/pkg/client"
15
16
16
17
"github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/config"
@@ -100,14 +101,11 @@ func NewDataCollectorImpl(
100
101
}
101
102
}
102
103
103
- // notImplemented is a value for string field, for which collection is not implemented yet.
104
- const notImplemented = "not-implemented"
105
-
106
104
// Collect collects and returns telemetry Data.
107
105
func (c DataCollectorImpl ) Collect (ctx context.Context ) (Data , error ) {
108
- nodeCount , err := CollectNodeCount (ctx , c .cfg .K8sClientReader )
106
+ clusterInfo , err := collectClusterInformation (ctx , c .cfg .K8sClientReader )
109
107
if err != nil {
110
- return Data {}, fmt .Errorf ("failed to collect node count : %w" , err )
108
+ return Data {}, fmt .Errorf ("failed to collect cluster information : %w" , err )
111
109
}
112
110
113
111
graphResourceCount , err := collectGraphResourceCount (c .cfg .GraphGetter , c .cfg .ConfigurationGetter )
@@ -130,21 +128,16 @@ func (c DataCollectorImpl) Collect(ctx context.Context) (Data, error) {
130
128
return Data {}, fmt .Errorf ("failed to get NGF deploymentID: %w" , err )
131
129
}
132
130
133
- var clusterID string
134
- if clusterID , err = CollectClusterID (ctx , c .cfg .K8sClientReader ); err != nil {
135
- return Data {}, fmt .Errorf ("failed to collect clusterID: %w" , err )
136
- }
137
-
138
131
data := Data {
139
132
Data : tel.Data {
140
133
ProjectName : "NGF" ,
141
134
ProjectVersion : c .cfg .Version ,
142
135
ProjectArchitecture : runtime .GOARCH ,
143
- ClusterID : clusterID ,
144
- ClusterVersion : notImplemented ,
145
- ClusterPlatform : notImplemented ,
136
+ ClusterID : clusterInfo . ClusterID ,
137
+ ClusterVersion : clusterInfo . Version ,
138
+ ClusterPlatform : clusterInfo . Platform ,
146
139
InstallationID : deploymentID ,
147
- ClusterNodeCount : int64 (nodeCount ),
140
+ ClusterNodeCount : int64 (clusterInfo . NodeCount ),
148
141
},
149
142
NGFResourceCounts : graphResourceCount ,
150
143
ImageSource : c .cfg .ImageSource ,
@@ -156,16 +149,6 @@ func (c DataCollectorImpl) Collect(ctx context.Context) (Data, error) {
156
149
return data , nil
157
150
}
158
151
159
- // CollectNodeCount returns the number of nodes in the cluster.
160
- func CollectNodeCount (ctx context.Context , k8sClient client.Reader ) (int , error ) {
161
- var nodes v1.NodeList
162
- if err := k8sClient .List (ctx , & nodes ); err != nil {
163
- return 0 , fmt .Errorf ("failed to get NodeList: %w" , err )
164
- }
165
-
166
- return len (nodes .Items ), nil
167
- }
168
-
169
152
func collectGraphResourceCount (
170
153
graphGetter GraphGetter ,
171
154
configurationGetter ConfigurationGetter ,
@@ -275,3 +258,51 @@ func CollectClusterID(ctx context.Context, k8sClient client.Reader) (string, err
275
258
}
276
259
return string (kubeNamespace .GetUID ()), nil
277
260
}
261
+
262
+ type clusterInformation struct {
263
+ Platform string
264
+ Version string
265
+ ClusterID string
266
+ NodeCount int
267
+ }
268
+
269
+ func collectClusterInformation (ctx context.Context , k8sClient client.Reader ) (clusterInformation , error ) {
270
+ var clusterInfo clusterInformation
271
+
272
+ var nodes v1.NodeList
273
+ if err := k8sClient .List (ctx , & nodes ); err != nil {
274
+ return clusterInformation {}, fmt .Errorf ("failed to get NodeList: %w" , err )
275
+ }
276
+
277
+ nodeCount := len (nodes .Items )
278
+ if nodeCount == 0 {
279
+ return clusterInformation {}, errors .New ("failed to collect cluster information: NodeList length is zero" )
280
+ }
281
+ clusterInfo .NodeCount = nodeCount
282
+
283
+ node := nodes .Items [0 ]
284
+
285
+ kubeletVersion := node .Status .NodeInfo .KubeletVersion
286
+ version , err := k8sversion .ParseGeneric (kubeletVersion )
287
+ if err != nil {
288
+ clusterInfo .Version = "unknown"
289
+ } else {
290
+ clusterInfo .Version = version .String ()
291
+ }
292
+
293
+ var namespaces v1.NamespaceList
294
+ if err = k8sClient .List (ctx , & namespaces ); err != nil {
295
+ return clusterInformation {}, fmt .Errorf ("failed to collect cluster information: %w" , err )
296
+ }
297
+
298
+ clusterInfo .Platform = getPlatform (node , namespaces )
299
+
300
+ var clusterID string
301
+ clusterID , err = CollectClusterID (ctx , k8sClient )
302
+ if err != nil {
303
+ return clusterInformation {}, fmt .Errorf ("failed to collect cluster information: %w" , err )
304
+ }
305
+ clusterInfo .ClusterID = clusterID
306
+
307
+ return clusterInfo , nil
308
+ }
0 commit comments