github.com/juju/juju@v0.0.0-20240327075706-a90865de2538/worker/uniter/probe.go (about) 1 // Copyright 2020 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package uniter 5 6 import ( 7 "sync" 8 9 "github.com/juju/juju/observability/probe" 10 ) 11 12 // Probe is a prober implementation for the uniter worker to form part of the 13 // Juju probe support 14 type Probe struct { 15 hasStartedLock sync.RWMutex 16 hasStarted bool 17 } 18 19 // HasStarted indiciates if this probe considered the uniter to have been 20 // started. 21 func (p *Probe) HasStarted() bool { 22 p.hasStartedLock.RLock() 23 defer p.hasStartedLock.RUnlock() 24 return p.hasStarted 25 } 26 27 // SetHasStarted sets the has started state for this probe. Should be called 28 // when the uniter has started its associated charm. 29 func (p *Probe) SetHasStarted(started bool) { 30 p.hasStartedLock.Lock() 31 defer p.hasStartedLock.Unlock() 32 p.hasStarted = started 33 } 34 35 // SupportedProbes implements probe.ProbeProvider interface 36 func (p *Probe) SupportedProbes() probe.SupportedProbes { 37 return probe.SupportedProbes{ 38 probe.ProbeLiveness: probe.ProberFn(func() (bool, error) { 39 return true, nil 40 }), 41 probe.ProbeReadiness: probe.ProberFn(func() (bool, error) { 42 return p.HasStarted(), nil 43 }), 44 } 45 }