Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add environment variables support for Client configuration #78

Merged
merged 4 commits into from
Mar 29, 2019

Conversation

clamoriniere
Copy link
Contributor

Support of 3 environment variables for Client configuration:

  • "DD_AGENT_HOST" used to provide the Agent hostname.
  • "DD_DOGSTATSD_PORT" used to provide the DogStatsD port.
  • "DD_ENTITY_ID" used to provide an identifier to the Client.

Support of 3 environment variables for Client configuration:
- "DD_AGENT_HOST" used to provide the Agent hostname.
- "DD_DOGSTATSD_PORT" used to provide the DogStatsD port.
- "DD_ENTITY_ID" used to provide an identifier to the Client.
Copy link
Member

@lucaspimentel lucaspimentel left a comment

Choose a reason for hiding this comment

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

Left a few comments regarding the amount of (avoidable) null checks in the code.

@@ -179,11 +207,32 @@ private static string EscapeContent(string content)
.Replace("\n", "\\n");
}

private static string ConcatTags(ref string[] constantTags,ref string[] tags)
Copy link
Member

@lucaspimentel lucaspimentel Mar 18, 2019

Choose a reason for hiding this comment

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

The references to constantTags and tags are never set in this method, so there's no need for the ref keyword. Arrays are always passed by reference, if that was the intent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, thank you for the info

@@ -179,11 +207,32 @@ private static string EscapeContent(string content)
.Replace("\n", "\\n");
}

private static string ConcatTags(ref string[] constantTags,ref string[] tags)
{
Copy link
Member

@lucaspimentel lucaspimentel Mar 18, 2019

Choose a reason for hiding this comment

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

I think it we can make the code around tags simpler by avoiding null arrays entirely. For example, early in the GetCommand() overloads, we can replace null arrays with empty ones.

// in Statsd class
private static readonly string[] EmptyArray = new string[0];
// in GetCommand()
constantTags = constantTags ?? EmptyArray;
tags = tags ?? EmptyArray;

If we guarantee that the constantTags and tags arrays are never null, we wouldn't need IsNullOrEmptyT<T>() and ConcatTags() becomes much simpler:

private static string ConcatTags(string[] constantTags, string[] tags)
{
    // concatenate all tags into a single enumerable
    var allTags = constantTags.Concat(tags);

    return "|#" + string.Join(",", allTags);
}

(edit: add a global empty array to avoid multiple allocations)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I took your remarks, and update the PR.

}
else
{
Array.Resize(ref _constantTags, _constantTags.Length + 1);
Copy link
Member

Choose a reason for hiding this comment

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

We might want to use List<T> if we plan on resizing the collections. Then this code becomes simply:

_constantTags.Add(entityIDTag);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Port = port;
if (Port == -1)
Copy link
Member

@lucaspimentel lucaspimentel Mar 18, 2019

Choose a reason for hiding this comment

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

Zero is more idiomatic as the "not set" value here, unless -1 is already defined elsewhere. Alternatively, we should check for both, or anything less than or equal to zero.

Suggested change
if (Port == -1)
if (Port == 0)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

src/StatsdClient/StatsdUDP.cs Outdated Show resolved Hide resolved
@clamoriniere clamoriniere force-pushed the feature/envvars_support branch 4 times, most recently from d00af7b to 1389f81 Compare March 19, 2019 09:57
@clamoriniere
Copy link
Contributor Author

@lucaspimentel Thanks the review.
I updated the PR with your comments.

@clamoriniere clamoriniere force-pushed the feature/envvars_support branch 2 times, most recently from 705f939 to 8c21c96 Compare March 19, 2019 10:21
@clamoriniere
Copy link
Contributor Author

@lucaspimentel any plan for merging it?

@lucaspimentel
Copy link
Member

@clamoriniere I'm not a maintainer on this repo or have write access. I think @yannmh can do it. Sorry about the confusion.

@yannmh yannmh merged commit 93c9ad6 into DataDog:master Mar 29, 2019
@lemkepf
Copy link

lemkepf commented Apr 4, 2019

Can we get a nuget release for this? The ConstantTags would be HUGE.

@yannmh
Copy link
Member

yannmh commented Apr 4, 2019

@lemkepf we are on it. ETA is before the week.

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.

None yet

4 participants