Skip to content

Conversation

Frando
Copy link
Member

@Frando Frando commented Apr 11, 2025

Description

  • Adds a Metric trait that is implemented on Gauge and Counter to provide a common interface.
  • Adds a custom trait and derive macro Iterable that works similar to struct_iterable, but returns an iterator over &dyn Metric and does not allocate for iteration.
  • Adds a derive macro MetricsGroup that expands to the Iterable impl and also implements Default by calling FieldType::new(description) for each field, where description is the first line of the field's doc comment, or a custom string set via #[metrics(description = "my description")]. Also implements MetricsGroup, with a name of either the struct name converted to camel_case, or a custom name set via #[metrics_group(name = "my_name")]
  • Simplifies the iterators over MetricsGroup and MetricsGroupSet by using the new Metric trait and the dyn field iterator from the derived Iterable impl
  • Removes the MetricDescription types, those are not needed anymore.

Breaking Changes

  • struct_iterable::Iterable is no longer exported from iroh-metrics, and is no longer a supertrait of MetricsGroup
  • instead, MetricsGroup now has iroh_metrics::Iterable and iroh_metrics::IntoIterable supertraits. They can be implemented manually, but it is recommended to use the new MetricsGroup or Iterable derive macros exported from iroh_metrics. See their docs for details.
  • MetricsGroupSet::iter is renamed to MetricsGroupSet::groups
  • MetricsGroup::values and MetricsGroup::describe are removed. Use MetricsGroup::iter instead.
  • MetricItem struct changed, but still provides access to the same data, through the name() method and its deref to &dyn Metric.
  • MetricDescription is removed, everything there is now accessible over MetricItem through MetricsGroup::iter.

Notes & open questions

Change checklist

  • Self-review.
  • Documentation updates following the style guide, if relevant.
  • Tests if relevant.
  • All breaking changes documented.

@Frando Frando changed the title Frando/refactor2 refactor: Add derive macro and Metric trait Apr 11, 2025
Copy link

github-actions bot commented Apr 11, 2025

Documentation for this PR has been generated and is available at: https://n0-computer.github.io/iroh-metrics/pr/18/docs/iroh_gossip/

Last updated: 2025-04-11T09:40:08Z

@Frando Frando force-pushed the Frando/refactor2 branch 2 times, most recently from 34dedbc to 2206f7a Compare April 11, 2025 08:34
@Frando Frando force-pushed the Frando/refactor2 branch from 2206f7a to 7d3af42 Compare April 11, 2025 08:35
@Frando Frando requested a review from matheus23 April 11, 2025 08:35
@Frando Frando force-pushed the Frando/refactor2 branch from 47575bc to 4f10df0 Compare April 11, 2025 08:41
@n0bot n0bot bot added this to iroh Apr 11, 2025
@github-project-automation github-project-automation bot moved this to 🏗 In progress in iroh Apr 11, 2025
@Frando Frando requested review from dignifiedquire and Arqu and removed request for matheus23 April 11, 2025 09:33
@Frando Frando mentioned this pull request Apr 11, 2025
4 tasks
@Frando Frando marked this pull request as ready for review April 11, 2025 10:03
Copy link
Contributor

@Arqu Arqu left a comment

Choose a reason for hiding this comment

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

Working through macros is always slightly mind bending.
Thanks for the tests, makes it so much easier to parse and understand.
👍

@Frando Frando merged commit 7ddd198 into Frando/refactor Apr 14, 2025
@github-project-automation github-project-automation bot moved this from 🏗 In progress to ✅ Done in iroh Apr 14, 2025
@dignifiedquire dignifiedquire deleted the Frando/refactor2 branch April 14, 2025 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

2 participants