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

Importer with bigtable support #1291

Merged
merged 4 commits into from
May 21, 2019
Merged

Importer with bigtable support #1291

merged 4 commits into from
May 21, 2019

Conversation

replay
Copy link
Contributor

@replay replay commented Apr 24, 2019

Modifies the whisper-importer-reader and writer utilities so they:

  1. use chunk write requests to send the data from the reader to the writer, which makes it easier to plug any store into the writer that satisfies the mdata.Store interface
  2. support bigtable as a store and as an index, both can be chosen separately

Unfortunately some of the arguments that need to be passed to the writer had to be changed, so the invocation will need to be updated (HM-API).

It requires some of the data structures in github.com/raintank/schema to be msgp marshalable, which they currently aren't. Once this PR is accepted I'll create an according PR there.

This is not tested yet.

This already includes the PR #1290, once that one is merged this diff will be shorter

@replay replay changed the title [WIP] Importer bigtable [WIP] Importer with bigtable support Apr 24, 2019
@replay replay force-pushed the importer_bigtable branch 3 times, most recently from 39f8294 to bb424c2 Compare April 24, 2019 20:41
adjustedPoints["sum"] = make(map[uint32]float64)
adjustedPoints := make(map[schema.Method]map[uint32]float64)
if retIdx > 0 && c.method == schema.Avg || c.method == schema.Sum {
adjustedPoints[schema.Cnt] = make(map[uint32]float64)
Copy link
Member

Choose a reason for hiding this comment

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

why do we keep a count aggregation if all the user wants is 'sum'?

Copy link
Contributor Author

@replay replay Apr 25, 2019

Choose a reason for hiding this comment

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

I think that was because that way we can also serve average queries

Copy link
Member

Choose a reason for hiding this comment

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

we should stop doing that. The "count" value we are storing will be wrong any time the original metrics stream had null points. eg, if the raw interval is 1min and their is a 10min SUM rollup, we cant assume that the sum is the result of 10 points. It could be the result of anywhere from 0-10 points.

But maybe we should address this problem in a followup PR.

@replay replay force-pushed the importer_bigtable branch 2 times, most recently from 79a8919 to 63bc54d Compare April 25, 2019 17:23
@replay replay force-pushed the importer_bigtable branch from efe2dcd to 84217de Compare April 26, 2019 02:30
mdata/cwr.go Outdated
return errors.New(fmt.Sprintf("ERROR: Creating Gzip reader: %q", err))
}

raw, err := ioutil.ReadAll(gzipReader)
Copy link
Member

Choose a reason for hiding this comment

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

There is no need to load the uncompressed data into memory, msgp can decode from a io.Reader directly.
eg,

err := msgp.Decode(gzipReader, a)

@replay
Copy link
Contributor Author

replay commented Apr 26, 2019

Thx for all the comments @woodsaj , will fix everything. What do you think about that I replaced the CLI flags with the same configuration method like what MT is using in 84217de? I figured that way it's going to be much easier to configure it from HM-API, because the majority of the store/index configs are just going to be the same as in the MT write deployments.

@woodsaj
Copy link
Member

woodsaj commented Apr 26, 2019

What do you think about that I replaced the CLI flags with the same configuration method like what MT is using

I love it.

