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

[improve][pip] PIP-303: Add optional parameters for getPartitionedStats #21228

Merged
merged 8 commits into from
Nov 20, 2023

Conversation

crossoverJie
Copy link
Member

Releted issue: #21200

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

@github-actions github-actions bot added type/PIP doc-not-needed Your PR changes do not impact docs labels Sep 21, 2023
Copy link
Contributor

@BewareMyPower BewareMyPower left a comment

Choose a reason for hiding this comment

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

More overloads will be added in this way. I'm wondering if we can just pass a XXXOption to replace so many parameters?

@crossoverJie
Copy link
Member Author

More overloads will be added in this way. I'm wondering if we can just pass a XXXOption to replace so many parameters?

Good advice, I'll use GetPartitionedStatsOptions instead of exclusivePublishers/exclusiveSubscriptions.

@Data
@Builder
public class GetPartitionedStatsOptions {
    /**
     * Set to true to get precise backlog, Otherwise get imprecise backlog.
     */
    private final boolean getPreciseBacklog;

    /**
     * Whether to get backlog size for each subscription.
     */
    private final boolean subscriptionBacklogSize;

    /**
     * Whether to get the earliest time in backlog.
     */
    private final boolean getEarliestTimeInBacklog;
}

CompletableFuture<PartitionedTopicStats> getPartitionedStatsAsync(
        String topic, boolean perPartition, boolean getPreciseBacklog, boolean subscriptionBacklogSize,
        boolean getEarliestTimeInBacklog, GetPartitionedStatsOptions getPartitionedStatsOptions);

Any other suggestions?

@BewareMyPower
Copy link
Contributor

I think we can package all parameters other than topic and perPartition, which are required. You can see the following overload:

    default PartitionedTopicStats getPartitionedStats(String topic, boolean perPartition) throws PulsarAdminException {
        return getPartitionedStats(topic, perPartition, false, false, false);
    }

@crossoverJie
Copy link
Member Author

Great, I'll create a class GetPartitionedStatsOptions:

@Data
@Builder
public class GetPartitionedStatsOptions {
    /**
     * Set to true to get precise backlog, Otherwise get imprecise backlog.
     */
    private final boolean getPreciseBacklog;

    /**
     * Whether to get backlog size for each subscription.
     */
    private final boolean subscriptionBacklogSize;

    /**
     * Whether to get the earliest time in backlog.
     */
    private final boolean getEarliestTimeInBacklog;

    /**
     * Whether to exclusive publishers.
     */
    private final boolean exclusivePublishers;

    /**
     * Whether to exclusive subscriptions.
     */
    private final boolean exclusiveSubscriptions;
}

Refer to this API:

public class GetStatsOptions {
/**
* Set to true to get precise backlog, Otherwise get imprecise backlog.
*/
private final boolean getPreciseBacklog;
/**
* Whether to get backlog size for each subscription.
*/
private final boolean subscriptionBacklogSize;
/**
* Whether to get the earliest time in backlog.
*/
private final boolean getEarliestTimeInBacklog;
}

TopicStats getStats(String topic, GetStatsOptions getStatsOptions) throws PulsarAdminException;
default TopicStats getStats(String topic, boolean getPreciseBacklog, boolean subscriptionBacklogSize,
boolean getEarliestTimeInBacklog) throws PulsarAdminException {
GetStatsOptions getStatsOptions =
new GetStatsOptions(getPreciseBacklog, subscriptionBacklogSize, getEarliestTimeInBacklog);
return getStats(topic, getStatsOptions);
}

If there are no other issues, I'll update the PIP docuement.

@github-actions
Copy link

The pr had no activity for 30 days, mark with Stale label.

@github-actions github-actions bot added the Stale label Oct 27, 2023
@crossoverJie
Copy link
Member Author

@BewareMyPower I have updated the PIP, please take a look.

pip/pip-303.md Outdated Show resolved Hide resolved
pip/pip-303.md Outdated Show resolved Hide resolved
@github-actions github-actions bot removed the Stale label Nov 9, 2023
Copy link
Contributor

@BewareMyPower BewareMyPower left a comment

Choose a reason for hiding this comment

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

Overall LGTM.

I just think the name would better be "excludeXxxx" rather than "exclusiveXxx" because the logic is excluding the publishers or consumers from the stats, not including "exclusive" publishers or consumers.

@crossoverJie
Copy link
Member Author

Overall LGTM.

I just think the name would better be "excludeXxxx" rather than "exclusiveXxx" because the logic is excluding the publishers or consumers from the stats, not including "exclusive" publishers or consumers.

This was my clerical error, done.

@Technoboy- Technoboy- added this to the 3.2.0 milestone Nov 13, 2023
pip/pip-303.md Outdated
TopicStatsImpl getStats(boolean getPreciseBacklog, boolean subscriptionBacklogSize,
boolean getEarliestTimeInBacklog, boolean excludePublishers, boolean excludeConsumers);

CompletableFuture<? extends TopicStatsImpl> asyncGetStats(boolean getPreciseBacklog,
Copy link
Member

@nodece nodece Nov 16, 2023

Choose a reason for hiding this comment

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

IMO, we only need to add an async method to avoid blocking the thread.

For the method arguments, we can also use the above design that moving these arguments to a class.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good suggestion, done.

Copy link
Member

@nodece nodece left a comment

Choose a reason for hiding this comment

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

I left a suggestion, can you confirm?

LGTM

@Technoboy- Technoboy- merged commit 9fbb92a into apache:master Nov 20, 2023
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc-not-needed Your PR changes do not impact docs type/PIP
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants