Repository: prometheus/alertmanager
File: silence/silence.go (Go)

Code before:
	return len(activeIDs) > 0
}

// Silences holds a silence state that can be modified, queried, and snapshot.
type Silences struct {
	clock clock.Clock

	logger    log.Logger
	metrics   *metrics
	retention time.Duration
	limits    Limits

	mtx       sync.RWMutex
	st        state
	version   int // Increments whenever silences are added.
	broadcast func([]byte)
	mc        matcherCache
}

// Limits contains the limits for silences.
type Limits struct {
	// MaxSilences limits the maximum number active and pending silences.
	// It does not include expired silences.
	MaxSilences       int
	MaxPerSilenceSize int
}

// MaintenanceFunc represents the function to run as part of the periodic maintenance for silences.
// It returns the size of the snapshot taken or an error if it failed.
type MaintenanceFunc func() (int64, error)

type metrics struct {
	gcDuration              prometheus.Summary
	snapshotDuration        prometheus.Summary
	snapshotSize            prometheus.Gauge
	queriesTotal            prometheus.Counter
	queryErrorsTotal        prometheus.Counter
	queryDuration           prometheus.Histogram
	silencesActive          prometheus.GaugeFunc
	silencesPending         prometheus.GaugeFunc
	silencesExpired         prometheus.GaugeFunc
	propagatedMessagesTotal prometheus.Counter
	maintenanceTotal        prometheus.Counter
	maintenanceErrorsTotal  prometheus.Counter
}

func newSilenceMetricByState(s *Silences, st types.SilenceState) prometheus.GaugeFunc {
	return prometheus.NewGaugeFunc(
		prometheus.GaugeOpts{
			Name:        "alertmanager_silences",
			Help:        "How many silences by state.",

Review comment (suggestion):
```suggestion
// Limits contain the limits for silences.
type Limits struct {
	// MaxSilences limits the maximum number of active and pending silences.
	// It does not include expired silences.
	MaxSilences       int
	// MaxBytesPerSilence is the maximum allowed size of all the attributes of a silence.
	MaxBytesPerSilence int
}
```

Code after:
	return len(activeIDs) > 0
}

// Silences holds a silence state that can be modified, queried, and snapshot.
type Silences struct {
	clock clock.Clock

	logger    log.Logger
	metrics   *metrics
	retention time.Duration
	limits    Limits

	mtx       sync.RWMutex
	st        state
	version   int // Increments whenever silences are added.
	broadcast func([]byte)
	mc        matcherCache
}

// Limits contains the limits for silences.
type Limits struct {
	// MaxSilences limits the maximum number active and pending silences.
	// It does not include expired silences.
	MaxSilences int
	// MaxPerSilenceBytes is the maximum size of an individual silence as
	// stored on disk.
	MaxPerSilenceBytes int
}

// MaintenanceFunc represents the function to run as part of the periodic maintenance for silences.
// It returns the size of the snapshot taken or an error if it failed.
type MaintenanceFunc func() (int64, error)

type metrics struct {
	gcDuration              prometheus.Summary
	snapshotDuration        prometheus.Summary
	snapshotSize            prometheus.Gauge
	queriesTotal            prometheus.Counter
	queryErrorsTotal        prometheus.Counter
	queryDuration           prometheus.Histogram
	silencesActive          prometheus.GaugeFunc
	silencesPending         prometheus.GaugeFunc
	silencesExpired         prometheus.GaugeFunc
	propagatedMessagesTotal prometheus.Counter
	maintenanceTotal        prometheus.Counter
	maintenanceErrorsTotal  prometheus.Counter
}

func newSilenceMetricByState(s *Silences, st types.SilenceState) prometheus.GaugeFunc {
	return prometheus.NewGaugeFunc(
		prometheus.GaugeOpts{