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: provide memstat methods to assist on testing (pipe-538) #210

Merged
merged 3 commits into from
Nov 16, 2023

Conversation

lvrach
Copy link
Member

@lvrach lvrach commented Nov 15, 2023

Description

Motivation

The existing method for verifying stats .Get during tests was limiting and cumbersome.

You could only retrieve a specific combination of name and tags. This way:

For these reasons, I wanted a way to retrieve a collection of metrics registered to the store.

Solution

  • Introduce .GetAll which returns a Metrics array, containing all possible name+stats combinations captured using the storage.
  • Introduce .GetByName which returns the subset that belongs to a measurement name.

Metric type is a bit special, it has

  • Value just float used for metrics/gauges
  • Values float array for histograms
  • Durations for timers

The motivation here was to use the most convenient representation for the stat type used. I tried a few approaches:

  • using a method per stat type
  • using generic interface to describe each Metric

However, both approaches had extra overhead when writing tests. So, I decided to go with the simpler approach from the perspective of validation.

You can seem them being used here

Linear Ticket

https://linear.app/rudderstack/issue/PIPE-538/improve-memstats-testing

Security

  • The code changed/added as part of this pull request won't create any security issues with how the software is being used.

Copy link

codecov bot commented Nov 15, 2023

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (52204ef) 79.23% compared to head (8afcedf) 79.41%.

Files Patch % Lines
stats/memstats/stats.go 94.87% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #210      +/-   ##
==========================================
+ Coverage   79.23%   79.41%   +0.17%     
==========================================
  Files          70       70              
  Lines        5183     5222      +39     
==========================================
+ Hits         4107     4147      +40     
- Misses        873      874       +1     
+ Partials      203      201       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@lvrach lvrach changed the title feat: provide memstat methods to assist on testing feat: provide memstat methods to assist on testing (pipe-538) Nov 15, 2023
@lvrach lvrach marked this pull request as ready for review November 15, 2023 13:48
stats/memstats/stats.go Outdated Show resolved Hide resolved
stats/memstats/stats.go Outdated Show resolved Hide resolved
lvrach and others added 2 commits November 15, 2023 16:26
Co-authored-by: Akash Chetty <achetty.iitr@gmail.com>
@achettyiitr
Copy link
Member

achettyiitr commented Nov 15, 2023

Thanks @lvrach for picking this up. It would be helpful in scenarios like this.

Copy link
Collaborator

@fracasula fracasula left a comment

Choose a reason for hiding this comment

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

Nice one. Just left an optional comment.

stats/memstats/stats.go Show resolved Hide resolved
@fracasula fracasula merged commit 8150925 into main Nov 16, 2023
10 checks passed
@fracasula fracasula deleted the feature.memstats-visibility branch November 16, 2023 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants