Skip to content
This repository has been archived by the owner on Apr 28, 2022. It is now read-only.

Parity with Java for Metrics #54

Closed
wants to merge 1 commit into from
Closed

Parity with Java for Metrics #54

wants to merge 1 commit into from

Conversation

cwe1ss
Copy link
Collaborator

@cwe1ss cwe1ss commented Apr 11, 2018

I'm comparing the C# code with the Java code and I'm trying to get it as close as possible to make future changes easier. (#29)

This PR brings the "Metrics" feature closer to Java. However there still need to be a few differences:

  • Java has a concrete class called Metrics which is used everywhere. Having a class with this name is not nice in C# because the namespace has the same name and people would have to use Metrics.Metrics. As I couldn't come up with a different name, I just kept the already existing IMetrics interface and moved Java's logic to a new MetricsImpl class.
  • C# can't use complex types on attribute constructors. The current C# code already used some custom logic for this but I reverted this and simplified it. It's now pretty close to Java.

I also replaced the metrics unit tests with the current version from Java.

Signed-off-by: Christian Weiss <[email protected]>
@cwe1ss cwe1ss added the enhancement New feature or request label Apr 11, 2018
@cwe1ss cwe1ss self-assigned this Apr 11, 2018
Copy link
Member

@yurishkuro yurishkuro left a comment

Choose a reason for hiding this comment

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

lgtm overall

public class MetricsImpl : IMetrics
{
/// <inheritdoc/>
[Metric(name: "traces", tag1Key: "state", tag1Value: "started", tag2Key: "sampled", tag2Value: "y")]
Copy link
Member

Choose a reason for hiding this comment

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

Is this a limitation of the annotation syntax that you can't do a dictionary?

If so I would recommend just having a string like tags="state=started, sampled=y" and parse it during construction. The objective is to make the annotation readable & easy, not to help the parsing engine (which isn't that complicated anyway).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, this is a limitation in C#! I'll change it to your recommendation.

@@ -28,7 +28,11 @@ private RemoteReporter(ITransport transport, ILoggerFactory loggerFactory, IMetr
try
{
int n = await _transport.CloseAsync(CancellationToken.None).ConfigureAwait(false);
_metrics.ReporterSuccess.Inc(n);

if (n > 0)
Copy link
Member

Choose a reason for hiding this comment

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

does it matter if it's 0? seems like unnecessary complication of the code

{
Assert.IsType<InMemoryMetricsFactory.InMemoryElement>(reporter._metrics.ReporterSuccess);
}
metrics.ReporterSuccess.Received(1).Inc(2);
Copy link
Member

Choose a reason for hiding this comment

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

why not use in-memory implementation and just assert the final counter value? With a mock you are testing not only external side effect, i.e. the resulting value of the counter which is what we're interested in, but also how it gets there, which is mostly an irrelevant implementation detail that makes the test itself more brittle.

@cwe1ss
Copy link
Collaborator Author

cwe1ss commented May 1, 2018

Superseded by #55.

@cwe1ss cwe1ss closed this May 1, 2018
@cwe1ss cwe1ss deleted the cweiss/Metrics branch May 14, 2018 19:31
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants