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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for multiple configuration contexts #48

Merged
merged 1 commit into from Aug 24, 2021

Conversation

helpermethod
Copy link
Contributor

@helpermethod helpermethod commented Aug 18, 2021

Hi @gunnarmorling,

here comes the PR! I hope I've got the the requirements right 馃槃.

One thing I would like to challenge is supporting the old, properties-like config format. Because we are still pre 1.0.0, I guess it would be acceptable to not support the current (properties-like) configuration format anymore. Wdyt?

The current, context-aware format is very flexible, except for the context-name and cluster URL, every other property is
optional.

So both

{
    "currentContext": "local",
    "local": {
        "cluster": "http://localhost:8083"
    }
}

and

{
    "currentContext": "local",
    "local": {
        "cluster": "http://localhost:8083",
        "boostrapServers": "localhost:9092",
        "offsetTopic": "connect-offsets"
    }
}

are valid.

Fixes #24.

Copy link
Collaborator

@gunnarmorling gunnarmorling left a comment

Choose a reason for hiding this comment

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

Nice, this LGTM overall. A few comments inline. Thx, @helpermethod!

pom.xml Show resolved Hide resolved

@Option(names = { "--cluster" }, description = "URL of the Kafka Connect cluster to connect to", required = true)
@Option(names = {"--cluster"}, description = "URL of the Kafka Connect cluster to connect to", required = true)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we default the options? http://localhost:8083 and localhost:9092 seem reasonable for KC and broker URLs? For the offset topic, we could leave that optional. If if it's not set for a given context, the future commands interacting with offsets wouldn't work without it, stating the need to specify a value in the chosen context. WDYT?

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.

configuration.addConfigurationContext(contextName, context)
);
} catch (IOException e) {
throw new RuntimeException("Couldn't write context file ~/" + CONFIG_FILE, e);
}
}

public URI getCluster() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this method go away entirely, and all access be via getContext()? And we'd log an error if no context has been defined.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

By logging you mean logging to STDOUT?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, exactly.

@MethodSource("dev.morling.kccli.util.ConfigurationContextTest#setConfigurationArguments")
@ParameterizedTest
void should_create_a_new_configuration_when_no_configuration_exists(String contextName, Context context, String expectedConfiguration) throws IOException {
System.setProperty("user.home", tempDir.getAbsolutePath());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Neat trick :) Alternatively, there could be a constructor in ConfigurationContext which takes the config directory, while the default constructor would use the home dir.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Had the exact same idea, but didn't want to change too much code at first. Good suggestion!

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.

var configuration = objectMapper.readValue(configPath, Configuration.class);

return configuration.configurationContexts().get(configuration.getCurrentContext());
} catch (IOException e) {
throw new RuntimeException("Couldn't read configuration file ~/" + CONFIG_FILE, e);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's add a sentence like "Create/update your configuration by running 'kcctl set-context ...'".

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.

@gunnarmorling
Copy link
Collaborator

One thing I would like to challenge is supporting the old, properties-like config format. Because we are still pre 1.0.0, I guess it would be acceptable to not support the current (properties-like) configuration format anymore. Wdyt?

Yes, that's ok. We only should log a meaningful error in that case.

Other than that, could you

  • Rebase this PR so to address the current conflicts
  • Squash the commits into one and prefix the message with a suitable emoj :)
  • Add a section to the README describing the notion of contexts; two or three sentences will surely suffice, just to explain the overall approach

Thanks again!

@helpermethod helpermethod force-pushed the issue-24 branch 2 times, most recently from c02d392 to b5c24e5 Compare August 20, 2021 19:42
@helpermethod
Copy link
Contributor Author

Now adding a few lines to the README.md.

@helpermethod
Copy link
Contributor Author

Hi @gunnarmorling, that push should resolve most, if not all of your comments 馃槃.

@gunnarmorling
Copy link
Collaborator

@helpermethod, could you also re-generate the completion script (see instructions in the README) for the new options?

@gunnarmorling
Copy link
Collaborator

Thanks a lot, @helpermethod! So I've played around a bit, it looks great overall. I wonder though if we can make the experience a bit smoother by default, i.e. if the user has not configured any context yet. How about the following if no context has been configured:

  • When invoking any command other than config and its sub-commands, use http://localhost:8083 (as before), and display a warning such as "No configuration context has been defined, using http://localhost:8083 by default. Run ... to create a context."
  • When invoking config get-context, print a message like "No configuration context has been defined, http://localhost:8083 will be used by default. Run ... to configure a create."

WDYT?

@helpermethod
Copy link
Contributor Author

Great suggestions, I'll incorporate them over the weekend!

@gunnarmorling
Copy link
Collaborator

@helpermethod, if you'd like me to wrap up this one, just let me know. Would love to have it in, so we can get to the offset reset stuff :)

@helpermethod
Copy link
Contributor Author

Hi @gunnarmorling,

I'm on it, I'm currently stuffed with work so it's not easy to find some uninterrupted time 馃槃.

I don't quite get the difference between

  • When invoking any command other than config and its sub-commands, use http://localhost:8083 (as before), and display a warning such as "No configuration context has been defined, using http://localhost:8083 by default. Run ... to create a context."
  • When invoking config get-context, print a message like "No configuration context has been defined, http://localhost:8083 will be used by default. Run ... to configure a create."

So in any case basically a warning is printed and a default is returned?

@helpermethod helpermethod force-pushed the issue-24 branch 2 times, most recently from 8bbbecc to 7c4ac6e Compare August 24, 2021 20:15
@gunnarmorling
Copy link
Collaborator

So in any case basically a warning is printed and a default is returned?

Yes, that'd be the idea. Only the wording of the messages might be slightly different ("Using..." for actual commands vs. "Will use..." for get-context), but perhaps I'm overthinking it and we can have one which fits for both :)

@gunnarmorling
Copy link
Collaborator

@helpermethod, there's a few odd changes part of this now, like version downgrades in the POM and removal of the Dependabot config.

@helpermethod
Copy link
Contributor Author

Messed up the latest commit, fixing it right now.

@helpermethod
Copy link
Contributor Author

I hope that should do it 馃槄!

@gunnarmorling gunnarmorling merged commit acfc54c into kcctl:main Aug 24, 2021
@gunnarmorling
Copy link
Collaborator

Yepp, LGTM. Applied. Thanks a lot!

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.

Expand notion of configuration context
2 participants