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

Remove stats.New #2442

Merged
merged 2 commits into from
Mar 29, 2022
Merged

Remove stats.New #2442

merged 2 commits into from
Mar 29, 2022

Conversation

oleiade
Copy link
Member

@oleiade oleiade commented Mar 14, 2022

This PR removes the stats.New method from the stats package. This change is intended to facilitate the move of the stats package code in a top-level metrics code. It was triggered and requested, as preparation step to #2433 and #2426.

Note that this PR might be taking certain shortcut, assuming the API will be readjusted later by the mentioned PRs.

Question marks

I took the initiative to use the registry.NewMetric in places where stats.New used to be. I could see two main alternatives:

  • using registry.MustNewMetric, but considering we use require.NoError everywhere else, I picked registry.NewMetric instead
  • instantiating Metric instances “manually” everywhere it's possible. However, considering we want to explicit that metrics should be created through a registry, I judged it more relevant.

Dependencies

This should be merged before #2433 and #2426

@oleiade oleiade force-pushed the refactor/remove_stats_New branch 4 times, most recently from 3b9c4c4 to a69cc06 Compare March 17, 2022 10:38
@oleiade oleiade changed the base branch from master to cleanup-7 March 17, 2022 10:38
@oleiade oleiade force-pushed the refactor/remove_stats_New branch 4 times, most recently from 750b46d to 83d73fc Compare March 17, 2022 11:28
@oleiade
Copy link
Member Author

oleiade commented Mar 17, 2022

Rebased this on #2426. This now depends on said PR.

A notable change made is that we now use the myMetric.AddSubmetric API to handle tagged metrics. This was made possible by #2426 changes.

The failing tests are inherited from #2426 and the PR should be green once those issues are addressed in said PR.

olegbespalov
olegbespalov previously approved these changes Mar 18, 2022
@na-- na-- force-pushed the cleanup-7 branch 2 times, most recently from 591a0fe to f06d6f0 Compare March 18, 2022 13:18
@na-- na-- force-pushed the cleanup-7 branch 3 times, most recently from 58fca82 to 8276246 Compare March 29, 2022 09:13
Base automatically changed from cleanup-7 to master March 29, 2022 13:26
This commit drops the dependency on `stats.New`, in favor of
`metrics.Registry.NewMetric`, which is considered the canonical way
of creating metrics.
if len(t) > 0 {
vt = t[0]
// newMetric instantiates a new Metric
func newMetric(name string, mt MetricType, vt ...ValueType) *Metric {
Copy link
Member

Choose a reason for hiding this comment

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

I am guessing this will get deleted when things are moved to metrics/?

Copy link
Member Author

@oleiade oleiade Mar 29, 2022

Choose a reason for hiding this comment

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

I ended up keeping it around, but private to, and only used in, the metrics package; as a helper. See #2442 (comment) for more details :)

@oleiade oleiade merged commit bd6adbd into master Mar 29, 2022
@oleiade oleiade deleted the refactor/remove_stats_New branch March 29, 2022 14:56
imiric pushed a commit to grafana/xk6-browser that referenced this pull request May 5, 2022
This is a fix for a breaking change introduced in k6 v0.38.0[1].

[1]: grafana/k6#2442
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants