github.com/thanos-io/thanos@v0.32.5/pkg/prober/combiner.go (about)

     1  // Copyright (c) The Thanos Authors.
     2  // Licensed under the Apache License 2.0.
     3  
     4  package prober
     5  
     6  import "sync"
     7  
     8  type combined struct {
     9  	mu     sync.Mutex
    10  	probes []Probe
    11  }
    12  
    13  // Combine folds given probes into one, reflects their statuses in a thread-safe way.
    14  func Combine(probes ...Probe) Probe {
    15  	return &combined{probes: probes}
    16  }
    17  
    18  // Ready sets components status to ready.
    19  func (p *combined) Ready() {
    20  	p.mu.Lock()
    21  	defer p.mu.Unlock()
    22  
    23  	for _, probe := range p.probes {
    24  		probe.Ready()
    25  	}
    26  }
    27  
    28  // NotReady sets components status to not ready with given error as a cause.
    29  func (p *combined) NotReady(err error) {
    30  	p.mu.Lock()
    31  	defer p.mu.Unlock()
    32  
    33  	for _, probe := range p.probes {
    34  		probe.NotReady(err)
    35  	}
    36  }
    37  
    38  // Healthy sets components status to healthy.
    39  func (p *combined) Healthy() {
    40  	p.mu.Lock()
    41  	defer p.mu.Unlock()
    42  
    43  	for _, probe := range p.probes {
    44  		probe.Healthy()
    45  	}
    46  }
    47  
    48  // NotHealthy sets components status to not healthy with given error as a cause.
    49  func (p *combined) NotHealthy(err error) {
    50  	p.mu.Lock()
    51  	defer p.mu.Unlock()
    52  
    53  	for _, probe := range p.probes {
    54  		probe.NotHealthy(err)
    55  	}
    56  }