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 Keyspace hits metrics for set #2579

Open
wants to merge 4 commits into
base: unstable
Choose a base branch
from

Conversation

chenbt-hz
Copy link
Collaborator

@chenbt-hz chenbt-hz commented Apr 3, 2024

修改内容
1.新增keyspace_hits、keyspace_misses指标
2.修改了set相关命令的返回结果,使得keyspace_hits、keyspace_misses可以正确统计
3.新增了go测试

需要审查的点

  • 当前修改新增了kNoExists是否合理?
  • 当前返回是否符合预期,尤其是异常列表中的情况能否接受?

说明

这次改动主要为了在pika支持keyspace hit相关参数。 关联的issue: #2423
参考redis的实现: redis在执行操作前会统一在内存查找key是否存在并统计
但在pika这一层,需要在各个命令执行阶段实现统计。

  • 本次的改动默认s_ = db_->storage()返回的状态对象能够符合预期的返回s_.IsNotFound()==true。
    即,当key不存在时s_.IsNotFound()==true。
  • 管理命令、有部分的write命令无关key是否存在,因此这些命令将不会纳入keyspace_hit相关的统计。
  • 对于执行报错的命令,不会纳入keyspace_hit相关的统计。
  • 对于read相关命令以及关于某个key的统计命令,应根据实际含义添加keyspace_hit相关统计。

当前只修改set,后续还需要将其他的数据类型命令全部修改。

异常返回统计表

当前版本由于storage层部分s_.IsNotFound()接口返回结果不适配,导致部分命令的返回结果会超出预期,这里是相关列表。


异常描述 命令列表
执行不存在的key命令返回keyspace_hits SInter,SInterstore,SDiffstore
执行存在的key命令返回keyspace_misses  
对存在的key,操作不存在的元素命令返回keyspace_misses Sismember,SMoveCmd
对存在的key,操作存在的元素命令返回keyspace_misses  
操作多个key时,有key存在且有key不存在时,返回keyspace_misses  
操作多个key时,所有key不存在时,返回keyspace_hits Sdiff,SUnionstore,SUnion
   

@chenbt-hz chenbt-hz changed the title Keyspace hits Add Keyspace hits metrics Apr 3, 2024
@chenbt-hz chenbt-hz changed the title Add Keyspace hits metrics feat: Add Keyspace hits metrics Apr 3, 2024
@chenbt-hz
Copy link
Collaborator Author

基本的验证

$redis-cli -p 9221 info stats |grep key
keyspace_hits:19
keyspace_misses:0
is_scaning_keyspace:No

集成测试
image

image

@github-actions github-actions bot added the ✏️ Feature New feature or request label Apr 3, 2024
add   workflow_dispatch
add workflow_dispatch
@AlexStocks AlexStocks changed the title feat: Add Keyspace hits metrics feat: Add Keyspace hits metrics for set Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✏️ Feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant