@@ -43,6 +43,7 @@ import (
4343 "github.com/apache/apisix-ingress-controller/internal/provider/adc/translator"
4444 "github.com/apache/apisix-ingress-controller/internal/types"
4545 "github.com/apache/apisix-ingress-controller/internal/utils"
46+ pkgmetrics "github.com/apache/apisix-ingress-controller/pkg/metrics"
4647)
4748
4849type adcConfig struct {
@@ -389,6 +390,8 @@ func (d *adcClient) sync(ctx context.Context, task Task) error {
389390 return nil
390391 }
391392
393+ var errs types.ADCExecutionErrors
394+
392395 // for global rules, we need to list all global rules and set it to the task resources
393396 if slices .Contains (task .ResourceTypes , "global_rule" ) {
394397 for _ , config := range task .configs {
@@ -410,42 +413,90 @@ func (d *adcClient) sync(ctx context.Context, task Task) error {
410413 task .Resources .GlobalRules = globalrule
411414 log .Debugw ("syncing resources global rules" , zap .Any ("globalRules" , task .Resources .GlobalRules ))
412415
416+ fileIOStart := time .Now ()
413417 syncFilePath , cleanup , err := prepareSyncFile (task .Resources )
414418 if err != nil {
419+ pkgmetrics .RecordFileIODuration ("prepare_sync_file" , "failure" , time .Since (fileIOStart ).Seconds ())
415420 return err
416421 }
422+ pkgmetrics .RecordFileIODuration ("prepare_sync_file" , "success" , time .Since (fileIOStart ).Seconds ())
417423 defer cleanup ()
418424
419425 args := BuildADCExecuteArgs (syncFilePath , task .Labels , task .ResourceTypes )
420426
421- if err := d .executor .Execute (ctx , d .BackendMode , config , args ); err != nil {
427+ // Record sync duration for each config
428+ startTime := time .Now ()
429+ resourceType := strings .Join (task .ResourceTypes , "," )
430+ if resourceType == "" {
431+ resourceType = "all"
432+ }
433+
434+ err = d .executor .Execute (ctx , d .BackendMode , config , args )
435+ duration := time .Since (startTime ).Seconds ()
436+
437+ status := "success"
438+ if err != nil {
439+ status = "failure"
422440 log .Errorw ("failed to execute adc command" , zap .Error (err ), zap .Any ("config" , config ))
423- return err
441+
442+ var execErr types.ADCExecutionError
443+ if errors .As (err , & execErr ) {
444+ errs .Errors = append (errs .Errors , execErr )
445+ pkgmetrics .RecordExecutionError (config .Name , execErr .Name )
446+ } else {
447+ pkgmetrics .RecordExecutionError (config .Name , "unknown" )
448+ }
424449 }
450+
451+ // Record metrics
452+ pkgmetrics .RecordSyncDuration (config .Name , resourceType , status , duration )
425453 }
426454
427455 return nil
428456 }
429457
458+ // Record file I/O duration
459+ fileIOStart := time .Now ()
430460 // every task resources is the same, so we can use the first config to prepare the sync file
431461 syncFilePath , cleanup , err := prepareSyncFile (task .Resources )
432462 if err != nil {
463+ pkgmetrics .RecordFileIODuration ("prepare_sync_file" , "failure" , time .Since (fileIOStart ).Seconds ())
433464 return err
434465 }
466+ pkgmetrics .RecordFileIODuration ("prepare_sync_file" , "success" , time .Since (fileIOStart ).Seconds ())
435467 defer cleanup ()
436468
437469 args := BuildADCExecuteArgs (syncFilePath , task .Labels , task .ResourceTypes )
438470
439- var errs types.ADCExecutionErrors
440471 for _ , config := range task .configs {
441- if err := d .executor .Execute (ctx , d .BackendMode , config , args ); err != nil {
472+ // Record sync duration for each config
473+ startTime := time .Now ()
474+ resourceType := strings .Join (task .ResourceTypes , "," )
475+ if resourceType == "" {
476+ resourceType = "all"
477+ }
478+
479+ err := d .executor .Execute (ctx , d .BackendMode , config , args )
480+ duration := time .Since (startTime ).Seconds ()
481+
482+ status := "success"
483+ if err != nil {
484+ status = "failure"
442485 log .Errorw ("failed to execute adc command" , zap .Error (err ), zap .Any ("config" , config ))
486+
443487 var execErr types.ADCExecutionError
444488 if errors .As (err , & execErr ) {
445489 errs .Errors = append (errs .Errors , execErr )
490+ pkgmetrics .RecordExecutionError (config .Name , execErr .Name )
491+ } else {
492+ pkgmetrics .RecordExecutionError (config .Name , "unknown" )
446493 }
447494 }
495+
496+ // Record metrics
497+ pkgmetrics .RecordSyncDuration (config .Name , resourceType , status , duration )
448498 }
499+
449500 if len (errs .Errors ) > 0 {
450501 return errs
451502 }
0 commit comments