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

Feature: Add option to exclude consumer from Stream metrics #906

Merged

Conversation

nantiferov
Copy link
Contributor

Tested it manually, looks like working properly, PTAL.

Probably need to add more tests, can check it later.

Amount of metrics on test redis:

  • without streams metrics collect - 260
  • with REDIS_EXPORTER_CHECK_STREAMS=* - 680
  • with this feature enabled in addition to previous - 430

Fixes: #902

Copy link
Owner

@oliver006 oliver006 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!
Looks good, minor suggestions re: naming to make it more clear what you're excluding (metrics) but I think you're going in the right direction.

README.md Outdated
@@ -148,6 +148,7 @@ Prometheus uses file watches and all changes to the json file are applied immedi
| check-single-keys | REDIS_EXPORTER_CHECK_SINGLE_KEYS | Comma separated list of keys to export value and length/size, eg: `db3=user_count` will export key `user_count` from db `3`. db defaults to `0` if omitted. The keys specified with this flag will be looked up directly without any glob pattern matching. Use this option if you don't need glob pattern matching; it is faster than `check-keys`. |
| check-streams | REDIS_EXPORTER_CHECK_STREAMS | Comma separated list of stream-patterns to export info about streams, groups and consumers. Syntax is the same as `check-keys`. |
| check-single-streams | REDIS_EXPORTER_CHECK_SINGLE_STREAMS | Comma separated list of streams to export info about streams, groups and consumers. The streams specified with this flag will be looked up directly without any glob pattern matching. Use this option if you don't need glob pattern matching; it is faster than `check-streams`. |
| streams-exclude-consumer | REDIS_EXPORTER_STREAMS_EXCLUDE_CONSUMER | Don't collect per consumer metrics for streams (decreases amount of metrics and cardinality). |
Copy link
Owner

Choose a reason for hiding this comment

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

REDIS_EXPORTER_STREAMS_EXCLUDE_CONSUMER -> REDIS_EXPORTER_STREAMS_EXCLUDE_CONSUMER_METRICS ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, sure.

My only concern was that it would be quite long, but not too much I think)

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, committed changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apparently tests are failing, but I don't see exact reason.

In the end of output only:

FAIL
coverage: 90.0% of statements
FAIL	github.com/oliver006/redis_exporter/exporter	22.273s
FAIL

And before something looks like errors, but nothing says FAIL

=== RUN   TestParseKeyArg/invalid_args_with_args_separator_skipped
time="2024-05-20T17:54:09Z" level=error msg="parseKeyArg(): Empty value parsed in pair '=', skip"
=== RUN   TestParseKeyArg/empty_args_with_comma_separators_skipped
=== RUN   TestParseKeyArg/multiple_invalid_args_skipped
time="2024-05-20T17:54:09Z" level=error msg="parseKeyArg(): Empty value parsed in pair '=', skip"
time="2024-05-20T17:54:09Z" level=error msg="parseKeyArg(): Empty value parsed in pair '=', skip"
=== RUN   TestParseKeyArg/empty_key_with_args_separator_skipped
time="2024-05-20T17:54:09Z" level=error msg="parseKeyArg(): Empty value parsed in pair '0=', skip"
=== RUN   TestParseKeyArg/empty_database_with_args_separator_skipped
time="2024-05-20T17:54:09Z" level=error msg="parseKeyArg(): Empty value parsed in pair '=my-key', skip"
=== RUN   TestParseKeyArg/string_database_index
    keys_test.go:265: Expected failure for test: string_database_index, got err: Invalid database index for db "wrong": strconv.Atoi: parsing "wrong": invalid syntax
=== RUN   TestParseKeyArg/prefixed_string_database_index
    keys_test.go:265: Expected failure for test: prefixed_string_database_index, got err: Invalid database index for db "wrong": strconv.Atoi: parsing "wrong": invalid syntax
=== RUN   TestParseKeyArg/wrong_args_count
    keys_test.go:265: Expected failure for test: wrong_args_count, got err: invalid key list argument: wrong=wrong=wrong
=== RUN   TestParseKeyArg/wrong_args
    keys_test.go:265: Expected failure for test: wrong_args, got err: invalid key list argument: wrong=wrong=1
=== RUN   TestParseKeyArg/negative_database_index
    keys_test.go:265: Expected failure for test: negative_database_index, got err: Invalid database index for db "-1": %!s(<nil>)

