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

Meta tags part1: meta record data structures and corresponding CRUD api calls #1301

Merged
merged 14 commits into from
May 8, 2019

Conversation

replay
Copy link
Contributor

@replay replay commented May 4, 2019

This is the first of multiple PRs to implement that meta tag feature.
The commits in this PR are also part of #960. I'm planning to merge the meta tag feature in multiple steps where each step is smaller and easier to review than merging the whole feature in one gigantic PR.

This PR adds the meta record data structure which keeps the definitions of the meta tags. It also adds the necessary API calls to add/upset/delete meta records. These structures will only become effective with future PRs, at the moment modifying them has no effect.

adds the data structures to store meta records and also the necessary
methods and api calls to insert/edit/delete them.
there are also unit tests to test the meta record modifications
@replay replay changed the title [WIP] Meta records Meta records May 7, 2019
@@ -9,7 +9,7 @@ import (
"github.com/grafana/metrictank/idx"
pickle "github.com/kisielk/og-rek"
opentracing "github.com/opentracing/opentracing-go"
"gopkg.in/macaron.v1"
macaron "gopkg.in/macaron.v1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vscode in the default settings uses goreturns to format the code on saving. that's documented here: https://github.com/Microsoft/vscode-go/wiki/On-Save-features#format-on-save
if you want I can disable that, or switch it to gofmt which doesn't add the import name explicitly even if the package name differs from the import path.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think goreturns is to blame here, something else is going on

go get -u github.com/sqs/goreturns && goreturns -w api/routes.go && grep macaron.v1 api/routes.go

	"gopkg.in/macaron.v1"

Copy link
Contributor Author

@replay replay May 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's strange, because i've tested that too before I wrote the last comment:

mst@mst-nb1:~/documents/code/go/src/github.com/grafana/metrictank$ cat api/models/graphite.go | grep macaron.v1
        "gopkg.in/macaron.v1"
mst@mst-nb1:~/documents/code/go/src/github.com/grafana/metrictank$ gofmt api/models/graphite.go | grep macaron.v1
        "gopkg.in/macaron.v1"
mst@mst-nb1:~/documents/code/go/src/github.com/grafana/metrictank$ goreturns api/models/graphite.go | grep macaron.v1
        macaron "gopkg.in/macaron.v1"

I think my goreturns has been installed by vscode. Maybe that installed a different version or default config or something like that. i'll try to figure out where this is defined

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after doing go get -u github.com/sqs/goreturns it doesn't do that anymore. i guess something must have changed in the newer version. anyway, i'll undo those changes that the old version made

// The first slice of strings has the meta tags & values
// The second slice has the tag query expressions which the meta tags & values refer to
// On parsing error the second returned value is an error, otherwise it is nil
func metaTagRecordFromStrings(metaTags []string, tagQueryExpressions []string) (metaTagRecord, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe i'm missing something, but wouldn't it be cleaner to validate much earlier? typically validation happens in the rest api layer. e.g. on the models or one of the first things in the http handler. seems we're quite deep into the callpath already here with potentially invalid data, seems weird

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The suggestion to move the parsing/validation to an earlier stage makes sense. At the moment this is here for consistency with all the other tag query methods, such as:

func (m *UnpartitionedMemoryIdx) FindByTag(orgId uint32, expressions []string, from int64) ([]idx.Node, error) {

It would probably make sense to move the whole expression parsing/validation for all the tag query handling methods to an earlier stage in the request handling. But I wouldn't want to do that in this PR, otherwise this PR will also need to modify a lot of the existing tag query call-paths.

record, created, err = m.MetaTagRecordUpsert(orgId, rawRecord)
} else {
_, _, err = m.MetaTagRecordUpsert(orgId, rawRecord)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are not closing over the m variable correctly.
run this and then try without the m := m line

package main

import (
	"context"
	"fmt"
	"time"

	"golang.org/x/sync/errgroup"
)

func main() {
	g, _ := errgroup.WithContext(context.Background())
	parts := []int{0, 1, 2, 3, 4, 5}
	for _, m := range parts {
		m := m
		g.Go(func() error {
			fmt.Println(m)
			return nil
		})
	}
	time.Sleep(time.Second)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch

replay and others added 8 commits May 7, 2019 13:56
1) don't expose the id to the user, as this information is not useful
2) use recordId type for record ids, instead of uint32
3) rename variables that call the record id "hash" to id, also update
   many comments accordingly
Co-Authored-By: replay <mauro.stettler@gmail.com>
@replay
Copy link
Contributor Author

replay commented May 7, 2019

I think I've addressed every comment. @Dieterbe, please take another look when you get a chance.

@Dieterbe Dieterbe changed the title Meta records Meta tags part1: meta record data structures and corresponding CRUD api calls May 8, 2019
@Dieterbe Dieterbe merged commit 65d50bf into master May 8, 2019
@Dieterbe Dieterbe deleted the meta_records branch May 8, 2019 13:30
@Dieterbe
Copy link
Contributor

Dieterbe commented May 8, 2019

see #660

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants