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

cmd/smithtest: add sqlsmith auto tester and github filer #40453

Merged
merged 1 commit into from
Sep 25, 2019
Merged

cmd/smithtest: add sqlsmith auto tester and github filer #40453

merged 1 commit into from
Sep 25, 2019

Conversation

maddyblue
Copy link
Contributor

@maddyblue maddyblue commented Sep 4, 2019

smithtest is a CLI program for automating sqlsmith testing. It does normal
sqlsmith but via cockroach start-single-node, so found panics don't also
take down the test itself. Found errors are de-duplicated using existing
github issues. The reducer is used to minimize test repros. A new tab
is opened to github with most of the issue data filled in.

Use a pty package to enable interactive mode in cockroach, which prints
the sql address to stdout, enabling us to scrape it and connect there.

Release note: None

Release justification: Category 1: Non-production code changes

@maddyblue maddyblue requested review from solongordon, rafiss and a team September 4, 2019 02:34
@maddyblue maddyblue requested a review from a team as a code owner September 4, 2019 02:34
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@maddyblue maddyblue requested a review from knz September 4, 2019 05:59
@maddyblue
Copy link
Contributor Author

@knz can you review the CLI interactive change?

Copy link
Contributor

@knz knz left a comment

Choose a reason for hiding this comment

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

Yeah so I reviewed this and I strongly recommend against this approach.

  1. the interactive boolean does imply a few other things besides just printing the intro text, and you probably don't want those things to occur
  2. printing the connection URL on the message shown to all users of demo will erroneously suggest that cockroach demo starts a "server" that they can connect to from other tools, or even suggest that they must use an external tool to use it. I find this coutner-productive to the kind of UX we want to advertise for cockroach demo, and it may increase our support burden in unexpected ways.

Instead, please consider issuing the following SQL query via the command's stdin instead: select value from crdb_internal.node_runtime_info where component='DB' and field='URL'; which will give you that URL too.

Reviewed 3 of 5 files at r1.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @knz, @rafiss, and @solongordon)

@knz
Copy link
Contributor

knz commented Sep 4, 2019

In fact I'd go a step further and argue that hijacking cockroach demo, a tool that's inherently designed for human consumption and where we have 0% guarantee of UX stability, for the purpose of automated testing which does require some form of API stability, is not a good way to go.

I'd instead recommend building an executable program that sets up a cockroachdb test server like any unit test and prints the connection URL on its stderr, and have that custom executable driven by your sqlsmith command. They would live next to each other in the same package and this way you don't create a mandate for every contributor to cockroach demo to keep your testing tool in mind.

Copy link
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

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

i reviewed the internals of the new command, bu i defer to knz about COCKROACH_FORCE_INTERACTIVE

Reviewed 1 of 1 files at r2.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @mjibson, @rafiss, and @solongordon)


pkg/cmd/smithtest/main.go, line 68 at r2 (raw file):

	rand.Seed(timeutil.Now().UnixNano())

	// Prepopulate seen issues from GitHub.

nit: populating seen issues could be extracted to a separate function


pkg/cmd/smithtest/main.go, line 71 at r2 (raw file):

	var opts github.SearchOptions
	for {
		results, _, err := setup.github.Search.Issues(ctx, "is:issue is:open label:C-bug label:O-sqlsmith", &opts)

i haven't used this github client library, so i might be missing something. how is this search being restricted to only the cockroachdb repo?


pkg/cmd/smithtest/main.go, line 98 at r2 (raw file):

// Setup contains initialization and configuration for running smithers.
type Setup struct {

nit: the name Setup doesn't really seem descriptive to me, but i also just may not know the naming conventions for stuff like this in go. perhaps a name like WorkerSetup or even WorkerPool? also, does the type need to be exported?


pkg/cmd/smithtest/main.go, line 228 at r2 (raw file):

	// it takes for a single reduction run.
	lock syncutil.RWMutex
	seen = map[string]bool{}

nit: it could be helpful to declare these earlier in the file, since i notice they are used earlier. and perhaps add a comment to seen


pkg/cmd/smithtest/main.go, line 289 at r2 (raw file):

		RawQuery: query.Encode(),
	}
	const max = 8000

just curious: do most issue bodies with stacktraces fit into this limit?

@knz
Copy link
Contributor

knz commented Sep 10, 2019

question from #40594 (comment)

Maybe my PR could solve its problem in a different way that doesn't involve changing anything on the interactive side?

What about you use the same technique used in Example_sql in cli_test.go: RunWithCapture and execute cockroach sql -e in this way.

@maddyblue
Copy link
Contributor Author

Using cockroach sql requires an actual server to connect to. I want to run a lot of servers, hence the desire for cockroach demo.

I started working on a standalone program that does all of this, and it's just an annoying amount of work to get around something that I believe is a theoretical problem. I already have this thing working with a minimal change to cockroach demo. I don't care if some other user breaks smithtest by changing the behavior of cockroach demo, I'll just fix it.

a tool that's inherently designed for human consumption and where we have 0% guarantee of UX stability

Sure, I'm fine with this. I'd rather deal with any possible UX fallout than write a new program that's like mostly already this.

What I have here already works perfectly with only a tiny amount of weirdness added to cockroach demo. The amount of work required to make this work correctly without using cockroach demo has a higher cost than dealing with theoretical fallout.

Copy link
Contributor Author

@maddyblue maddyblue left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @knz, @mjibson, @rafiss, and @solongordon)


