-
Notifications
You must be signed in to change notification settings - Fork 487
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added last read/wrote timestamp metrics to loki.write (#5699)
- Loading branch information
Showing
8 changed files
with
106 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package client | ||
|
||
import ( | ||
"github.com/grafana/agent/pkg/util" | ||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
type QueueClientMetrics struct { | ||
lastReadTimestamp *prometheus.GaugeVec | ||
} | ||
|
||
func NewQueueClientMetrics(reg prometheus.Registerer) *QueueClientMetrics { | ||
m := &QueueClientMetrics{ | ||
lastReadTimestamp: prometheus.NewGaugeVec( | ||
prometheus.GaugeOpts{ | ||
Namespace: "loki_write", | ||
Name: "last_read_timestamp", | ||
Help: "Latest timestamp read from the WAL", | ||
}, | ||
[]string{"id"}, | ||
), | ||
} | ||
|
||
if reg != nil { | ||
m.lastReadTimestamp = util.MustRegisterOrGet(reg, m.lastReadTimestamp).(*prometheus.GaugeVec) | ||
} | ||
|
||
return m | ||
} | ||
|
||
func (m *QueueClientMetrics) CurryWithId(id string) *QueueClientMetrics { | ||
return &QueueClientMetrics{ | ||
lastReadTimestamp: m.lastReadTimestamp.MustCurryWith(map[string]string{ | ||
"id": id, | ||
}), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package util | ||
|
||
import "github.com/prometheus/client_golang/prometheus" | ||
|
||
// MustRegisterOrGet will attempt to register the supplied collector into the register. If it's already | ||
// registered, it will return that one. | ||
// In case that the register procedure fails with something other than already registered, this will panic. | ||
func MustRegisterOrGet(reg prometheus.Registerer, c prometheus.Collector) prometheus.Collector { | ||
if err := reg.Register(c); err != nil { | ||
if are, ok := err.(prometheus.AlreadyRegisteredError); ok { | ||
return are.ExistingCollector | ||
} | ||
panic(err) | ||
} | ||
return c | ||
} |