CollectAll collects data from all available integrations Returns a map of integration name -> integration data Errors in individual integrations do not stop collection from others
(ctx context.Context)
| 80 | // Returns a map of integration name -> integration data |
| 81 | // Errors in individual integrations do not stop collection from others |
| 82 | func (m *Manager) CollectAll(ctx context.Context) map[string]*models.IntegrationData { |
| 83 | available := m.DiscoverIntegrations() |
| 84 | |
| 85 | if len(available) == 0 { |
| 86 | m.logger.Debug("No integrations available for collection") |
| 87 | return make(map[string]*models.IntegrationData) |
| 88 | } |
| 89 | |
| 90 | results := make(map[string]*models.IntegrationData) |
| 91 | var wg sync.WaitGroup |
| 92 | var resultsMu sync.Mutex |
| 93 | |
| 94 | m.logger.WithField("count", len(available)).Info("Collecting data from integrations...") |
| 95 | |
| 96 | for _, integration := range available { |
| 97 | wg.Add(1) |
| 98 | go func(integ Integration) { |
| 99 | defer wg.Done() |
| 100 | |
| 101 | name := integ.Name() |
| 102 | m.logger.WithField("integration", name).Debug("Starting collection") |
| 103 | startTime := time.Now() |
| 104 | |
| 105 | data, err := integ.Collect(ctx) |
| 106 | if err != nil { |
| 107 | m.logger.WithFields(logrus.Fields{ |
| 108 | "integration": name, |
| 109 | "error": err.Error(), |
| 110 | }).Warn("Integration collection failed") |
| 111 | |
| 112 | // Still add the result but with error |
| 113 | data = &models.IntegrationData{ |
| 114 | Name: name, |
| 115 | Enabled: true, |
| 116 | CollectedAt: utils.GetCurrentTimeUTC(), |
| 117 | ExecutionTime: time.Since(startTime).Seconds(), |
| 118 | Error: err.Error(), |
| 119 | } |
| 120 | } else { |
| 121 | m.logger.WithFields(logrus.Fields{ |
| 122 | "integration": name, |
| 123 | "execution_time": data.ExecutionTime, |
| 124 | }).Info("Integration collection completed") |
| 125 | } |
| 126 | |
| 127 | resultsMu.Lock() |
| 128 | results[name] = data |
| 129 | resultsMu.Unlock() |
| 130 | }(integration) |
| 131 | } |
| 132 | |
| 133 | wg.Wait() |
| 134 | return results |
| 135 | } |
| 136 | |
| 137 | // GetIntegration returns a specific integration by name |
| 138 | func (m *Manager) GetIntegration(name string) (Integration, error) { |
no test coverage detected