-
Notifications
You must be signed in to change notification settings - Fork 31
writer: allow writing to multiple endpoints. #496
Conversation
7e8cf03
to
e11686c
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
1e49d6e
to
f7b442a
Compare
This comment has been minimized.
This comment has been minimized.
config/agent.go
Outdated
APIEndpoint string | ||
APIKey string `json:"-"` // never publish this | ||
APIEnabled bool | ||
APIEndpoint string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I should merge these two into one:
Endpoints []*Endpoint
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, don't see the point of treating main vs additional differently and if we need to we can just ensure the main is the first in this endpoints list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing it in the scope of this PR, separate commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Partial review, I'll look at the remaining files after lunch 👨🍳
config/agent.go
Outdated
APIEndpoint string | ||
APIKey string `json:"-"` // never publish this | ||
APIEnabled bool | ||
APIEndpoint string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, don't see the point of treating main vs additional differently and if we need to we can just ensure the main is the first in this endpoints list.
writer/datadog_endpoint.go
Outdated
apiKey := e.APIKey | ||
if apiKey == "" { | ||
// if this endpoint doesn't have its own API key, try the main one. | ||
apiKey = conf.APIKey |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't even allow this to occur. Looking at the infra PR, they dedupe endpoints missing apikey already at the config: https://github.com/DataDog/datadog-agent/pull/352/files#diff-091ace02b49a46f55f2586cfec89a160R95
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough, removed it entirely. I've modified the config to ignore endpoints without API keys; but I think deduping is a bit overkill unless I'm missing some aspect.
writer/datadog_endpoint.go
Outdated
// newClient returns a http.Client configured with the Agent options. | ||
func newClient(conf *config.AgentConfig, noProxy bool) *http.Client { | ||
transport := &http.Transport{ | ||
TLSClientConfig: &tls.Config{InsecureSkipVerify: conf.SkipSSLValidation}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've had some issues with some other code that was using custom transports. We should probably include all settings set in DefaultTransport
as well otherwise most timeouts will be zeroed out and we'll wait for much longer than we should when network issues happen.
https://golang.org/src/net/http/transport.go (line 42). I'm fine with this going to another PR but we should track this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're very right here, this was indeed an oversight. Great catch! I've copied the http.DefaultTransport
except the Proxy: http.ProxyFromEnvironment
part which I assume was likely also an oversight on our behalf. We can ponder whether to introduce that back in a separate topic. I'm afraid not to cause any backwards breaking changes because of introducing it.
writer/multi_writer.go
Outdated
if len(endpoints) == 1 { | ||
return NewCustomQueuablePayloadSender(endpoints[0], cfg) | ||
} | ||
var senders []PayloadSender |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nit, we can already allocate enough space for len(endpoints)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely.
writer/multi_writer.go
Outdated
func newMultiSender(cfg config.QueuablePayloadSenderConf) func([]Endpoint) PayloadSender { | ||
return func(endpoints []Endpoint) PayloadSender { | ||
if len(endpoints) == 1 { | ||
return NewCustomQueuablePayloadSender(endpoints[0], cfg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice shortcut here, saving a bunch of overhead if not needed 👍
writer/multi_writer.go
Outdated
|
||
// newMultiSender returns a new factory to generate PayloadSenders capable of forwarding | ||
// payloads to multiple endpoints. | ||
func newMultiSender(cfg config.QueuablePayloadSenderConf) func([]Endpoint) PayloadSender { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name here threw me off initially and breaks expectations imo.
Can we have a newMultiSender(cfg, []Endpoint)
and turn this into
newMultiSenderFactory(cfg) func([]Endpoint) {
return func (endpoints) PayloadSender {
return newMultiSender(cfg, endpoints);
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it. Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great review and I agree with all your points. Submitted a new commit addressing all comments, except the merging of APIEndpoint
and AdditionalEndpoints
into one, which will follow in this very PR in an upcoming commit (tomorrow).
config/agent.go
Outdated
APIEndpoint string | ||
APIKey string `json:"-"` // never publish this | ||
APIEnabled bool | ||
APIEndpoint string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing it in the scope of this PR, separate commit.
writer/datadog_endpoint.go
Outdated
apiKey := e.APIKey | ||
if apiKey == "" { | ||
// if this endpoint doesn't have its own API key, try the main one. | ||
apiKey = conf.APIKey |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough, removed it entirely. I've modified the config to ignore endpoints without API keys; but I think deduping is a bit overkill unless I'm missing some aspect.
writer/datadog_endpoint.go
Outdated
// newClient returns a http.Client configured with the Agent options. | ||
func newClient(conf *config.AgentConfig, noProxy bool) *http.Client { | ||
transport := &http.Transport{ | ||
TLSClientConfig: &tls.Config{InsecureSkipVerify: conf.SkipSSLValidation}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're very right here, this was indeed an oversight. Great catch! I've copied the http.DefaultTransport
except the Proxy: http.ProxyFromEnvironment
part which I assume was likely also an oversight on our behalf. We can ponder whether to introduce that back in a separate topic. I'm afraid not to cause any backwards breaking changes because of introducing it.
writer/multi_writer.go
Outdated
|
||
// newMultiSender returns a new factory to generate PayloadSenders capable of forwarding | ||
// payloads to multiple endpoints. | ||
func newMultiSender(cfg config.QueuablePayloadSenderConf) func([]Endpoint) PayloadSender { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it. Done.
writer/multi_writer.go
Outdated
if len(endpoints) == 1 { | ||
return NewCustomQueuablePayloadSender(endpoints[0], cfg) | ||
} | ||
var senders []PayloadSender |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely.
3e24e1b
to
07e2808
Compare
07e2808
to
65c92e4
Compare
36ea26c
to
5317672
Compare
5317672
to
e573587
Compare
@AlexJF merged all endpoints in the latest commit. Tested manually with app too, seems to work fine. PTAL when you get a chance. |
@AlexJF good catch, changed in next commit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good from my side! If everything works in practice lets ship it! 🚢
Seems Github is buggy. Kept getting errors from using the "Squash & Merge" button and PR is still open even though it was merged twice (see master commits) |
Seems Github is buggy. Kept getting errors from using the "Squash & Merge" button and PR is still open even though it was merged twice (see master commits) |
Seems Github is buggy. Kept getting errors from using the "Squash & Merge" button and PR is still open even though it was merged twice (see master commits) |
* writer: add support for multiple endpoints * writer: add host information to stats * statsd: ensure all stats get version tag * writer: remove statsClient field from BaseWriter
* writer: add support for multiple endpoints * writer: add host information to stats * statsd: ensure all stats get version tag * writer: remove statsClient field from BaseWriter * all: merge APIEndpoint into Endpoints
Description
This change adds a new set of options to the
apm_config
sub-section of the config file, enabling the possibility of forwarding data (traces, stats & services) to additional endpoints besides the main one.Example configuration:
References