checkmgr/metrics.go
func (cm *CheckManager) addNewMetrics(newMetrics map[string]*api.CheckBundleMetric) bool {
	updatedCheckBundle := false

	if cm.checkBundle == nil || len(newMetrics) == 0 {
		return updatedCheckBundle
	}

	cm.cbmu.Lock()
	defer cm.cbmu.Unlock()

	numCurrMetrics := len(cm.checkBundle.Metrics)
	numNewMetrics := len(newMetrics)

	if numCurrMetrics+numNewMetrics >= cap(cm.checkBundle.Metrics) {
		nm := make([]api.CheckBundleMetric, numCurrMetrics+numNewMetrics)
		copy(nm, cm.checkBundle.Metrics)
		cm.checkBundle.Metrics = nm
	}

	cm.checkBundle.Metrics = cm.checkBundle.Metrics[0 : numCurrMetrics+numNewMetrics]

	i := 0
	for _, metric := range newMetrics {
		cm.checkBundle.Metrics[numCurrMetrics+i] = *metric
		i++
		updatedCheckBundle = true
	}

	if updatedCheckBundle {
		cm.forceCheckUpdate = true
	}

	return updatedCheckBundle
}
func (cm *CheckManager) addNewMetrics(newMetrics map[string]*api.CheckBundleMetric) bool {
	updatedCheckBundle := false

	if cm.checkBundle == nil || len(newMetrics) == 0 {
		return updatedCheckBundle
	}

	cm.cbmu.Lock()
	defer cm.cbmu.Unlock()

	numCurrMetrics := len(cm.checkBundle.Metrics)
	numNewMetrics := len(newMetrics)

	if numCurrMetrics+numNewMetrics >= cap(cm.checkBundle.Metrics) {
		nm := make([]api.CheckBundleMetric, numCurrMetrics+numNewMetrics)
		copy(nm, cm.checkBundle.Metrics)
		cm.checkBundle.Metrics = nm
	}

	cm.checkBundle.Metrics = cm.checkBundle.Metrics[0 : numCurrMetrics+numNewMetrics]

	i := 0
	for _, metric := range newMetrics {
		cm.checkBundle.Metrics[numCurrMetrics+i] = *metric
		i++
		updatedCheckBundle = true
	}

	if updatedCheckBundle {
		cm.forceCheckUpdate = true
	}

	return updatedCheckBundle
}
func ( cm * CheckManager ) addNewMetrics ( newMetrics map [ string ] * api . CheckBundleMetric ) bool { updatedCheckBundle := false if cm . checkBundle == nil || len ( newMetrics ) == 0 { return updatedCheckBundle } cm . cbmu . Lock ( ) defer cm . cbmu . Unlock ( ) numCurrMetrics := len ( cm . checkBundle . Metrics ) numNewMetrics := len ( newMetrics ) if numCurrMetrics + numNewMetrics >= cap ( cm . checkBundle . Metrics ) { nm := make ( [ ] api . CheckBundleMetric , numCurrMetrics + numNewMetrics ) copy ( nm , cm . checkBundle . Metrics ) cm . checkBundle . Metrics = nm } cm . checkBundle . Metrics = cm . checkBundle . Metrics [ 0 : numCurrMetrics + numNewMetrics ] i := 0 for _ , metric := range newMetrics { cm . checkBundle . Metrics [ numCurrMetrics + i ] = * metric i ++ updatedCheckBundle = true } if updatedCheckBundle { cm . forceCheckUpdate = true } return updatedCheckBundle }
// addNewMetrics updates a check bundle with new metrics
addNewMetrics updates a check bundle with new metrics