Skip to content

KAFKA-7793: Improve the Trogdor command line.#6133

Merged
cmccabe merged 5 commits intoapache:trunkfrom
cmccabe:KAFKA-7793
Jan 24, 2019
Merged

KAFKA-7793: Improve the Trogdor command line.#6133
cmccabe merged 5 commits intoapache:trunkfrom
cmccabe:KAFKA-7793

Conversation

@cmccabe
Copy link
Copy Markdown
Contributor

@cmccabe cmccabe commented Jan 12, 2019

  • Allow the Trogdor agent to be started in "exec mode", where it simply
    runs a single task and exits after it is complete.

  • For AgentClient and CoordinatorClient, allow the user to pass the path
    to a file containing JSON, instead of specifying the JSON object in the
    command-line text itself. This means that we can get rid of the bash
    scripts whose only function was to load task specs into a bash string
    and run a Trogdor command.

  • Print dates and times in a human-readable way, rather than as numbers
    of milliseconds.

  • When listing tasks or workers, output human-readable tables of
    information.

  • Allow the user to filter on task ID name, task ID pattern, or task
    state.

  • Support a --json flag to provide raw JSON output if desired.

More detailed description of your change,
if necessary. The PR title and PR message become
the squashed commit message, so use a separate
comment to ping reviewers.

Summary of testing strategy (including rationale)
for the feature or bug fix. Unit and/or integration
tests are expected for any behaviour change and
system tests should be considered for larger changes.

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

Copy link
Copy Markdown
Contributor

@stanislavkozlovski stanislavkozlovski left a comment

Choose a reason for hiding this comment

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

Lots of great changes! Thanks for the PR, @cmccabe!

I like the separation into .json specs a lot - it is more friendly for an abundance of examples rather than all the .sh scripts we had to duplicate logic in.

Comment thread tests/spec/round_trip.json Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we support templating now?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oops-- this was an oversight. Fixed.

Comment thread tests/spec/round_trip.json Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm wondering whether we should add a README.md under /tests/spec/ or rename to something similar to /tests/trogdor_specs - just to make it clearer for new users what these specs represent

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good idea. I added an Apache header and a comment to the files, referring to TROGDOR.md

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: Might as well create an addWorkerIdArgument() to be consistent with the other shared args

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: probably not worth it to log an error, as another delete will be attempted. TestUtils.tempFile() calls file.deleteOnExit();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Those two test cases are exactly the same, I assume you wanted to test one with spaces ( ) only?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed, thanks

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: extra space

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: extra space

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we add a shorthand --s or chance --show-status's shorthand to --s?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added -s as shorthand for --state

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Will this work with multiple task ids? The tasks() code does this:

        uriBuilder.queryParam("taskId", (Object[]) request.taskIds().toArray(new String[0]));

I think that returns a single-element array only?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

List#toArray can return arrays with more than one element.

https://docs.oracle.com/javase/8/docs/api/java/util/List.html#toArray-T:A-

The array argument at the end is a little weird. TL;DR is that if you want to squeeze out some extra efficiency, you can pass something other than a zero-length array to that argument, to avoid object allocation.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is great functionality but would it be better if we had it in the coordinator server in order to leverage it from REST API clients in other languages? Otherwise we probably need to duplicate logic.
We could maybe open a JIRA to track this as a separate item

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We've been holding off on including regular expressions into APIs since we would like APIs to be language neutral, and Java regexps are not. They also change over time as Java changes (java 8 changed how some of them are interpreted).

I think we could open a follow-up JIRA for this, though. We can use re2 regular expressions to make the API language-neutral.

* Allow the Trogdor agent to be started in "exec mode", where it simply
runs a single task and exits after it is complete.

* For AgentClient and CoordinatorClient, allow the user to pass the path
to a file containing JSON, instead of specifying the JSON object in the
command-line text itself.  This means that we can get rid of the bash
scripts whose only function was to load task specs into a bash string
and run a Trogdor command.

* Print dates and times in a human-readable way, rather than as numbers
of milliseconds.