@@ -55,6 +55,7 @@ type Options struct {
CheckSingleKeys string
CheckStreams string
CheckSingleStreams string
StreamsExcludeConsumer bool
Copy link
Owner

Choose a reason for hiding this comment

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

Same, add Metrics ?

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

@oliver006
Copy link
Owner

Try rebasing your PR, I pushed a fix to master last week to fix an issue with an outdated Redis docker container.

@coveralls
Copy link

coveralls commented May 21, 2024

Pull Request Test Coverage Report for Build 352

Details

  • 8 of 83 (9.64%) changed or added relevant lines in 3 files are covered.
  • 13 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.06%) to 84.172%

Changes Missing Coverage Covered Lines Changed/Added Lines %
main.go 0 75 0.0%
Files with Coverage Reduction New Missed Lines %
exporter/exporter.go 13 94.44%
Totals Coverage Status
Change from base Build 344: -0.06%
Covered Lines: 1973
Relevant Lines: 2344

💛 - Coveralls

@nantiferov
Copy link
Contributor Author

Try rebasing your PR, I pushed a fix to master last week to fix an issue with an outdated Redis docker container.

That helped, thank you.

Though coverage decreased, I will check later today to add tests.

@nantiferov
Copy link
Contributor Author

Added tests for new option, but coverage still decreases.

Copy link
Owner

@oliver006 oliver006 left a comment

Choose a reason for hiding this comment

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

PR looks good, minor comment re: the README but otherwise looks good

README.md Outdated
@@ -148,6 +148,7 @@ Prometheus uses file watches and all changes to the json file are applied immedi
| check-single-keys | REDIS_EXPORTER_CHECK_SINGLE_KEYS | Comma separated list of keys to export value and length/size, eg: `db3=user_count` will export key `user_count` from db `3`. db defaults to `0` if omitted. The keys specified with this flag will be looked up directly without any glob pattern matching. Use this option if you don't need glob pattern matching; it is faster than `check-keys`. |
| check-streams | REDIS_EXPORTER_CHECK_STREAMS | Comma separated list of stream-patterns to export info about streams, groups and consumers. Syntax is the same as `check-keys`. |
| check-single-streams | REDIS_EXPORTER_CHECK_SINGLE_STREAMS | Comma separated list of streams to export info about streams, groups and consumers. The streams specified with this flag will be looked up directly without any glob pattern matching. Use this option if you don't need glob pattern matching; it is faster than `check-streams`. |
| streams-exclude-consumer | REDIS_EXPORTER_STREAMS_EXCLUDE_CONSUMER_METRICS | Don't collect per consumer metrics for streams (decreases amount of metrics and cardinality). |
Copy link
Owner

Choose a reason for hiding this comment

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

streams-exclude-consumer --> streams-exclude-consumer-metrics

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for noticing. Missed update here.

Now should be good.

checkKeyGroups = flag.String("check-key-groups", getEnv("REDIS_EXPORTER_CHECK_KEY_GROUPS", ""), "Comma separated list of lua regex for grouping keys")
checkStreams = flag.String("check-streams", getEnv("REDIS_EXPORTER_CHECK_STREAMS", ""), "Comma separated list of stream-patterns to export info about streams, groups and consumers, searched for with SCAN")
checkSingleStreams = flag.String("check-single-streams", getEnv("REDIS_EXPORTER_CHECK_SINGLE_STREAMS", ""), "Comma separated list of single streams to export info about streams, groups and consumers")
streamsExcludeConsumerMetrics = flag.Bool("streams-exclude-consumer-metrics", getEnvBool("REDIS_EXPORTER_STREAMS_EXCLUDE_CONSUMER_METRICS", false), "Don't collect per consumer metrics for streams (decreases cardinality)")
Copy link
Owner

Choose a reason for hiding this comment

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

streams-exclude-consumer-metrics - here you got it right :-)

Copy link
Owner

@oliver006 oliver006 left a comment

Choose a reason for hiding this comment

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

Looks good now, thanks for the PR!

@nantiferov
Copy link
Contributor Author

@oliver006 when you have time, could you please merge this PR if all looks good now and release a new version?

@oliver006 oliver006 merged commit 2c968d5 into oliver006:master May 30, 2024
4 of 5 checks passed
@oliver006
Copy link
Owner

Thanks for the nudge.
Do you think we can get #911 sorted and into the next release as well?

@nantiferov
Copy link
Contributor Author

Yep, probably can check it later today.

Nklya pushed a commit to Nklya/redis_exporter that referenced this pull request May 30, 2024
…6#906)

* Feature: Add option to exclude consumer from Stream metrics
@oliver006
Copy link
Owner

oliver006 commented May 31, 2024

Released v1.60.0 which includes this and your other PRs - nice work, thanks for all your contributions!

@nantiferov
Copy link
Contributor Author

Thank you!

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.

Feature: Add option to exclude per consumer stream metrics
3 participants