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

feat: add REST /metadata path to display KSQL server information (replaces /info) #3313

Merged
merged 4 commits into from
Sep 19, 2019

Conversation

spena
Copy link
Member

@spena spena commented Sep 9, 2019

Description

This new path (/metadata) will replace the /info path in the next KSQL major release. It is added to have a standard API between Confluent components that show information about the current cluster.

For now, this path displays the following:

/metadata
{
  "version": "5.4.0-SNAPSHOT",
  "clusterId": {
    "id": "",
    "scope": {
      "kafka-cluster": "H6tCQq0zSWan9_L-TZHa9A",
      "ksql-cluster": "default_"
    }
  }
}

/metadata/id
{
  "id": "",
  "scope": {
    "kafka-cluster": "H6tCQq0zSWan9_L-TZHa9A",
    "ksql-cluster": "default_"
  }
}

Follow-up PRs:

  • Call /metadata instead of /info from the KSQL CLI
  • Add documentation about the new path
  • Remove the /info path in KSQL 6.x (pending Issue)

Testing done

  • Added unit tests
  • Manual verification

Reviewer checklist

  • Ensure docs are updated if necessary. (eg. if a user visible feature is being added or changed).
  • Ensure relevant issues are linked (description should include text like "Fixes #")

@spena spena added this to the 5.4 milestone Sep 9, 2019
@spena spena requested a review from a team September 9, 2019 17:22
@spena spena self-assigned this Sep 9, 2019
@spena spena force-pushed the metadata_rest_api branch from d221d97 to 4a4a6ac Compare September 9, 2019 21:32
Copy link
Contributor

@big-andy-coates big-andy-coates left a comment

Choose a reason for hiding this comment

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

Thanks @spena

LGTM, with a few nits...

It would be good to add something to RestApiTest to test this new end point end-to-end

Also, a SecureIntegerationTest to ensure you don't need to authenticate to access it, maybe?

Finally, can you create a Github issue to remove the old /info URL, mark it for milestone 6.0, i.e. our next breaking change, and then include the PR number in your description please?

@@ -189,10 +196,25 @@ public static String getCommandsStreamName() {
requireNonNull(rocksDBConfigSetterHandler, "rocksDBConfigSetterHandler");
}

private static KsqlRestConfig injectRestConfigDefaults(final KsqlRestConfig restConfig) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: private to the bottom of the file

Copy link
Member Author

Choose a reason for hiding this comment

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

done

);

// REST paths that are public and do not require authentication
restConfigs.put(RestConfig.AUTHENTICATION_SKIP_PATHS,
Copy link
Contributor

Choose a reason for hiding this comment

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

could this not potentially be overwriting a config a user has set?

Should we not be adding to the existing setting, rather than overwriting?

Copy link
Member Author

Choose a reason for hiding this comment

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

done

restConfigs.put(RestConfig.AUTHENTICATION_SKIP_PATHS,
Joiner.on(",").join(authenticationSkipPaths));

return new KsqlRestConfig(restConfigs);
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than adjusting the supplied KsqlConfig, is there some reason you can't add the RestConfig.AUTHENTICATION_SKIP_PATHS when building the original KsqlConfig in KsqlRestApplication.buildApplication?

Copy link
Member Author

Choose a reason for hiding this comment

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

I could, but the KsqlConfig is built from the below line that does not include the RestConfig properties:
final KsqlConfig ksqlConfig = new KsqlConfig(restConfig.getKsqlConfigProperties());

And the KsqlRestApplication constructor passes the KsqlRestConfig to the parent class, no the KsqlConfig. So I had to overwrite the KsqlRestConfig instead. I'm not sure why we have two different configurations, btw. Do you think we should join KsqlConfig and KsqlRetsConfig into one?

@@ -52,4 +63,8 @@ public void filter(final ContainerRequestContext requestContext) {
requestContext.abortWith(Errors.accessDenied(t.getMessage()));
}
}

private boolean requiresAuthorization(final String path) {
return !UNAUTHORIZED_ENDPOINTS.contains(path);
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we case sensitive on paths? Not sure. if not, then this should also not be case sensitive.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, we are case sensitive.

@@ -32,6 +34,11 @@
public class KsqlAuthorizationFilter implements ContainerRequestFilter {
private static final Logger log = LoggerFactory.getLogger(KsqlAuthorizationFilter.class);

private static final Set<String> UNAUTHORIZED_ENDPOINTS = ImmutableSet.of(
"/metadata",
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be good to pick these up from constants in ServerMetadataResource...

Copy link
Member Author

Choose a reason for hiding this comment

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

done

private static final String KAFKA_CLUSTER = "kafka-cluster";
private static final String KSQL_CLUSTER = "ksql-cluster";

@JsonProperty("id")
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: unnecessary, given there is a getId method

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@JsonProperty("id")
private final String id;

@JsonProperty("scope")
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is there no getter for this field?

Copy link
Member Author

Choose a reason for hiding this comment

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

Added one

@JsonProperty("version") final String version,
@JsonProperty("clusterId") final ServerClusterId clusterId
) {
this.version = version;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: null checks.

Copy link
Member Author

Choose a reason for hiding this comment

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

done


import static org.junit.Assert.assertEquals;

public class ServerMetadataTest {
Copy link
Contributor

Choose a reason for hiding this comment

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

need same test for ServerClusterId.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

// Given:
final ServerMetadata expected = new ServerMetadata(
"1.0.0",
ServerClusterId.of("kafka1", "ksql1")
Copy link
Contributor

Choose a reason for hiding this comment

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

Use a mock for ServerClusterId in this test means this test is not dependant on ServerClusterId impl. This test would then only be testing this class, which is a good thing.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@spena spena merged commit 8be29b9 into confluentinc:master Sep 19, 2019
@spena
Copy link
Member Author

spena commented Sep 19, 2019

Thanks @big-andy-coates for the review.

@spena spena deleted the metadata_rest_api branch September 19, 2019 20:50
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.

2 participants