Skip to content

Commit c250082

Browse files
committed
Report on table capacity
Even though we actually set the table capacity in our code, there's nothing that prevents it from being changed, so it can be useful to instrument in our code base in case something unexpected happens.
1 parent c008545 commit c250082

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

chunk/dynamo_client.go

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package chunk
22

33
import (
44
"net/url"
5+
"strings"
56
"sync"
67
"time"
78

@@ -18,8 +19,11 @@ const (
1819

1920
type dynamoWatcher struct {
2021
accountMaxCapacity *prometheus.GaugeVec
22+
tableCapacity *prometheus.GaugeVec
23+
24+
dynamoDB *dynamodb.DynamoDB
25+
tableName string
2126

22-
dynamoDB *dynamodb.DynamoDB
2327
updateInterval time.Duration
2428
quit chan struct{}
2529
wait sync.WaitGroup
@@ -43,15 +47,20 @@ func WatchDynamo(dynamoDBURL string, interval time.Duration) (Watcher, error) {
4347
}
4448
client := dynamodb.New(session.New(dynamoDBConfig))
4549

46-
// TODO: Report on table capacity.
47-
// tableName := strings.TrimPrefix(dynamoURL.Path, "/")
50+
tableName := strings.TrimPrefix(url.Path, "/")
4851
w := &dynamoWatcher{
4952
accountMaxCapacity: prometheus.NewGaugeVec(prometheus.GaugeOpts{
5053
Namespace: "cortex",
5154
Name: "dynamo_account_max_capacity_units",
5255
Help: "Account-wide DynamoDB capacity, measured in DynamoDB capacity units.",
5356
}, []string{"op"}),
57+
tableCapacity: prometheus.NewGaugeVec(prometheus.GaugeOpts{
58+
Namespace: "cortex",
59+
Name: "dynamo_table_capacity_units",
60+
Help: "Per-table DynamoDB capacity, measured in DynamoDB capacity units.",
61+
}, []string{"op", "table"}),
5462
dynamoDB: client,
63+
tableName: tableName,
5564
updateInterval: interval,
5665
quit: make(chan struct{}),
5766
}
@@ -92,12 +101,25 @@ func (w *dynamoWatcher) updateAccountLimits() error {
92101
return nil
93102
}
94103

104+
func (w *dynamoWatcher) updateTableLimits() error {
105+
output, err := w.dynamoDB.DescribeTable(&dynamodb.DescribeTableInput{})
106+
if err != nil {
107+
return err
108+
}
109+
throughput := output.Table.ProvisionedThroughput
110+
w.tableCapacity.WithLabelValues(readLabel, w.tableName).Set(float64(*throughput.ReadCapacityUnits))
111+
w.tableCapacity.WithLabelValues(writeLabel, w.tableName).Set(float64(*throughput.WriteCapacityUnits))
112+
return nil
113+
}
114+
95115
// Describe implements prometheus.Collector.
96116
func (w *dynamoWatcher) Describe(ch chan<- *prometheus.Desc) {
97117
w.accountMaxCapacity.Describe(ch)
118+
w.tableCapacity.Describe(ch)
98119
}
99120

100121
// Collect implements prometheus.Collector.
101122
func (w *dynamoWatcher) Collect(ch chan<- prometheus.Metric) {
102123
w.accountMaxCapacity.Collect(ch)
124+
w.tableCapacity.Collect(ch)
103125
}

0 commit comments

Comments
 (0)