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