MCPcopy Create free account
hub / github.com/cortexproject/cortex / PreStore

Method PreStore

pkg/alertmanager/alertmanager.go:761–791  ·  view source on GitHub ↗
(alert *types.Alert, existing bool)

Source from the content-addressed store, hash-verified

759}
760
761func (a *alertsLimiter) PreStore(alert *types.Alert, existing bool) error {
762 if alert == nil {
763 return nil
764 }
765
766 fp := alert.Fingerprint()
767
768 countLimit := a.limits.AlertmanagerMaxAlertsCount(a.tenant)
769 sizeLimit := a.limits.AlertmanagerMaxAlertsSizeBytes(a.tenant)
770
771 sizeDiff := alertSize(alert.Alert)
772
773 a.mx.Lock()
774 defer a.mx.Unlock()
775
776 if !existing && countLimit > 0 && (a.count+1) > countLimit {
777 a.failureCounter.Inc()
778 return fmt.Errorf(errTooManyAlerts, countLimit, alert.Name())
779 }
780
781 if existing {
782 sizeDiff -= a.sizes[fp]
783 }
784
785 if sizeLimit > 0 && (a.totalSize+sizeDiff) > sizeLimit {
786 a.failureCounter.Inc()
787 return fmt.Errorf(errAlertsTooBig, sizeLimit)
788 }
789
790 return nil
791}
792
793func (a *alertsLimiter) PostStore(alert *types.Alert, existing bool) {
794 if alert == nil {

Callers 1

testLimiterFunction · 0.80

Calls 5

alertSizeFunction · 0.85
NameMethod · 0.65
IncMethod · 0.45

Tested by 1

testLimiterFunction · 0.64