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

Commit 8a321e5

Browse files
committed
tools: fix the last ones. mt-whisper-importer-*
1 parent 65807e2 commit 8a321e5

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

cmd/mt-whisper-importer-reader/main.go

+15-13
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"time"
2020

2121
log "github.com/Sirupsen/logrus"
22-
"github.com/grafana/metrictank/api"
2322
"github.com/grafana/metrictank/conf"
2423
"github.com/grafana/metrictank/mdata/chunk"
2524
"github.com/grafana/metrictank/mdata/chunk/archive"
@@ -287,7 +286,7 @@ func getMetric(w *whisper.Whisper, file, name string) (archive.Metric, error) {
287286
OrgId: *orgId,
288287
}
289288
md.SetId()
290-
_, schema := schemas.Match(md.Name, int(w.Header.Archives[0].SecondsPerPoint))
289+
_, schem := schemas.Match(md.Name, int(w.Header.Archives[0].SecondsPerPoint))
291290

292291
points := make(map[int][]whisper.Point)
293292
for i := range w.Header.Archives {
@@ -299,20 +298,24 @@ func getMetric(w *whisper.Whisper, file, name string) (archive.Metric, error) {
299298
}
300299

301300
conversion := newConversion(w.Header.Archives, points, method)
302-
for retIdx, retention := range schema.Retentions {
301+
for retIdx, retention := range schem.Retentions {
303302
convertedPoints := conversion.getPoints(retIdx, uint32(retention.SecondsPerPoint), uint32(retention.NumberOfPoints))
304303
for m, p := range convertedPoints {
305304
if len(p) == 0 {
306305
continue
307306
}
308-
rowKey := getRowKey(retIdx, md.Id, m, retention.SecondsPerPoint)
307+
mkey, err := schema.MKeyFromString(md.Id)
308+
if err != nil {
309+
panic(err)
310+
}
311+
rowKey := getRowKey(retIdx, mkey, m, retention.SecondsPerPoint)
309312
encodedChunks := encodedChunksFromPoints(p, uint32(retention.SecondsPerPoint), retention.ChunkSpan)
310313
log.Debugf("Archive %d Method %s got %d points = %d chunks at a span of %d", retIdx, m, len(p), len(encodedChunks), retention.ChunkSpan)
311314
res.Archives = append(res.Archives, archive.Archive{
312315
SecondsPerPoint: uint32(retention.SecondsPerPoint),
313316
Points: uint32(retention.NumberOfPoints),
314317
Chunks: encodedChunks,
315-
RowKey: rowKey,
318+
RowKey: rowKey.String(),
316319
})
317320
if int64(p[len(p)-1].Timestamp) > md.Time {
318321
md.Time = int64(p[len(p)-1].Timestamp)
@@ -324,15 +327,14 @@ func getMetric(w *whisper.Whisper, file, name string) (archive.Metric, error) {
324327
return res, nil
325328
}
326329

327-
func getRowKey(retIdx int, id, meth string, secondsPerPoint int) string {
330+
func getRowKey(retIdx int, mkey schema.MKey, meth string, secondsPerPoint int) schema.AMKey {
328331
if retIdx == 0 {
329-
return id
330-
} else {
331-
return api.AggMetricKey(
332-
id,
333-
meth,
334-
uint32(secondsPerPoint),
335-
)
332+
return schema.AMKey{MKey: mkey}
333+
}
334+
m, _ := schema.MethodFromString(meth)
335+
return schema.AMKey{
336+
MKey: mkey,
337+
Archive: schema.NewArchive(m, uint32(secondsPerPoint)),
336338
}
337339
}
338340

cmd/mt-whisper-importer-writer/main.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"strings"
1111
"time"
1212

13+
schema "gopkg.in/raintank/schema.v1"
14+
1315
log "github.com/Sirupsen/logrus"
1416
"github.com/gocql/gocql"
1517
"github.com/grafana/metrictank/cluster"
@@ -219,13 +221,17 @@ func (s *Server) chunksHandler(w http.ResponseWriter, req *http.Request) {
219221
throwError("Metric has no archives")
220222
return
221223
}
224+
mkey, err := schema.MKeyFromString(metric.MetricData.Id)
225+
if err != nil {
226+
throwError(fmt.Sprintf("Invalid MetricData.Id: %s", err))
227+
}
222228

223229
partition, err := s.Partitioner.Partition(&metric.MetricData, int32(*numPartitions))
224230
if err != nil {
225231
throwError(fmt.Sprintf("Error partitioning: %q", err))
226232
return
227233
}
228-
s.Index.AddOrUpdate(&metric.MetricData, partition)
234+
s.Index.AddOrUpdate(mkey, &metric.MetricData, partition)
229235

230236
for archiveIdx, a := range metric.Archives {
231237
archiveTTL := a.SecondsPerPoint * a.Points

0 commit comments

Comments
 (0)