Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Grryum
Copy link
Contributor

@Grryum Grryum commented May 31, 2023

This merge request introduces a new feature that allows for the dumping of current ZIO metric values for the purpose of debugging. The primary objective of this feature is to provide developers efficient method to gain insights into the current state of various metrics during debugging sessions.

Dump will look like:

c1   tags[x: a, y: b]  Counter[2.0]
g1   tags[x: a, y: b]  Gauge[3.0]
h1   tags[x: a, y: b]  Histogram[buckets: [(1.0 -> 1), (2.0 -> 1), (3.0 -> 2), (1.7976931348623157E308 -> 2)], count: [2], min: [1.0], max: [3.0], sum: [4.0]]
s1   tags[x: a, y: b]  Summary[quantiles: [(0.1 -> None), (0.5 -> Some(1.0)), (0.9 -> Some(1.0))], count: [2], min: [1.0], max: [3.0], sum: [4.0]]
sc1  tags[x: a, y: b]  Frequency[(strValue2 -> 1), (strValue1 -> 2)]

Closes #5543

MetricsRenderer.prettyPrint(metrics)
}

object CurrentMetrics {
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 not sure a user might think to look here.

Perhaps we could do:

object ZIO {
  def metrics: UIO[zio.metrics.Metrics]
}

Then Metrics can have methods such as dump, etc., on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, thank you for idea! Done.


import java.io.IOException

final case class CurrentMetrics private[metrics] (metrics: Set[MetricPair.Untyped]) extends Serializable {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
final case class CurrentMetrics private[metrics] (metrics: Set[MetricPair.Untyped]) extends Serializable {
final case class Metrics private[metrics] (metrics: Set[MetricPair.Untyped]) extends Serializable {

/**
* Dumps all current metrics to the specified callback.
*/
def dumpWith[R, E, T](f: CurrentMetrics => ZIO[R, E, T])(implicit trace: Trace): ZIO[R, E, T] =
Copy link
Member

Choose a reason for hiding this comment

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

This should not exist because a user can always flatMap a Metrics, having acquired it with ZIO.metrics.

/**
* Dumps all current metrics to the console.
*/
def dump(implicit trace: Trace): IO[IOException, Unit] =
Copy link
Member

Choose a reason for hiding this comment

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

I'd make this a method on Metrics.

jdegoes
jdegoes previously approved these changes Jun 13, 2023
@jdegoes
Copy link
Member

jdegoes commented Jun 13, 2023

@Grryum Good to merge when the CI is passing. Can you please take a look at the failures? 🙏

@Grryum
Copy link
Contributor Author

Grryum commented Jun 13, 2023

@jdegoes first of all thank you for review! I've fixed all pipeline failures.


}

private[metrics] object MetricsRenderer {
Copy link
Contributor

Choose a reason for hiding this comment

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

At this point this could be changed to private object Metrics or these could be inlined as private methods in the Metrics class.

* Dumps all current metrics to the console.
*/
def dump(implicit trace: Trace): IO[IOException, Unit] =
prettyPrint.flatMap(zio.Console.print(_))
Copy link
Contributor

Choose a reason for hiding this comment

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

printLine


import java.io.IOException

final case class Metrics private[zio] (metrics: Set[MetricPair.Untyped]) extends Serializable {
Copy link
Contributor

Choose a reason for hiding this comment

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

Case classes are already serializable so no need for this unless you're trying to do the product with serializable thing.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could construct the Metrics in the companion object so this constructor can be private instead of package private.

Copy link
Contributor Author

@Grryum Grryum Jun 14, 2023

Choose a reason for hiding this comment

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

Sure, forgot to remove this, thank you!

@Grryum
Copy link
Contributor Author

Grryum commented Jun 14, 2023

@adamgfraser I've also added MetricKey description to rendered string.

@Grryum Grryum requested review from adamgfraser and jdegoes June 24, 2023 22:45
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.

Implement Developer Mode Metrics Reporting

3 participants