Skip to content

SAMZA-2574: improve flexibility of SystemFactory interface#1408

Merged
sborya merged 8 commits intoapache:masterfrom
MabelYC:interfaceChange
Aug 12, 2020
Merged

SAMZA-2574: improve flexibility of SystemFactory interface#1408
sborya merged 8 commits intoapache:masterfrom
MabelYC:interfaceChange

Conversation

@MabelYC
Copy link
Contributor

@MabelYC MabelYC commented Aug 4, 2020

improve SystemFactory interface by providing user-defined clientId prefix so that we can access more information of the clients created: with changes, user can add specific clientId prefix for clients to help monitor clients.

API Changes: Added three default functions in SystemFactory. Since they are default functions, they won't make any impact to current users.

Upgrade Instructions: N/A

Usage Instructions: To use the new default functions, user will need to redefine them in their implementation class. And then user can set specific clientId.

@prateekm
Copy link
Contributor

prateekm commented Aug 5, 2020

@cameronlee314 can you take a look?

@prateekm
Copy link
Contributor

prateekm commented Aug 5, 2020

@MabelYC Please also explain (in the description) why this change is required and how this will be used.

@MabelYC
Copy link
Contributor Author

MabelYC commented Aug 5, 2020

@MabelYC Please also explain (in the description) why this change is required and how this will be used.

Sure.

Copy link
Contributor

@sborya sborya left a comment

Choose a reason for hiding this comment

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

Please change the name of the rb to describe the changes, not the generic intent. Something to the effect of "..allow specify prefix for consumer/producer/admin ids.."

SystemProducer systemProducer =
systemFactory.getProducer(diagnosticsSystemStream.getSystem(), config, new MetricsRegistryMap());
systemFactory.getProducer(diagnosticsSystemStream.getSystem(), config, new MetricsRegistryMap(),
MethodHandles.lookup().lookupClass().getSimpleName());
Copy link
Contributor

Choose a reason for hiding this comment

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

i think it is ok to hardcode the prefix to "DiagnosticsUtil" too.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use Class.getSimpleName() here too?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is a static method. And we CAN use simpleName(), but we don't have too. As long as it is unique for the caller.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it, thanks. We can probably use DiagnosticsUtil.class.getSimpleName() so that any refactoring updates it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it. Will do.


SystemAdmin getAdmin(String systemName, Config config);

default SystemConsumer getConsumer(String systemName, Config config, MetricsRegistry registry, String consumerIdPrefix) {
Copy link
Contributor

@prateekm prateekm Aug 6, 2020

Choose a reason for hiding this comment

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

Why assume that it's used as prefix in the API? Maybe just call this consumerName/consumerId and let the actual implementation figure out how to use it?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we don't want caller to assume that this is the id and it must be used as is. The idea is that it should be a unique piece of info that can be used to construct an id. Please suggest your name.

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 assuming this is intended to be used as part of the Kafka clientId to figure out who owns the instance?

Maybe consumerLabel. We should add some documentation on what this should be set to by the caller (e.g., set this to indicate ownership of the client instance), how this will be used by system implementers (e.g., to identify consumers in logs, threads and client instances etc., along with other relevant information like systemName).

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 "add some documentation" you mean add javadoc or open source documentation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

@MabelYC I mean Javadocs. The page you linked is auto-generated from Javadocs.


SystemAdmin getAdmin(String systemName, Config config);

default SystemConsumer getConsumer(String systemName, Config config, MetricsRegistry registry, String consumerIdPrefix) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add method Javadocs clarifying what the parameters are, and how these methods are different than the ones above.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, let's make this the second parameter after systemName to group naming related parameters together.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point. Thanks. Will do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, let's make this the second parameter after systemName to group naming related parameters together.

I think change order may not be a good option. We are adding functions to help make previous ones more flexible, so may be better to keep the order the same as previous one. And also, systemName is not intended to be a naming parameter. So i think it may be better to keep it in current order. what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

That's a good point, let's keep this order and add javadocs.


SystemAdmin getAdmin(String systemName, Config config);

default SystemConsumer getConsumer(String systemName, Config config, MetricsRegistry registry, String consumerIdPrefix) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we mark the other methods as @deprecated to encourage use of the new methods and identify other call sites that need to be updated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if it is better. With deprecated, user will still have to implement them later. Can it work as we expect?

Copy link
Contributor

Choose a reason for hiding this comment

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

@MabelYC what do you mean? I'm suggesting that we add the annotation to mark them as deprecated (e.g. https://www.baeldung.com/java-deprecated). We will not remove the older methods. This will mean that when some code calls the older methods, the author will get build time warnings that the method they're calling is deprecated, so that they can start using the new (better) method instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@prateekm make sense. Marked theme as @deprecated.

@MabelYC MabelYC requested a review from sborya August 7, 2020 01:32
Copy link
Contributor

@sborya sborya left a comment

Choose a reason for hiding this comment

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

with some nit comments.

/**
* This function provides an extra input parameter than {@link #getConsumer}, which can be used to provide extra
* information e.g. ownership of client instance, to helper better identify consumers in logs,
* threads and client instances etc., along with other relevant information like systemName
Copy link
Contributor

Choose a reason for hiding this comment

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

nit. add '.' at the end.

* @param systemName The name of the system to create consumer for.
* @param config The config to create consumer with.
* @param registry MetricsRegistry to which to publish consumer specific metrics.
* @param consumerLabel a string used to provide info the consumer instance.
Copy link
Contributor

Choose a reason for hiding this comment

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

" a string to provide extra info for the consumer instance."

* @param systemName The name of the system to create producer for.
* @param config The config to create producer with.
* @param registry MetricsRegistry to which to publish producer specific metrics.
* @param producerLabel a string used to provide info the producer instance.
Copy link
Contributor

Choose a reason for hiding this comment

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

see above.

/**
* This function provides an extra input parameter than {@link #getAdmin}, which can be used to provide extra
* information e.g. ownership of client instance, to helper better identify admins in logs,
* threads and client instances etc., along with other relevant information like systemName
Copy link
Contributor

Choose a reason for hiding this comment

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

^^^


/**
* This function provides an extra input parameter to {@link #getConsumer}, which can be used to provide extra
* information for the consumer instance, e.g. ownership of client instance, to helper better identify consumers in logs,
Copy link
Contributor

Choose a reason for hiding this comment

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

s/helper/help


/**
* This function provides an extra input parameter to {@link #getProducer}, which can be used to provide extra
* information for the producer instance, e.g. ownership of client instance, to helper better identify producers in logs,
Copy link
Contributor

Choose a reason for hiding this comment

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

see above.


/**
* This function provides an extra input parameter to {@link #getAdmin}, which can be used to provide extra
* information for the admin instance, e.g. ownership of client instance, to helper better identify admins in logs,
Copy link
Contributor

Choose a reason for hiding this comment

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

see above.

@sborya sborya merged commit b736af9 into apache:master Aug 12, 2020
@MabelYC MabelYC deleted the interfaceChange branch September 16, 2020 01:29
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