func CollectAndRecordGatherer(
	ctx context.Context,
	gatherer gatherers.Interface,
	rec recorder.Interface,
	configurator configobserver.Configurator,
) ([]GathererFunctionReport, error) {
	resultsChan, err := startGatheringConcurrently(ctx, gatherer, configurator.Config().Gather)
	if err != nil {
		return nil, err
	}

	gathererName := gatherer.GetName()

	var errs []error
	var functionReports []GathererFunctionReport

	for result := range resultsChan {
		if result.Panic != nil {
			klog.Error(fmt.Errorf(
				"gatherer %v's function %v panicked with error: %v",
				gathererName, result.FunctionName, result.Panic,
			))
			result.Errs = append(result.Errs, fmt.Errorf("%v", result.Panic))
		}

		for _, err := range result.Errs {
			errStr := fmt.Sprintf(
				"gatherer %v's function %v failed with error: %v",
				gathererName, result.FunctionName, err,
			)

			if result.IgnoreErrors {
				klog.Error(errStr)
			} else {
				errs = append(errs, fmt.Errorf(errStr))
			}
		}
		recordedRecs := 0
		for _, r := range result.Records {
			if err := rec.Record(r); err != nil {
				recErr := fmt.Errorf(
					"unable to record gatherer %v function %v' result %v because of error: %v",
					gathererName, result.FunctionName, r.Name, err,
				)
				result.Errs = append(result.Errs, recErr)
				continue
			}
			recordedRecs++
		}

		klog.Infof(
			"Gather %v's function %v took %v to process %v records",
			gathererName, result.FunctionName, result.TimeElapsed, len(result.Records),
		)

		functionReports = append(functionReports, GathererFunctionReport{
			FuncName:     fmt.Sprintf("%v/%v", gathererName, result.FunctionName),
			Duration:     result.TimeElapsed.Milliseconds(),
			RecordsCount: recordedRecs,
			Errors:       errorsToStrings(result.Errs),
			Panic:        result.Panic,
		})
	}
	return functionReports, sumErrors(errs)
}
// CollectAndRecordGatherer gathers enabled functions of the provided gatherer and records the results to the recorder
// and returns info about the recorded data. Panics are just logged and written
// to the resulting array (to the archive metadata)
CollectAndRecordGatherer gathers enabled functions of the provided gatherer and records the results to the recorder
and returns info about the recorded data. Panics are just logged and written
to the resulting array (to the archive metadata)
// CollectAndRecordGatherer gathers enabled functions of the provided gatherer and records the results to the recorder // and returns info about the recorded data . Panics are just logged and written // to the resulting array ( to the archive metadata )
func CollectAndRecordGatherer(
	ctx context.Context,
	gatherer gatherers.Interface,
	rec recorder.Interface,
	configurator configobserver.Configurator,
) ([]GathererFunctionReport, error) {
	resultsChan, err := startGatheringConcurrently(ctx, gatherer, configurator.Config().Gather)
	if err != nil {
		return nil, err
	}
	gathererName := gatherer.GetName()
	var errs []error
	var functionReports []GathererFunctionReport
	for result := range resultsChan {
		if result.Panic != nil {
			klog.Error(fmt.Errorf(
				"gatherer %v's function %v panicked with error: %v",
				gathererName, result.FunctionName, result.Panic,
			))
			result.Errs = append(result.Errs, fmt.Errorf("%v", result.Panic))
		}
		for _, err := range result.Errs {
			errStr := fmt.Sprintf(
				"gatherer %v's function %v failed with error: %v",
				gathererName, result.FunctionName, err,
			)
			if result.IgnoreErrors {
				klog.Error(errStr)
			} else {
				errs = append(errs, fmt.Errorf(errStr))
			}
		}
		recordedRecs := 0
		for _, r := range result.Records {
			if err := rec.Record(r); err != nil {
				recErr := fmt.Errorf(
					"unable to record gatherer %v function %v' result %v because of error: %v",
					gathererName, result.FunctionName, r.Name, err,
				)
				result.Errs = append(result.Errs, recErr)
				continue
			}
			recordedRecs++
		}
		klog.Infof(
			"Gather %v's function %v took %v to process %v records",
			gathererName, result.FunctionName, result.TimeElapsed, len(result.Records),
		)
		functionReports = append(functionReports, GathererFunctionReport{
			FuncName:     fmt.Sprintf("%v/%v", gathererName, result.FunctionName),
			Duration:     result.TimeElapsed.Milliseconds(),
			RecordsCount: recordedRecs,
			Errors:       errorsToStrings(result.Errs),
			Panic:        result.Panic,
		})
	}
	return functionReports, sumErrors(errs)
}
func CollectAndRecordGatherer ( ctx context . Context , gatherer gatherers . Interface , rec recorder . Interface , configurator configobserver . Configurator , ) ( [ ] GathererFunctionReport , error ) { resultsChan , err := startGatheringConcurrently ( ctx , gatherer , configurator . Config ( ) . Gather ) if err != nil { return nil , err } gathererName := gatherer . GetName ( ) var errs [ ] error var functionReports [ ] GathererFunctionReport for result := range resultsChan { if result . Panic != nil { klog . Error ( fmt . Errorf ( " " , gathererName , result . FunctionName , result . Panic , ) ) result . Errs = append ( result . Errs , fmt . Errorf ( " " , result . Panic ) ) } for _ , err := range result . Errs { errStr := fmt . Sprintf ( " " , gathererName , result . FunctionName , err , ) if result . IgnoreErrors { klog . Error ( errStr ) } else { errs = append ( errs , fmt . Errorf ( errStr ) ) } } recordedRecs := 0 for _ , r := range result . Records { if err := rec . Record ( r ) ; err != nil { recErr := fmt . Errorf ( " " , gathererName , result . FunctionName , r . Name , err , ) result . Errs = append ( result . Errs , recErr ) continue } recordedRecs ++ } klog . Infof ( " " , gathererName , result . FunctionName , result . TimeElapsed , len ( result . Records ) , ) functionReports = append ( functionReports , GathererFunctionReport { FuncName : fmt . Sprintf ( " " , gathererName , result . FunctionName ) , Duration : result . TimeElapsed . Milliseconds ( ) , RecordsCount : recordedRecs , Errors : errorsToStrings ( result . Errs ) , Panic : result . Panic , } ) } return functionReports , sumErrors ( errs ) }
CollectAndRecordGatherer gathers enabled functions of the provided gatherer and records the results to the recorder
and returns info about the recorded data.
CollectAndRecordGatherer gathers enabled functions of the provided gatherer and records the results to the recorder and returns info about the recorded data .