Skip to content

Add support for universal service tagging#139

Merged
ogaca-dd merged 4 commits intoDataDog:masterfrom
kevingosse:kevin/tagging
Oct 22, 2020
Merged

Add support for universal service tagging#139
ogaca-dd merged 4 commits intoDataDog:masterfrom
kevingosse:kevin/tagging

Conversation

@kevingosse
Copy link
Copy Markdown
Contributor

Read the DD_SERVICE, DD_ENV, and DD_VERSION environment variables and set the tags appropriately.

Comment thread src/StatsdClient/StatsdConfig.cs Outdated
StatsdMaxUDPPacketSize = DefaultStatsdMaxUDPPacketSize;
Advanced = new AdvancedStatsConfig();

Service = System.Environment.GetEnvironmentVariable(ServiceEnvVar);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm not sure how defensive we need to be about GetEnvironmentVariable calls throwing a SecurityException since I see many other of these calls in the codebase that are not wrapped in try/catch blocks, but that came to mind when I read this block

{
Environment.SetEnvironmentVariable("DD_ENTITY_ID", "foobar");
using (var nonStaticServiceInstance = new DogStatsdService())
Environment.SetEnvironmentVariable(envVar, "foobar");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should be careful about static data like these affecting other tests running at the same time, but we don't have a good way to fake env vars here, do we? (non-blocking)

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.

Yes it is an issue.
I have not noticed flaky tests because of that so I think we can ignore it. If I notice something, I will mock Environment.GetEnvironmentVariable.

Comment thread tests/StatsdClient.Tests/GlobalSetup.cs
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 👍 , just a few minor comments.
It worths reading all the comments before starting any changes.

_prefix = prefix;
_optionalTelemetry = optionalTelemetry;

var environmentTags = new List<string>();
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.

Statsd is deprecated and will be removed soon (Not thread safe, slow, does not support Windows Named pipe).
Note: You can keep the changes in the file, no need to revert them.

Comment thread src/StatsdClient/StatsdConfig.cs Outdated
Comment thread src/StatsdClient/StatsdConfig.cs
Comment thread src/StatsdClient/StatsdConfig.cs Outdated
{
Environment.SetEnvironmentVariable("DD_ENTITY_ID", "foobar");
using (var nonStaticServiceInstance = new DogStatsdService())
Environment.SetEnvironmentVariable(envVar, "foobar");
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.

Yes it is an issue.
I have not noticed flaky tests because of that so I think we can ignore it. If I notice something, I will mock Environment.GetEnvironmentVariable.

using StatsdClient;

[SetUpFixture]
public class GlobalSetup
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.

Is GlobalSetup needed as setting the env var is done in a single function Setting_tag_with_env_arg?
Note: If Environment.GetEnvironmentVariable starts to be annoying in the unit tests, I will mock Environment.GetEnvironmentVariable.

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.

This is not strictly needed, but remember that the statsd client now automatically populates tags from environment variables. On my machine I have the DD_ENV variable set, and so completely unrelated tests started failing because of the unexpected extra tag. The GlobalSetup is not needed for the CI, but this is a convenience for developers running tests locally.

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.

It makes sense!
Note: _values and public void TearDown() can be removed (I can do it later).

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.

LGTM!

using StatsdClient;

[SetUpFixture]
public class GlobalSetup
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.

It makes sense!
Note: _values and public void TearDown() can be removed (I can do it later).

@ogaca-dd ogaca-dd merged commit 66f080d into DataDog:master Oct 22, 2020
@kevingosse kevingosse deleted the kevin/tagging branch October 22, 2020 15:25
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.

5 participants