Skip to content

statsd: support sending counters and gauges with timestamp.#185

Merged
remeh merged 7 commits intomasterfrom
remeh/timed-sample
Oct 25, 2022
Merged

statsd: support sending counters and gauges with timestamp.#185
remeh merged 7 commits intomasterfrom
remeh/timed-sample

Conversation

@remeh
Copy link
Copy Markdown
Contributor

@remeh remeh commented Oct 11, 2022

This PR adds the timestamp parameter to Gauge() and Counter().

Metrics sent with a timestamp to the DogStatsD server will be directly sent to the intake with no aggregation done server-side.

Even if the client side aggregation is enabled, metrics submitted with a timestamp won't go through any aggregation, they will be written in the serialization buffer as-is.

remeh added 3 commits October 11, 2022 09:31
This PR adds the `timestamp` parameter to `Gauge()` and `Counter()`.

Metrics sent with a `timestamp` to the DogStatsD server will be directly sent to the intake with no aggregation done server-side.

Even if the client side aggregation is enabled, metrics submitted with a timestamp won't go through any aggregation, they will be written in the serialization buffer as-is.
@remeh remeh force-pushed the remeh/timed-sample branch from 928facc to 3edcc86 Compare October 12, 2022 12:53
Copy link
Copy Markdown
Contributor

@ogaca-dd ogaca-dd left a comment

Choose a reason for hiding this comment

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

Great PR, thanks!!!

// available on older versions of .Net.
// Snippet from: https://github.com/dotnet/dotnet-api-docs/blob/13d97c7/snippets/csharp/System/DateTimeOffset/ToUnixTimeSeconds/tounixtimeseconds1.cs
// License: https://github.com/dotnet/dotnet-api-docs/blob/13d97c7/LICENSE-CODE
internal class DateTimeOffsetHelper
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am going to remove the support for old frameworks and so this code will not be needed anymore. I will open a PR soon.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

See #186.

Comment thread src/StatsdClient/StatsRouter.cs Outdated
{
break;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I suggest merging if (metric.Timestamp > 0) with if (_optionalCountAggregator != null), ie if (_optionalCountAggregator != null && metric.Timestamp == 0) to highlight that aggregation happens when it is enabled and when metric.Timestamp > 0.

}

[Test]
public void SendCounterWithTimestamp()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this is not needed to have 3 tests as the timestamp is just append at the end.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It validates that the timestamp is correctly appended in every situation (i.e. when there is a sample rate and when there is not, when there is tags and when there is not).

Copy link
Copy Markdown
Contributor

@ogaca-dd ogaca-dd Oct 18, 2022

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

While I agree that current code is just appending, units test are not here to test current code but to test current code and its future changes. Right now the implementation is basically appending to the end, in the future it may be different and, I want to test that there is a timestamp regardless if there is a sample rate, tags, or none of these.

Comment thread tests/StatsdClient.Tests/Serializer/MetricSerializerTests.cs Outdated
Comment thread src/StatsdClient/StatsRouter.cs Outdated
Comment thread tests/StatsdClient.Tests/StatsRouterTests.cs Outdated
@remeh remeh force-pushed the remeh/timed-sample branch from 1d8e8c5 to 875f669 Compare October 24, 2022 09:43
Copy link
Copy Markdown
Contributor

@ogaca-dd ogaca-dd left a comment

Choose a reason for hiding this comment

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

Thanks for this PR

@@ -1,343 +1,427 @@
using System;
Copy link
Copy Markdown
Contributor

@ogaca-dd ogaca-dd Oct 25, 2022

Choose a reason for hiding this comment

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

The end of the lines were changed.

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.

2 participants