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

Make the importer utilities rely on TSDB-GW for authentication and org-association #1335

Merged
merged 6 commits into from
Jun 17, 2019

Conversation

replay
Copy link
Contributor

@replay replay commented May 28, 2019

This change makes the importer rely on tsdb-gw to authenticate the incoming requests and associate them with an org-id based on the user the authenticated as.
It also creates a new mdata/importer package which contains all the importer data conversion logic and the related structs for sending the data over the wire.

fixes #1334

@replay replay force-pushed the limit_writer_org branch 2 times, most recently from e20989d to b9ecb6a Compare May 28, 2019 23:35
@@ -33,6 +33,7 @@ var (
uriPath = flag.String("uri-path", "/chunks", "the URI on which we expect chunks to get posted")
numPartitions = flag.Int("num-partitions", 1, "Number of Partitions")
logLevel = flag.String("log-level", "info", "log level. panic|fatal|error|warning|info|debug")
orgId = flag.Int("org-id", -1, "the id of the org we import to")
Copy link
Member

Choose a reason for hiding this comment

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

I think we should set the default to '0', which should mean dont do org-id check.

@replay
Copy link
Contributor Author

replay commented May 31, 2019

I pushed quite a different implementation, as discussed in #1334
It's not very well tested yet, will do that tomorrow. And I'll still need to fix the unit tests.

@replay
Copy link
Contributor Author

replay commented May 31, 2019

Just like last time, Once this is accepted I'll create a PR to raintank/schema for those changes and once it's merged there I'll update the vendored raintank/schema here.

@replay replay force-pushed the limit_writer_org branch 2 times, most recently from 61673e0 to f8743a2 Compare June 3, 2019 14:25
@@ -27,7 +29,8 @@ import (
var (
confFile = flag.String("config", "/etc/metrictank/metrictank.ini", "configuration file path")
exitOnError = flag.Bool("exit-on-error", false, "Exit with a message when there's an error")
httpEndpoint = flag.String("http-endpoint", "127.0.0.1:8080", "The http endpoint to listen on")
listenAddress = flag.String("listen-address", "127.0.0.1", "The address to listen on")
listenPort = flag.Int("listen-port", 8080, "The port to listen on")
ttlsStr = flag.String("ttls", "35d", "list of ttl strings used by MT separated by ','")
partitionScheme = flag.String("partition-scheme", "bySeries", "method used for partitioning metrics. This should match the settings of tsdb-gw. (byOrg|bySeries)")
uriPath = flag.String("uri-path", "/chunks", "the URI on which we expect chunks to get posted")
Copy link
Contributor

Choose a reason for hiding this comment

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

uriPath needs updating to "/metrics/import"

mdata/cwr.go Outdated
return ChunkWriteRequest{ChunkWriteRequestPayload{ttl, t0, data, ts}, callback, key}
}

// ChunkWriteRequestWithoutOrg is used by the importer utility to send cwrs over the network
Copy link
Contributor

Choose a reason for hiding this comment

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

if you need to document a structure in mdata that it's [only] used by a specific tool, then we should just move that structure to a package for that tool.
e.g. create a package importer and create a ChunkWriteRequest type in there?

Copy link
Contributor

Choose a reason for hiding this comment

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

all of cmd/mt-whisper-importer-reader/conversion.go should go into an importer package as well, cmd is meant for the main program code.

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 idea. where would you suggest i put that importer package? should that live in mdata since it is all kind of related to data handling & conversion?

Copy link
Contributor

@Dieterbe Dieterbe Jun 7, 2019

Choose a reason for hiding this comment

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

sounds good, if you don't run into circular import problems

@@ -27,7 +29,8 @@ import (
var (
confFile = flag.String("config", "/etc/metrictank/metrictank.ini", "configuration file path")
exitOnError = flag.Bool("exit-on-error", false, "Exit with a message when there's an error")
httpEndpoint = flag.String("http-endpoint", "127.0.0.1:8080", "The http endpoint to listen on")
listenAddress = flag.String("listen-address", "127.0.0.1", "The address to listen on")
listenPort = flag.Int("listen-port", 8080, "The port to listen on")
Copy link
Contributor

Choose a reason for hiding this comment

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

why are you changing this? the commit message "importer transfers cwrs without org" doesn't give any clues..
why not keep this consistent with http.listen? (the config option used for MT to establish its listen address and port)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right, i think this temporarily made sense during some older revision, but now not anymore. changing it back


// SerializableChunkWriteRequest is used by the importer utility to send cwrs over the network
// It does not contain the org id because this is assumed to be defined by the auth mechanism
type SerializableChunkWriteRequest struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

"serializable" is not helpful because pretty much all datastructures are serializable .
I would just stick with the name ChunkWriteRequest, the fact that this is in the importer package already gives a solid clue that this CWR type is specific to the importer.
You can see the same pattern in stdlib, for example https://golang.org/pkg/html/template/#Template and https://golang.org/pkg/text/template/#Template

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For example the .Callback property of the mdata.ChunkWriteRequest is not serializable because that's a memory address. But I'm fine either way, I'll rename it back to ChunkWriteRequest

@replay replay changed the title limit importer-writer to specific org id Make the importer utilities rely on TSDB-GW for authentication and org-association Jun 10, 2019
@replay replay force-pushed the limit_writer_org branch 5 times, most recently from c43e9fe to ebf5284 Compare June 11, 2019 01:21
@replay
Copy link
Contributor Author

replay commented Jun 11, 2019

I've moved all the importer-related logic into the importer package, please take another look

@replay replay force-pushed the limit_writer_org branch 2 times, most recently from 0053fd1 to 8b99e7f Compare June 12, 2019 17:00
@replay
Copy link
Contributor Author

replay commented Jun 12, 2019

FYI I've done another test import with the latest version of the writer & reader, once into BigTable and once into Cassandra, and they both look as expected.

@Dieterbe
Copy link
Contributor

#!/bin/bash -eo pipefail
scripts/qa/docs.sh
checking tools
709c709
<     	The http endpoint to listen on (default "127.0.0.1:8080")
---
>     	The http endpoint to listen on (default "0.0.0.0:8080")
docs/tools.md does not match output of scripts/dev/tools-to-doc.sh
Exited with code 2

these two changes were in reaction to PR comments
also move all the related tests
keep incResolution() and decResolution() as stand-alone functions
because that way they're way more testable than if they were an
integrated method of the conversion type
the instantiation of the ArchiveRequest struct should be located
together with the struct definition, this moves it there
@replay
Copy link
Contributor Author

replay commented Jun 12, 2019

sorry about that, fixed the docs

@replay replay mentioned this pull request Jun 14, 2019
Copy link
Contributor

@Dieterbe Dieterbe left a comment

Choose a reason for hiding this comment

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

LGTM. i didn't look very thoroughly, but you've tested this fairly well right? then i think this is good to go

@Dieterbe Dieterbe merged commit a4bc9e1 into master Jun 17, 2019
@Dieterbe Dieterbe deleted the limit_writer_org branch June 17, 2019 21:08
@replay
Copy link
Contributor Author

replay commented Jun 18, 2019

Cool, thx. Yeah, I've done multiple test imports

@replay
Copy link
Contributor Author

replay commented Jun 18, 2019

I didn't update the vendored raintank/schema yet (#1335 (comment)). I'll make a PR for that, because otherwise the build is broken

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.

We need to be able to restrict the whisper importer utility to a single org
3 participants