func()

in internal/daemon/mysql/mysql.go [61:117]


func (s *Service) Start(ctx context.Context, a any) {
	if s.Config.GetMysqlConfiguration() != nil && !s.Config.GetMysqlConfiguration().GetEnabled() {
		// If MySQL workload agent service is explicitly disabled in the configuration, then return.
		log.CtxLogger(ctx).Info("MySQL workload agent service is disabled in the configuration")
		return
	}

	go (func() {
		for {
			s.checkServiceCommunication(ctx)
		}
	})()
	ticker := time.NewTicker(5 * time.Second)
	defer ticker.Stop()
	enabled := s.Config.GetMysqlConfiguration().GetEnabled()
EnableCheck:
	for {
		select {
		case <-ctx.Done():
			log.CtxLogger(ctx).Info("MySQL workload agent service cancellation requested")
			return
		case <-ticker.C:
			// Once DW is enabled and the workload is present/enabled, start discovery and metric collection.
			if s.dwActivated && (s.isWorkloadPresent() || enabled) {
				log.CtxLogger(ctx).Info("MySQL workload agent service is enabled and DW is activated. Starting discovery and metric collection")
				break EnableCheck
			}
		}
	}

	// Start MySQL Discovery
	dCtx := log.SetCtx(ctx, "context", "MySQLDiscovery")
	discoveryRoutine := &recovery.RecoverableRoutine{
		Routine:             runDiscovery,
		RoutineArg:          runDiscoveryArgs{s},
		ErrorCode:           usagemetrics.MySQLDiscoveryFailure,
		UsageLogger:         *usagemetrics.UsageLogger,
		ExpectedMinDuration: 0,
	}
	discoveryRoutine.StartRoutine(dCtx)

	// Start MySQL Metric Collection
	mcCtx := log.SetCtx(ctx, "context", "MySQLMetricCollection")
	metricCollectionRoutine := &recovery.RecoverableRoutine{
		Routine:             runMetricCollection,
		RoutineArg:          runMetricCollectionArgs{s},
		ErrorCode:           usagemetrics.MySQLMetricCollectionFailure,
		UsageLogger:         *usagemetrics.UsageLogger,
		ExpectedMinDuration: 0,
	}
	metricCollectionRoutine.StartRoutine(mcCtx)
	select {
	case <-ctx.Done():
		log.CtxLogger(ctx).Info("MySQL workload agent service cancellation requested")
		return
	}
}