* When listing tasks or workers, output human-readable tables of
information.

* Allow the user to filter on task ID name, task ID pattern, or task
state.

* Support a --json flag to provide raw JSON output if desired.
}

/**
* Determine if a string is a JSON object literal.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we have any use cases for lists of objects at the top level of a JSON string?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's a fair question. The answer here is that in all the cases where we're using this function, we want a JSON object as the top-level thing. We generally always make things objects in case we need to add more stuff later on. (For example, perhaps right now we want to configure X with a list of ints, but later we might want a list of ints and a float, etc.)

/**
* Utilities for formatting strings.
*/
public class Formatter {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe StringFormatter?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sounds good. Renamed

Copy link
Copy Markdown
Member

@mumrah mumrah left a comment

Choose a reason for hiding this comment

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

I don't see any examples of --exec usage in the README. Maybe we could add one?

Supplying the spec JSON in a file rather than having to do shell gymnastics is definitely an improvement. Human readable output is always nice (for us humans, at least).

@cmccabe
Copy link
Copy Markdown
Contributor Author

cmccabe commented Jan 23, 2019

retest this please

Copy link
Copy Markdown
Member

@mumrah mumrah left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Contributor

@stanislavkozlovski stanislavkozlovski left a comment

Choose a reason for hiding this comment

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

JDK8 build test failure is unrelated - kafka.api.AdminClientIntegrationTest.testForceClose

LGTM! Working with Trogdor locally just got a heck of a lot better - thanks a lot for these changes @cmccabe!

@cmccabe cmccabe merged commit a79d6dc into apache:trunk Jan 24, 2019
jarekr pushed a commit to confluentinc/kafka that referenced this pull request Apr 18, 2019
* ak/trunk:
  MINOR: Update usage of deprecated API (apache#6146)
  KAFKA-4217: Add KStream.flatTransform (apache#5273)
  MINOR: Update Gradle to 5.1.1 (apache#6160)
  KAFKA-3522: Generalize Segments (apache#6170)
  Added quotes around the class path (apache#4469)
  KAFKA-7837: Ensure offline partitions are picked up as soon as possible when shrinking ISR (apache#6202)
  MINOR: In the MetadataResponse schema, ignorable should be a boolean
  KAFKA-7838: Log leader and follower end offsets when shrinking ISR (apache#6168)
  KAFKA-5692: Change PreferredReplicaLeaderElectionCommand to use Admin… (apache#3848)
  MINOR: clarify why suppress can sometimes drop tombstones (apache#6195)
  MINOR: Upgrade ducktape to 0.7.5 (apache#6197)
  MINOR: Improve IntegrationTestUtils documentation (apache#5664)
  MINOR: upgrade to jdk8 8u202
  KAFKA-7693; Fix SequenceNumber overflow in producer (apache#5989)
  KAFKA-7692; Fix ProducerStateManager SequenceNumber overflow (apache#5990)
  MINOR: update copyright year in the NOTICE file. (apache#6196)
  KAFKA-7793: Improve the Trogdor command line. (apache#6133)
@cmccabe cmccabe deleted the KAFKA-7793 branch May 20, 2019 19:03
pengxiaolong pushed a commit to pengxiaolong/kafka that referenced this pull request Jun 14, 2019
* Allow the Trogdor agent to be started in "exec mode", where it simply
runs a single task and exits after it is complete.

* For AgentClient and CoordinatorClient, allow the user to pass the path
to a file containing JSON, instead of specifying the JSON object in the
command-line text itself.  This means that we can get rid of the bash
scripts whose only function was to load task specs into a bash string
and run a Trogdor command.

* Print dates and times in a human-readable way, rather than as numbers
of milliseconds.

* When listing tasks or workers, output human-readable tables of
information.

* Allow the user to filter on task ID name, task ID pattern, or task
state.

* Support a --json flag to provide raw JSON output if desired.

Reviewed-by: David Arthur <mumrah@gmail.com>, Stanislav Kozlovski <stanislav_kozlovski@outlook.com>
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