Skip to content
This repository was archived by the owner on Aug 23, 2023. It is now read-only.

Commit b68b58a

Browse files
committed
simplify creating cassandra metrics
1 parent 6ba1ee2 commit b68b58a

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

cassandra/metrics.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ type Metrics struct {
1616
cassErrOther met.Count
1717
}
1818

19-
func (m *Metrics) Init(component string, stats met.Backend) {
20-
m.cassErrTimeout = stats.NewCount(fmt.Sprintf("%s.error.timeout", component))
21-
m.cassErrTooManyTimeouts = stats.NewCount(fmt.Sprintf("%s.error.too-many-timeouts", component))
22-
m.cassErrConnClosed = stats.NewCount(fmt.Sprintf("%s.error.conn-closed", component))
23-
m.cassErrNoConns = stats.NewCount(fmt.Sprintf("%s.error.no-connections", component))
24-
m.cassErrUnavailable = stats.NewCount(fmt.Sprintf("%s.error.unavailable", component))
25-
m.cassErrOther = stats.NewCount(fmt.Sprintf("%s.error.other", component))
19+
func NewMetrics(component string, stats met.Backend) Metrics {
20+
return Metrics{
21+
cassErrTimeout: stats.NewCount(fmt.Sprintf("%s.error.timeout", component)),
22+
cassErrTooManyTimeouts: stats.NewCount(fmt.Sprintf("%s.error.too-many-timeouts", component)),
23+
cassErrConnClosed: stats.NewCount(fmt.Sprintf("%s.error.conn-closed", component)),
24+
cassErrNoConns: stats.NewCount(fmt.Sprintf("%s.error.no-connections", component)),
25+
cassErrUnavailable: stats.NewCount(fmt.Sprintf("%s.error.unavailable", component)),
26+
cassErrOther: stats.NewCount(fmt.Sprintf("%s.error.other", component)),
27+
}
2628
}
2729

2830
func (m *Metrics) Inc(err error) {

idx/cassandra/cassandra.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,7 @@ func (c *CasIdx) Init(stats met.Backend) error {
131131
idxCasFail = stats.NewCount("idx.cassandra.fail")
132132
idxCasAddDuration = stats.NewTimer("idx.cassandra.add_duration", 0)
133133
idxCasDeleteDuration = stats.NewTimer("idx.cassandra.delete_duration", 0)
134-
metrics = cassandra.Metrics{}
135-
metrics.Init("idx.cassandra", stats)
134+
metrics = cassandra.NewMetrics("idx.cassandra", stats)
136135

137136
for i := 0; i < numConns; i++ {
138137
c.wg.Add(1)

mdata/store_cassandra.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ func NewCassandraStore(stats met.Backend, addrs, keyspace, consistency string, t
9898
writeQueues: make([]chan *ChunkWriteRequest, writers),
9999
readQueue: make(chan *ChunkReadRequest, readqsize),
100100
writeQueueMeters: make([]met.Meter, writers),
101-
metrics: cassandra.Metrics{},
102101
}
103102

104103
for i := 0; i < writers; i++ {
@@ -128,7 +127,7 @@ func (c *cassandraStore) InitMetrics(stats met.Backend) {
128127
chunkSizeAtSave = stats.NewMeter("chunk_size.at_save", 0)
129128
chunkSizeAtLoad = stats.NewMeter("chunk_size.at_load", 0)
130129

131-
c.metrics.Init("cassandra", stats)
130+
c.metrics = cassandra.NewMetrics("cassandra", stats)
132131
}
133132

134133
func (c *cassandraStore) Add(cwr *ChunkWriteRequest) {

0 commit comments

Comments
 (0)