Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions lib/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,25 @@ var (
[]string{teleport.TagCacheComponent},
)

cacheCollectors = []prometheus.Collector{cacheEventsReceived, cacheStaleEventsReceived}
cacheHealth = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: teleport.MetricNamespace,
Subsystem: "cache",
Name: "health",
Help: "Whether the cache for a particular Teleport service is healthy.",
},
[]string{teleport.TagCacheComponent},
)

cacheLastReset = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: teleport.MetricNamespace,
Subsystem: "cache",
Name: "last_reset_seconds",
Help: "The unix time in seconds that the last cache reset was performed.",
},
[]string{teleport.TagCacheComponent},
)
)

// highVolumeResources is the set of cached resources that tend to produce high
Expand Down Expand Up @@ -506,6 +524,12 @@ func (c *Cache) setInitError(err error) {
c.initErr = err
close(c.initC)
})

if err == nil {
cacheHealth.WithLabelValues(c.Component).Set(1.0)
} else {
cacheHealth.WithLabelValues(c.Component).Set(0.0)
}
}

// setReadStatus updates Cache.ok, which determines whether the
Expand Down Expand Up @@ -858,7 +882,12 @@ const (

// New creates a new instance of Cache
func New(config Config) (*Cache, error) {
if err := metrics.RegisterPrometheusCollectors(cacheCollectors...); err != nil {
if err := metrics.RegisterPrometheusCollectors(
cacheEventsReceived,
cacheStaleEventsReceived,
cacheHealth,
cacheLastReset,
); err != nil {
return nil, trace.Wrap(err)
}

Expand Down Expand Up @@ -1143,6 +1172,7 @@ func (c *Cache) notify(ctx context.Context, event Event) {
// we assume that this cache will eventually end up in a correct state
// potentially lagging behind the state of the database.
func (c *Cache) fetchAndWatch(ctx context.Context, retry retryutils.Retry, timer *time.Timer) error {
cacheLastReset.WithLabelValues(c.Component).SetToCurrentTime()
requestKinds := c.Config.Watches
watcher, err := c.Events.NewWatcher(c.ctx, types.Watch{
Name: c.Component,
Expand Down
Loading