@replay replay force-pushed the importer_bigtable branch 4 times, most recently from b80bfd7 to d2aaaf2 Compare April 26, 2019 18:15
mdata/cwr.go Outdated
versionBuf := make([]byte, 1)
readBytes, err := b.Read(versionBuf)
if err != nil || readBytes != 1 {
return errors.New(fmt.Sprintf("ERROR: Failed to read one byte: %s", err))
Copy link
Member

Choose a reason for hiding this comment

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

instead of errors.New(fmt.Sprintf(... you can just use fmt.Errorf(

@replay
Copy link
Contributor Author

replay commented May 8, 2019

I first redeployed my test instance in the QA cluster and made it use BigTable as index & store, then I imported 5 test metrics from generated whisper files, after restarting the read MT they showed up correctly.
Then I redeployed the instance and made it use Cassandra and imported the same test metrics into Cassandra, after restarting the read MT they again showed up correctly.

@Dieterbe
Copy link
Contributor

Dieterbe commented May 9, 2019

just fix my last comment,
and also why is anything changing in the vendor dir?
seems that in one place we removed an import for github.com/raintank/schema , andthen elsewhere introduced it again, so why are we making changes to it?

@replay
Copy link
Contributor Author

replay commented May 9, 2019

@Dieterbe regarding the changes in the vendor dir. because now we need the schema.AMKey and its member the schema.Archive to be marshallable (if that's a verb). I mentioned that in the top message: #1291 (comment)
I'll create a PR to raintank/schema as soon as we're sure that this is the final solution that we want.

@Dieterbe
Copy link
Contributor

Dieterbe commented May 9, 2019

oh! well, when i came up with schema.Archive, MKey, Key, etc my idea was that these would all be internal implementation details that could be changed at any time because their exact values would only stay inside of a process, and never be serialized and sent in network requests.

For serialisation I think think we should use the string representation of the keys (e.g. 'orgid.deadbeef_sum_60'). this makes it easier to inspect them on the wire too

@replay
Copy link
Contributor Author

replay commented May 9, 2019

For serialisation I think think we should use the string representation of the keys (e.g. 'orgid.deadbeef_sum_60').

That would mean we couldn't use mdata.ChunkWriteRequest anymore. We'd have to build some kind of struct which is basically the same, with the only difference being that it uses a string for the key. I thought one of the "nice" things in this PR is that it makes everything very short and concise, because we can directly transmit the cwrs, so we'd then lose that benefit.

@Dieterbe
Copy link
Contributor

Dieterbe commented May 9, 2019

That would mean we couldn't use mdata.ChunkWriteRequest anymore. We'd have to build some kind of struct which is basically the same, with the only difference being that it uses a string for the key.

you're conflating a struct and its serialized representation.
you can totally use mdata.ChunkWriteRequest, but when serializing and deserializing, use the string representation of the AMKey. this may involve a tweak to AMKey to use its string representation in the msgp methods, i'm not sure what's the concrete way to do it.

@replay
Copy link
Contributor Author

replay commented May 9, 2019

@Dieterbe i think you're right, I'll try that

@replay
Copy link
Contributor Author

replay commented May 9, 2019

@Dieterbe how's this: 39123b1
Or would you prefer if I try to find a way to implement the same thing without modifying raintank/schema at all? I think this would probably be possible by writing a similar extension for the ChunkWriteRequest type, it would just be a bit more complicated than this solution and I figured maybe somebody else also wants to encode the AMKey as string.

@Dieterbe
Copy link
Contributor

looks good, but there's 2 things left in schema that still need to be cleaned up:
Archive should not need any msgp code, and neither should Point, as far as i can see.

is it correct to say the only change in the schema library should be that we add msgp encoding to the AMKey (by serializing it to its string representation) ?

Also, the commit history has lots of back and forth, can we "compact" the commits (via git rebase -i)
it should ultimately be 2 or 3 commits:

  1. the switch to using CWR for the importer, and all its corresponding changes in tests etc
  2. the change in how we handle config management
  3. (updates to docs/tools.md though that could be part of the 1/2 as well)

I suggest give it a shot, and see how far it can be cleaned up (i tend to do many runs of git rebase -i, each time squashing some commits together, until it becomes clear that i'll hit a merge conflict, or if i hit a merge conflict during rebasing i then just do git rebase --abort. if you do many smaller runs that still leaves you with the cleaned up history from previous runs)

@replay replay force-pushed the importer_bigtable branch 3 times, most recently from 9669930 to d8d8891 Compare May 12, 2019 02:18
@replay
Copy link
Contributor Author

replay commented May 12, 2019

is it correct to say the only change in the schema library should be that we add msgp encoding to the AMKey (by serializing it to its string representation) ?

I also fixed a typo in an error message and msgp generated a bunch of tests for that extension, otherwise that's right. If this PR is accepted I can create a PR to raintank/schema with those changes. There I can create separate commits for the typo and the msgp stuff. Then, once that's merged, we can just update the vendored raintank/schema to the latest master and there shouldn't be any code changes only the revision hash should change.

I fixed up the git history. Usually I do that by just squashing all changes into one commit, then I go back and edit that commit and use either git add -p or the + in vscode to add change by change and create separate commits that way (basically splitting it).
I made sure that even the first one of those two commits, without the second one, compiles. But it won't be useful, because it's not configurable. Only both together are useful.

@Dieterbe
Copy link
Contributor

Dieterbe commented May 12, 2019

so why does your PR still introduce a bunch of other files like point_gen_test.go and metric_gen_test.go ?
once we're only making the changes to schema that we need, and nothing else, this is all good to go
( the change to method_string.go is fine, that's due to a new stringer version)

@replay replay force-pushed the importer_bigtable branch 2 times, most recently from f5a6ed3 to f8a3927 Compare May 13, 2019 15:57
replay added 2 commits May 13, 2019 16:01
when transferring the data between the whisper-importer-reader and
-writer we now use the same chunk write request type that metrictank
uses internally when submitting writes to its stores. this makes it
easier to add other store types to the importer-writer if we add more to
metrictank in the future.
futhermore, it modifies the chunk write requests so they include a
callback to be called when a chunk has been written. this helps to
decouple the mdata package from the store package by letting the
instantiator of the chunk write request adding any generic callback to
it.
this makes the configuration of the importer-writer consistent with the
way how MT and other MT-tools are configured. this makes sense to do now
because with the added support for the bigtable store and index the
configuration would get too complex if we'd try to come up with a way to
configure all of that via cli arguments, so its easier and more consistent
to just do it in the same way like everything else.
@replay replay force-pushed the importer_bigtable branch from f8a3927 to b0327ee Compare May 13, 2019 16:02
@replay
Copy link
Contributor Author

replay commented May 13, 2019

@Dieterbe I cleaned it up, please take another look
I previously regenerated the files by doing go generate vendor/github.com/raintank/schema/*.go, which also generated the tests, but usually those don't get vendored. I removed the tests now.

@replay replay force-pushed the importer_bigtable branch from c74a83b to 0461e94 Compare May 16, 2019 22:31
@replay
Copy link
Contributor Author

replay commented May 16, 2019

I found a critical bug and fixed it and added a test that covers it:
0461e94#diff-2f8bddc453c2ba697972cbeff0844d5fL86

it took me forever to find that, i only saw that some metrics looked weird because certain chunks which were supposed to be archive chunks overwrote some raw chunks, but not always....

after fixing it i did some more test imports with cassandra and bigtable backends, and it all looks fine

@Dieterbe
Copy link
Contributor

yep please patch in schema so we can merge there, introduce here cleanly, and merge here.

@replay replay merged commit 7dafad7 into master May 21, 2019
@Dieterbe Dieterbe deleted the importer_bigtable branch May 27, 2019 07:21
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.

3 participants