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

Add Command filter to MicrometerCommandLatencyRecorder #2406

Closed
andre237 opened this issue May 13, 2023 · 0 comments
Closed

Add Command filter to MicrometerCommandLatencyRecorder #2406

andre237 opened this issue May 13, 2023 · 0 comments
Labels
type: feature A new feature
Milestone

Comments

@andre237
Copy link
Contributor

andre237 commented May 13, 2023

Feature Request

Describe the solution you'd like

I would like to have the possibility of choosing which commands should be recorded when using MicrometerCommandLatencyRecorder. Using the latest version (6.2.4-RELEASE), this is not possible and all commands issued to Redis are stored in Micrometer MeterRegistry. I'm willing to submit a Pull request implementing this feature.

Describe alternatives you've considered

I thought about implementing this by adding a List<CommandType> as a new member to the MicrometerOptions class, and then, on MicrometerCommandLatencyRecorder#recordCommandLatency method, add a second validation checking if the ProtocolKeyword#name is contained in the new list of commands option.

Possible implementation would look like:

@Override
public void recordCommandLatency(SocketAddress local, SocketAddress remote, ProtocolKeyword protocolKeyword,
        long firstResponseLatency, long completionLatency) {

    if (!isEnabled() || !isCommandInFilter(protocolKeyword)) {
        return;
    }
    
    .... 
}


private boolean isCommandInFilter(ProtocolKeyword protocolKeyword) {
    return options.getDesiredCommands().isEmpty() || options.getDesiredCommands().contains(protocolKeyword.name());
}

The name desiredCommands is up to debate, I'm not certain if the word "desired" fully expresses the feature proposal

Teachability, Documentation, Adoption, Migration Strategy

Whenever someone would like to filter which commands should have their latency recorded, it would only need to build the MicrometerOptions with the new method, something like:

MicrometerOptions.builder()
        .desiredCommands(CommandType.HGET, CommandType.SMEMBERS, CommandType.LRANGE)
        .build();

Regarding documentation, my PullRequest would include a new row to the MicrometerOptions table description (https://github.com/lettuce-io/lettuce-core/wiki/Command-Latency-Metrics#micrometer-options)

Any opinions about it would be appreciated!

@mp911de mp911de added the type: feature A new feature label May 15, 2023
mp911de pushed a commit that referenced this issue Aug 15, 2023
We can now filter particular commands from being recorded to Micrometer.

Original pull request: #2407
mp911de added a commit that referenced this issue Aug 15, 2023
Refactor enabledCommands to use a Predicate for metrics recording.

Original pull request: #2407
@mp911de mp911de linked a pull request Aug 15, 2023 that will close this issue
4 tasks
@mp911de mp911de changed the title Feature request: filtering commands on MicrometerCommandLatencyRecorder Add Command filter to MicrometerCommandLatencyRecorder Aug 15, 2023
@mp911de mp911de added this to the 6.3 milestone Aug 15, 2023
@mp911de mp911de closed this as completed Aug 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature A new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants