Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EXPLAIN ANALYZE implementation #8947

Merged
merged 1 commit into from
Oct 20, 2017
Merged

EXPLAIN ANALYZE implementation #8947

merged 1 commit into from
Oct 20, 2017

Conversation

stuartcarnie
Copy link
Contributor

EXPLAIN ANALYZE SELECT ... will measure a number of counters whilst
executing the query. All data is processed, providing an accurate
account of blocks that were decoded, cursors created for each
expression in a SELECT statement.

The total planning and execution times are measured.

Required for all non-trivial PRs
  • Rebased/mergable
  • Tests pass
  • CHANGELOG.md updated

@stuartcarnie
Copy link
Contributor Author

@jsternberg I've broken the PR into multiple commits so it is easier for you to see the changes

@stuartcarnie
Copy link
Contributor Author

Example output

Godeps Outdated
@@ -17,8 +17,10 @@ github.com/peterh/liner 88609521dc4b6c858fd4c98b628147da928ce4ac
github.com/philhofer/fwd 1612a298117663d7bc9a760ae20d383413859798
github.com/retailnext/hllpp 38a7bb71b483e855d35010808143beaf05b67f9d
github.com/spaolacci/murmur3 0d12bf811670bf6a1a63828dfbd003eded177fce
github.com/stretchr/testify 890a5c3458b43e6104ff5da8dfa139d013d77544
Copy link
Contributor

Choose a reason for hiding this comment

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

Unless there's a compelling reason, I would prefer we didn't add a testing framework. Is this from custom code or is it a dependency on some copied code?

Copy link
Contributor Author

@stuartcarnie stuartcarnie Oct 19, 2017

Choose a reason for hiding this comment

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

I agree with not using other testing packages. This package is included only to leverage the assertion package testify/assert. It removes a lot of noise from unit tests when asserting for expected behavior / values. If the assertion fails, it will generate a standard t.Error, t.Fail, etc. For more complex types, like collections, diffs will also be produced.

testify/assert contains APIs for simplifying a number of scenarios and uses the standard Go *testing.T type to report errors or failures. Some example

  • assert.PanicsWithValue – asserts the code panics and returns an expected value. Much simpler than writing defers, etc

Others I like include:

  • assert.NotNil
  • assert.NoError
  • assert.Empty
  • assert.Equal

This little introduction is helpful. You can also review the docs for the available assertions.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm aware of this testing package. But, we don't use it anywhere else and I don't like the idea of including an additional dependency for only one section of code. Introducing this likely means that it will start being used in other locations and the unit tests won't have the same pattern anymore. They don't currently, but adding additional unit test patterns to a code base that already has a bunch seems like too much to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed in favor of pkg/testing/assert

@@ -18,11 +18,15 @@ import (
"sync/atomic"
"time"

"strconv"
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be grouped with the other imports. I've noticed Gogland seems to do this a lot.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -74,7 +75,7 @@ func TestLocalShardMapper(t *testing.T) {
t.Fatalf("unexpected number of shard mappings: %d", len(m.ShardMap))
}

if _, err := ic.CreateIterator(measurement, query.IteratorOptions{}); err != nil {
if _, err := ic.CreateIterator(context.TODO(), measurement, query.IteratorOptions{}); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you modify these various context.TODO() calls to what they're supposed to be?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll change them to Background

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -0,0 +1,32 @@
package tracing
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a doc.go file to this package to explain the behavior? I think I've figured it out, but it's a bit confusing and I don't see very many doc comments.

If I'm correctly, you create a Trace at the beginning of the thing you want to trace. You then use the Span to create child spans. All spans are managed by the Trace and each Span only keeps track of its own level. It does not keep track of anything else.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

@jsternberg jsternberg left a comment

Choose a reason for hiding this comment

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

Squash the commits and just one comment. I'm approving in advance.

@@ -25,3 +25,5 @@
- github.com/uber-go/zap [MIT LICENSE](https://github.com/uber-go/zap/blob/master/LICENSE.txt)
- golang.org/x/crypto [BSD LICENSE](https://github.com/golang/crypto/blob/master/LICENSE)
- jquery 2.1.4 [MIT LICENSE](https://github.com/jquery/jquery/blob/master/LICENSE.txt)
- github.com/xlab/treeprint [MIT LICENSE](https://github.com/xlab/treeprint/blob/master/LICENSE)
- github.com/stretchr/testify [MIT LICENSE](https://github.com/stretchr/testify/blob/master/LICENSE)
Copy link
Contributor

Choose a reason for hiding this comment

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

This license needs to be removed if we aren't using this dependency.

@e-dard e-dard added this to the 1.4.0 milestone Oct 20, 2017
* Introduces EXPLAIN ANALYZE command, which
  produces a detailed tree of operations used to
  execute the query.

introduce context.Context to APIs

metrics package

* create groups of named measurements
* safe for concurrent access

tracing package

EXPLAIN ANALYZE implementation for OSS

Serialize EXPLAIN ANALYZE traces from remote nodes

use context.Background for tests

group with other stdlib packages

additional documentation and remove unused API

use influxdb/pkg/testing/assert

remove testify reference
@stuartcarnie stuartcarnie merged commit 618f0d0 into master Oct 20, 2017
@ghost ghost removed the review label Oct 20, 2017
@stuartcarnie stuartcarnie deleted the sgc-explain branch October 20, 2017 15:35
@jsternberg jsternberg mentioned this pull request Jan 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants