-
Notifications
You must be signed in to change notification settings - Fork 2
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
Push host metadata on startup #65
Changes from 4 commits
5a715dc
95a4c5c
61d67fa
dc36058
e29dd46
1314caa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,12 @@ | |
package datadogexporter | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
"time" | ||
|
||
"go.opentelemetry.io/collector/consumer/pdata" | ||
"go.uber.org/zap" | ||
|
@@ -26,23 +31,47 @@ type metricsExporter struct { | |
logger *zap.Logger | ||
cfg *Config | ||
client *datadog.Client | ||
tags []string | ||
} | ||
|
||
func newMetricsExporter(logger *zap.Logger, cfg *Config) (*metricsExporter, error) { | ||
client := datadog.NewClient(cfg.API.Key, "") | ||
client.SetBaseUrl(cfg.Metrics.TCPAddr.Endpoint) | ||
|
||
// Calculate tags at startup | ||
tags := cfg.TagsConfig.GetTags(false) | ||
return &metricsExporter{logger, cfg, client}, nil | ||
} | ||
|
||
// pushHostMetadata sends a host metadata payload to the "/intake" endpoint | ||
func (exp *metricsExporter) pushHostMetadata(metadata hostMetadata) error { | ||
path := exp.cfg.Metrics.TCPAddr.Endpoint + "/intake" | ||
buf, _ := json.Marshal(metadata) | ||
req, _ := http.NewRequest(http.MethodPost, path, bytes.NewBuffer(buf)) | ||
req.Header.Set("DD-API-KEY", exp.cfg.API.Key) | ||
req.Header.Set("Content-Type", "application/json") | ||
mx-psi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
client := &http.Client{Timeout: 10 * time.Second} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a blocker for this PR, but we should investigate if we also need here all the options that the Agent passes as
This git blame might help us track why they were added in the Agent: https://github.com/DataDog/datadog-agent/blame/7305c07eaf917f63274749dfdd96119b0b713883/pkg/util/common.go Eg: the PR that disables FallbackDelay mentions "Some concerns have been raised about the effect this might have on the intake." Also, the proxy settings are probably something we also want. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
the zero value for the
I think we should keep (4) as is and maybe change (1)/(2)/(3) depending on what Agent Core says. If we change (1)/(2)/(3) we should also change it on the metrics exporter client which uses the default client (maybe on zorkian's library?). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Being consistent with how the proxy is configured everywhere else makes sense, I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Also, |
||
resp, err := client.Do(req) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
defer resp.Body.Close() | ||
|
||
return &metricsExporter{logger, cfg, client, tags}, nil | ||
if resp.StatusCode >= 400 { | ||
return fmt.Errorf( | ||
"'%d - %s' error when sending metadata payload to %s", | ||
resp.StatusCode, | ||
resp.Status, | ||
path, | ||
) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (exp *metricsExporter) processMetrics(metrics []datadog.Metric) { | ||
addNamespace := exp.cfg.Metrics.Namespace != "" | ||
overrideHostname := exp.cfg.Hostname != "" | ||
addTags := len(exp.tags) > 0 | ||
|
||
for i := range metrics { | ||
if addNamespace { | ||
|
@@ -53,11 +82,6 @@ func (exp *metricsExporter) processMetrics(metrics []datadog.Metric) { | |
if overrideHostname || metrics[i].GetHost() == "" { | ||
metrics[i].Host = GetHost(exp.cfg) | ||
} | ||
|
||
if addTags { | ||
metrics[i].Tags = append(metrics[i].Tags, exp.tags...) | ||
} | ||
|
||
} | ||
} | ||
|
||
|
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.
Could be done separately/tracked as an improvement, but ideally this should also send a host metadata payload every 30 minutes, so that:
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 will do this separately, right now it doesn't change but I want to add support for EC2 tags so this makes sense. Thanks!