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

Commit

Permalink
deprecate Metric field in favor of Name
Browse files Browse the repository at this point in the history
  • Loading branch information
Dieterbe committed Apr 10, 2018
1 parent 96a9579 commit 8dec28c
Show file tree
Hide file tree
Showing 17 changed files with 29 additions and 84 deletions.
4 changes: 0 additions & 4 deletions api/ccache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ func TestMetricDeleteWithPattern(t *testing.T) {
Id: testId.String(),
OrgId: 1,
Name: testKey,
Metric: testKey,
Interval: 10,
Value: 1,
},
Expand Down Expand Up @@ -110,7 +109,6 @@ func TestMetricDeleteWithTags(t *testing.T) {
Id: testId.String(),
OrgId: 1,
Name: testKey,
Metric: testKey,
Interval: 10,
Tags: []string{"mytag=myvalue"},
Value: 1,
Expand Down Expand Up @@ -200,7 +198,6 @@ func TestMetricDeleteWithErrorInPropagation(t *testing.T) {
Id: testId.String(),
OrgId: 1,
Name: testKey,
Metric: testKey,
Interval: 10,
Value: 1,
},
Expand Down Expand Up @@ -267,7 +264,6 @@ func TestMetricDeletePropagation(t *testing.T) {
Id: testId.String(),
OrgId: 1,
Name: testKey,
Metric: testKey,
Interval: 10,
Value: 1,
},
Expand Down
1 change: 0 additions & 1 deletion chaos/ingest.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ func init() {
m := &schema.MetricData{
OrgId: 1,
Name: name,
Metric: name,
Interval: 1,
Value: 1,
Unit: "s",
Expand Down
4 changes: 2 additions & 2 deletions cmd/mt-index-cat/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,10 @@ func main() {
for _, d := range defs {
// note that prefix and substr can be "", meaning filter disabled.
// the conditions handle this fine as well.
if !strings.HasPrefix(d.Metric, prefix) {
if !strings.HasPrefix(d.Name, prefix) {
continue
}
if !strings.Contains(d.Metric, substr) {
if !strings.Contains(d.Name, substr) {
continue
}
if tags == "none" && len(d.Tags) != 0 {
Expand Down
13 changes: 5 additions & 8 deletions cmd/mt-index-migrate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,14 @@ func writeDefs(session *gocql.Session, defsChan chan *schema.MetricDefinition) {
counter := 0
pre := time.Now()
for def := range defsChan {
qry := `INSERT INTO metric_idx (id, orgid, partition, name, metric, interval, unit, mtype, tags, lastupdate) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
qry := `INSERT INTO metric_idx (id, orgid, partition, name, interval, unit, mtype, tags, lastupdate) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`
if *dryRun {
fmt.Printf(
"INSERT INTO metric_idx (id, orgid, partition, name, metric, interval, unit, mtype, tags, lastupdate) VALUES ('%s', '%d', '%d','%s', '%s','%d', '%s','%s', '%v', '%d')\n",
"INSERT INTO metric_idx (id, orgid, partition, name, interval, unit, mtype, tags, lastupdate) VALUES ('%s', '%d', '%d','%s', '%d', '%s','%s', '%v', '%d')\n",
def.Id,
def.OrgId,
def.Partition,
def.Name,
def.Metric,
def.Interval,
def.Unit,
def.Mtype,
Expand All @@ -109,7 +108,6 @@ func writeDefs(session *gocql.Session, defsChan chan *schema.MetricDefinition) {
def.OrgId,
def.Partition,
def.Name,
def.Metric,
def.Interval,
def.Unit,
def.Mtype,
Expand Down Expand Up @@ -143,14 +141,14 @@ func getDefs(session *gocql.Session, defsChan chan *schema.MetricDefinition) {
if err != nil {
log.Fatal(4, "failed to initialize partitioner. %s", err)
}
iter := session.Query("SELECT id, orgid, partition, name, metric, interval, unit, mtype, tags, lastupdate from metric_idx").Iter()
iter := session.Query("SELECT id, orgid, partition, name, interval, unit, mtype, tags, lastupdate from metric_idx").Iter()

var id, name, metric, unit, mtype string
var id, name, unit, mtype string
var orgId, interval int
var partition int32
var lastupdate int64
var tags []string
for iter.Scan(&id, &orgId, &partition, &name, &metric, &interval, &unit, &mtype, &tags, &lastupdate) {
for iter.Scan(&id, &orgId, &partition, &name, &interval, &unit, &mtype, &tags, &lastupdate) {
mkey, err := schema.MKeyFromString(id)
if err != nil {
log.Error(3, "could not parse ID %q: %s -> skipping", id, err)
Expand All @@ -161,7 +159,6 @@ func getDefs(session *gocql.Session, defsChan chan *schema.MetricDefinition) {
OrgId: orgId,
Partition: partition,
Name: name,
Metric: metric,
Interval: interval,
Unit: unit,
Mtype: mtype,
Expand Down
6 changes: 3 additions & 3 deletions cmd/mt-kafka-mdm-sniff-out-of-order/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ func newInputOOOFinder(format string) *inputOOOFinder {
}

func (ip *inputOOOFinder) ProcessMetricData(metric *schema.MetricData, partition int32) {
if *prefix != "" && !strings.HasPrefix(metric.Metric, *prefix) {
if *prefix != "" && !strings.HasPrefix(metric.Name, *prefix) {
return
}
if *substr != "" && !strings.Contains(metric.Metric, *substr) {
if *substr != "" && !strings.Contains(metric.Name, *substr) {
return
}
mkey, err := schema.MKeyFromString(metric.Id)
Expand Down Expand Up @@ -171,7 +171,7 @@ func main() {
fmt.Fprintln(os.Stderr, "for MetricData, prefix these with Md. : Time OrgId Id Name Metric Interval Value Unit Mtype Tags")
fmt.Fprintln(os.Stderr, "for MetricPoint, prefix these with Mp. : Time MKey Value")

// formatMd = flag.String("format-md", "{{.Part}} {{.OrgId}} {{.Id}} {{.Name}} {{.Metric}} {{.Interval}} {{.Value}} {{.Time}} {{.Unit}} {{.Mtype}} {{.Tags}}", "template to render MetricData with")
// formatMd = flag.String("format-md", "{{.Part}} {{.OrgId}} {{.Id}} {{.Name}} {{.Interval}} {{.Value}} {{.Time}} {{.Unit}} {{.Mtype}} {{.Tags}}", "template to render MetricData with")
// formatP = flag.String("format-point", "{{.Part}} {{.MKey}} {{.Value}} {{.Time}}", "template to render MetricPoint data with")
fmt.Fprintf(os.Stderr, "\nFlags:\n\n")
flag.PrintDefaults()
Expand Down
6 changes: 3 additions & 3 deletions cmd/mt-kafka-mdm-sniff/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

var (
confFile = flag.String("config", "/etc/metrictank/metrictank.ini", "configuration file path")
formatMd = flag.String("format-md", "{{.Part}} {{.OrgId}} {{.Id}} {{.Name}} {{.Metric}} {{.Interval}} {{.Value}} {{.Time}} {{.Unit}} {{.Mtype}} {{.Tags}}", "template to render MetricData with")
formatMd = flag.String("format-md", "{{.Part}} {{.OrgId}} {{.Id}} {{.Name}} {{.Interval}} {{.Value}} {{.Time}} {{.Unit}} {{.Mtype}} {{.Tags}}", "template to render MetricData with")
formatP = flag.String("format-point", "{{.Part}} {{.MKey}} {{.Value}} {{.Time}}", "template to render MetricPoint data with")
prefix = flag.String("prefix", "", "only show metrics that have this prefix")
substr = flag.String("substr", "", "only show metrics that have this substring")
Expand Down Expand Up @@ -54,10 +54,10 @@ func newInputPrinter(formatMd, formatP string) inputPrinter {
}

func (ip inputPrinter) ProcessMetricData(metric *schema.MetricData, partition int32) {
if *prefix != "" && !strings.HasPrefix(metric.Metric, *prefix) {
if *prefix != "" && !strings.HasPrefix(metric.Name, *prefix) {
return
}
if *substr != "" && !strings.Contains(metric.Metric, *substr) {
if *substr != "" && !strings.Contains(metric.Name, *substr) {
return
}
stdoutLock.Lock()
Expand Down
1 change: 0 additions & 1 deletion cmd/mt-whisper-importer-reader/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ func getMetric(w *whisper.Whisper, file, name string) (archive.Metric, error) {

md := schema.MetricData{
Name: name,
Metric: name,
Interval: int(w.Header.Archives[0].SecondsPerPoint),
Value: 0,
Unit: "unknown",
Expand Down
4 changes: 2 additions & 2 deletions cmd/mt-whisper-importer-writer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ func (s *Server) chunksHandler(w http.ResponseWriter, req *http.Request) {
}

log.Debugf(
"Receiving Id:%s OrgId:%d Metric:%s AggMeth:%d ArchCnt:%d",
metric.MetricData.Id, metric.MetricData.OrgId, metric.MetricData.Metric, metric.AggregationMethod, len(metric.Archives))
"Receiving Id:%s OrgId:%d Name:%s AggMeth:%d ArchCnt:%d",
metric.MetricData.Id, metric.MetricData.OrgId, metric.MetricData.Name, metric.AggregationMethod, len(metric.Archives))

if len(metric.Archives) == 0 {
throwError("Metric has no archives")
Expand Down
12 changes: 5 additions & 7 deletions idx/cassandra/cassandra.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,24 +376,24 @@ func (c *CasIdx) rebuildIndex() {
}

func (c *CasIdx) Load(defs []schema.MetricDefinition, cutoff uint32) []schema.MetricDefinition {
iter := c.session.Query("SELECT id, orgid, partition, name, metric, interval, unit, mtype, tags, lastupdate from metric_idx").Iter()
iter := c.session.Query("SELECT id, orgid, partition, name, interval, unit, mtype, tags, lastupdate from metric_idx").Iter()
return c.load(defs, iter, cutoff)
}

func (c *CasIdx) LoadPartition(partition int32, defs []schema.MetricDefinition, cutoff uint32) []schema.MetricDefinition {
iter := c.session.Query("SELECT id, orgid, partition, name, metric, interval, unit, mtype, tags, lastupdate from metric_idx where partition=?", partition).Iter()
iter := c.session.Query("SELECT id, orgid, partition, name, interval, unit, mtype, tags, lastupdate from metric_idx where partition=?", partition).Iter()
return c.load(defs, iter, cutoff)
}

func (c *CasIdx) load(defs []schema.MetricDefinition, iter cqlIterator, cutoff uint32) []schema.MetricDefinition {
defsByNames := make(map[string][]*schema.MetricDefinition)
var id, name, metric, unit, mtype string
var id, name, unit, mtype string
var orgId, interval int
var partition int32
var lastupdate int64
var tags []string
cutoff64 := int64(cutoff)
for iter.Scan(&id, &orgId, &partition, &name, &metric, &interval, &unit, &mtype, &tags, &lastupdate) {
for iter.Scan(&id, &orgId, &partition, &name, &interval, &unit, &mtype, &tags, &lastupdate) {
mkey, err := schema.MKeyFromString(id)
if err != nil {
log.Error(3, "cassandra-idx: load() could not parse ID %q: %s -> skipping", id, err)
Expand All @@ -405,7 +405,6 @@ func (c *CasIdx) load(defs []schema.MetricDefinition, iter cqlIterator, cutoff u
OrgId: orgId,
Partition: partition,
Name: name,
Metric: metric,
Interval: interval,
Unit: unit,
Mtype: mtype,
Expand Down Expand Up @@ -441,7 +440,7 @@ func (c *CasIdx) processWriteQueue() {
var attempts int
var err error
var req writeReq
qry := `INSERT INTO metric_idx (id, orgid, partition, name, metric, interval, unit, mtype, tags, lastupdate) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
qry := `INSERT INTO metric_idx (id, orgid, partition, name, interval, unit, mtype, tags, lastupdate) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`
for req = range c.writeQueue {
if err != nil {
log.Error(3, "Failed to marshal metricDef. %s", err)
Expand All @@ -459,7 +458,6 @@ func (c *CasIdx) processWriteQueue() {
req.def.OrgId,
req.def.Partition,
req.def.Name,
req.def.Metric,
req.def.Interval,
req.def.Unit,
req.def.Mtype,
Expand Down
25 changes: 6 additions & 19 deletions idx/cassandra/cassandra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ type cassRow struct {
orgId int
partition int32
name string
metric string
interval int
unit string
mtype string
Expand All @@ -37,7 +36,7 @@ func (i *testIterator) Scan(dest ...interface{}) bool {
return false
}

if len(dest) < 10 {
if len(dest) < 9 {
return false
}

Expand All @@ -46,12 +45,11 @@ func (i *testIterator) Scan(dest ...interface{}) bool {
*(dest[1].(*int)) = row.orgId
*(dest[2].(*int32)) = row.partition
*(dest[3].(*string)) = row.name
*(dest[4].(*string)) = row.metric
*(dest[5].(*int)) = row.interval
*(dest[6].(*string)) = row.unit
*(dest[7].(*string)) = row.mtype
*(dest[8].(*[]string)) = row.tags
*(dest[9].(*int64)) = row.lastUpdate
*(dest[4].(*int)) = row.interval
*(dest[5].(*string)) = row.unit
*(dest[6].(*string)) = row.mtype
*(dest[7].(*[]string)) = row.tags
*(dest[8].(*int64)) = row.lastUpdate

i.rows = i.rows[1:]

Expand Down Expand Up @@ -113,7 +111,6 @@ func getMetricData(orgId, depth, count, interval int, prefix string) []*schema.M

data[i] = &schema.MetricData{
Name: s,
Metric: s,
OrgId: orgId,
Interval: interval,
}
Expand Down Expand Up @@ -452,7 +449,6 @@ func insertDefs(ix idx.MetricIndex, i int) {
series = "some.metric." + strconv.Itoa(n)
data = &schema.MetricData{
Name: series,
Metric: series,
Interval: 10,
OrgId: 1,
}
Expand Down Expand Up @@ -528,7 +524,6 @@ func BenchmarkIndexingWithUpdates(b *testing.B) {
series = "some.metric." + strconv.Itoa(n)
data = &schema.MetricData{
Name: series,
Metric: series,
Interval: 10,
OrgId: 1,
Time: 10,
Expand Down Expand Up @@ -556,7 +551,6 @@ func TestPruneStaleOnLoad(t *testing.T) {
orgId: 1,
partition: 1,
name: "met1",
metric: "met1",
interval: 1,
lastUpdate: 1,
})
Expand All @@ -565,7 +559,6 @@ func TestPruneStaleOnLoad(t *testing.T) {
orgId: 1,
partition: 1,
name: "met1",
metric: "met1",
interval: 3,
lastUpdate: 2,
})
Expand All @@ -574,7 +567,6 @@ func TestPruneStaleOnLoad(t *testing.T) {
orgId: 1,
partition: 1,
name: "met2",
metric: "met2",
interval: 1,
lastUpdate: 1,
})
Expand All @@ -583,7 +575,6 @@ func TestPruneStaleOnLoad(t *testing.T) {
orgId: 1,
partition: 1,
name: "met2",
metric: "met2",
interval: 3,
lastUpdate: 1,
})
Expand All @@ -609,7 +600,6 @@ func TestPruneStaleOnLoadWithTags(t *testing.T) {
orgId: 1,
partition: 1,
name: "met1",
metric: "met1",
interval: 1,
lastUpdate: 1,
tags: []string{"tag1=val1"},
Expand All @@ -619,7 +609,6 @@ func TestPruneStaleOnLoadWithTags(t *testing.T) {
orgId: 1,
partition: 1,
name: "met1",
metric: "met1",
interval: 2,
lastUpdate: 2,
tags: []string{"tag1=val1"},
Expand All @@ -629,7 +618,6 @@ func TestPruneStaleOnLoadWithTags(t *testing.T) {
orgId: 1,
partition: 1,
name: "met1",
metric: "met1",
interval: 3,
lastUpdate: 1,
tags: []string{"tag1=val1;tag2=val2"},
Expand All @@ -639,7 +627,6 @@ func TestPruneStaleOnLoadWithTags(t *testing.T) {
orgId: 1,
partition: 1,
name: "met1",
metric: "met1",
interval: 4,
lastUpdate: 1,
tags: []string{"tag1=val1;tag2=val2"},
Expand Down
Loading

0 comments on commit 8dec28c

Please sign in to comment.