@@ -133,12 +133,17 @@ func NewDataCollectorImpl(
133
133
134
134
// Collect collects and returns telemetry Data.
135
135
func (c DataCollectorImpl ) Collect (ctx context.Context ) (Data , error ) {
136
+ g := c .cfg .GraphGetter .GetLatestGraph ()
137
+ if g == nil {
138
+ return Data {}, errors .New ("failed to collect telemetry data: latest graph cannot be nil" )
139
+ }
140
+
136
141
clusterInfo , err := collectClusterInformation (ctx , c .cfg .K8sClientReader )
137
142
if err != nil {
138
143
return Data {}, fmt .Errorf ("failed to collect cluster information: %w" , err )
139
144
}
140
145
141
- graphResourceCount , err := collectGraphResourceCount (c . cfg . GraphGetter , c .cfg .ConfigurationGetter )
146
+ graphResourceCount , err := collectGraphResourceCount (g , c .cfg .ConfigurationGetter )
142
147
if err != nil {
143
148
return Data {}, fmt .Errorf ("failed to collect NGF resource counts: %w" , err )
144
149
}
@@ -158,12 +163,7 @@ func (c DataCollectorImpl) Collect(ctx context.Context) (Data, error) {
158
163
return Data {}, fmt .Errorf ("failed to get NGF deploymentID: %w" , err )
159
164
}
160
165
161
- snippetsFiltersDirectiveContexts ,
162
- snippetsFiltersDirectiveContextsCount ,
163
- err := collectSnippetsFilterSnippetsInfo (c .cfg .GraphGetter )
164
- if err != nil {
165
- return Data {}, fmt .Errorf ("failed to collect snippet filter directive info: %w" , err )
166
- }
166
+ snippetsFiltersDirectiveContexts , snippetsFiltersDirectiveContextsCount := collectSnippetsFilterSnippetsInfo (g )
167
167
168
168
data := Data {
169
169
Data : tel.Data {
@@ -190,16 +190,12 @@ func (c DataCollectorImpl) Collect(ctx context.Context) (Data, error) {
190
190
}
191
191
192
192
func collectGraphResourceCount (
193
- graphGetter GraphGetter ,
193
+ g * graph. Graph ,
194
194
configurationGetter ConfigurationGetter ,
195
195
) (NGFResourceCounts , error ) {
196
196
ngfResourceCounts := NGFResourceCounts {}
197
- g := graphGetter .GetLatestGraph ()
198
197
cfg := configurationGetter .GetLatestConfiguration ()
199
198
200
- if g == nil {
201
- return ngfResourceCounts , errors .New ("latest graph cannot be nil" )
202
- }
203
199
if cfg == nil {
204
200
return ngfResourceCounts , errors .New ("latest configuration cannot be nil" )
205
201
}
@@ -406,16 +402,11 @@ func collectClusterInformation(ctx context.Context, k8sClient client.Reader) (cl
406
402
}
407
403
408
404
type sfDirectiveContext struct {
409
- context string
410
405
directive string
406
+ context string
411
407
}
412
408
413
- func collectSnippetsFilterSnippetsInfo (graphGetter GraphGetter ) ([]string , []int64 , error ) {
414
- g := graphGetter .GetLatestGraph ()
415
- if g == nil {
416
- return nil , nil , errors .New ("latest graph cannot be nil" )
417
- }
418
-
409
+ func collectSnippetsFilterSnippetsInfo (g * graph.Graph ) ([]string , []int64 ) {
419
410
directiveContextMap := make (map [sfDirectiveContext ]int )
420
411
421
412
for _ , sf := range g .SnippetsFilters {
@@ -442,17 +433,15 @@ func collectSnippetsFilterSnippetsInfo(graphGetter GraphGetter) ([]string, []int
442
433
directives := parseSnippetValueIntoDirectives (snippetValue )
443
434
for _ , directive := range directives {
444
435
directiveContext := sfDirectiveContext {
445
- context : parsedContext ,
446
436
directive : directive ,
437
+ context : parsedContext ,
447
438
}
448
439
directiveContextMap [directiveContext ]++
449
440
}
450
441
}
451
442
}
452
443
453
- directiveContextList , countList := parseDirectiveContextMapIntoLists (directiveContextMap )
454
-
455
- return directiveContextList , countList , nil
444
+ return parseDirectiveContextMapIntoLists (directiveContextMap )
456
445
}
457
446
458
447
func parseSnippetValueIntoDirectives (snippetValue string ) []string {
0 commit comments