pkg/cmd/smithtest/main.go, line 71 at r2 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

i haven't used this github client library, so i might be missing something. how is this search being restricted to only the cockroachdb repo?

Fixed.


pkg/cmd/smithtest/main.go, line 98 at r2 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

nit: the name Setup doesn't really seem descriptive to me, but i also just may not know the naming conventions for stuff like this in go. perhaps a name like WorkerSetup or even WorkerPool? also, does the type need to be exported?

Renamed. I just wanted it uppercase to indicate its importance. Doesn't matter for commands.


pkg/cmd/smithtest/main.go, line 289 at r2 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

just curious: do most issue bodies with stacktraces fit into this limit?

Yes. I only found a few that don't, mostly caused by large queries that weren't very reduceable.

@maddyblue
Copy link
Contributor Author

Updated to use a pty package and cockroach start-single-node instead of the env var. Note: we do indeed need the pty because the stuff isn't printed to stdout otherwise.

@maddyblue
Copy link
Contributor Author

PTAL

Copy link
Contributor

@knz knz left a comment

Choose a reason for hiding this comment

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

Reviewed 3 of 5 files at r3.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @knz, @mjibson, @rafiss, and @solongordon)


pkg/cmd/smithtest/main.go, line 156 at r3 (raw file):

		"--port", "0",
		"--http-port", "0",
		"--insecure",

Add --logtostderr to this and remove the pty thing altogether. The log will go to stderr and you can pick the details up from there.

Bonus is that this way you'll also get stack traces and crash reports for fatal errors, not just panics (you'd only get panics otherwise).

Copy link
Contributor Author

@maddyblue maddyblue left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @knz, @mjibson, @rafiss, and @solongordon)


pkg/cmd/smithtest/main.go, line 156 at r3 (raw file):

Previously, knz (kena) wrote…

Add --logtostderr to this and remove the pty thing altogether. The log will go to stderr and you can pick the details up from there.

Bonus is that this way you'll also get stack traces and crash reports for fatal errors, not just panics (you'd only get panics otherwise).

Done. Thanks.

Copy link
Contributor

@knz knz left a comment

Choose a reason for hiding this comment

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

:lgtm: with perhaps a nit.

But otherwise thanks!

Reviewed 3 of 3 files at r4.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @mjibson, @rafiss, and @solongordon)


pkg/cmd/smithtest/main.go, line 141 at r4 (raw file):

// run is a single sqlsmith worker. It starts a new sqlsmither and cockroach
// demo instance. If an error is found it reduces and submits the issue. If

comment needs adjustment. "and in-memory single-node cluster"


pkg/cmd/smithtest/main.go, line 147 at r4 (raw file):

// nil, since they are expected. Something unexpected would be like the
// initialization SQL was unable to run.
func (s WorkerSetup) run(ctx context.Context, rnd *rand.Rand) error {

My preference would be to split this large functions into small(er) sub-functions. Your call.

smithtest is a CLI program for automating sqlsmith testing. It does normal
sqlsmith but via cockroach start-single-node, so found panics don't also
take down the test itself. Found errors are de-duplicated using existing
github issues. The reducer is used to minimize test repros. A new tab
is opened to github with most of the issue data filled in.

Release note: None
Copy link
Contributor Author

@maddyblue maddyblue left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @knz, @mjibson, @rafiss, and @solongordon)


pkg/cmd/smithtest/main.go, line 141 at r4 (raw file):

Previously, knz (kena) wrote…

comment needs adjustment. "and in-memory single-node cluster"

Done.

@maddyblue
Copy link
Contributor Author

bors r+

craig bot pushed a commit that referenced this pull request Sep 25, 2019
40453: cmd/smithtest: add sqlsmith auto tester and github filer r=mjibson a=mjibson

smithtest is a CLI program for automating sqlsmith testing. It does normal
sqlsmith but via cockroach start-single-node, so found panics don't also
take down the test itself. Found errors are de-duplicated using existing
github issues. The reducer is used to minimize test repros. A new tab
is opened to github with most of the issue data filled in.

Use a pty package to enable interactive mode in cockroach, which prints
the sql address to stdout, enabling us to scrape it and connect there.

Release note: None

Release justification: Category 1: Non-production code changes

Co-authored-by: Matt Jibson <[email protected]>
@craig
Copy link
Contributor

craig bot commented Sep 25, 2019

Build succeeded

@craig craig bot merged commit c94d29b into cockroachdb:master Sep 25, 2019
@maddyblue maddyblue deleted the smithtest branch September 25, 2019 20:52
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.

4 participants