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

Fix/metrics interpolation #2030

Merged
merged 2 commits into from
Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions agent/backend/pktvisor/pktvisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ type pktvisorBackend struct {
adminAPIProtocol string

// added for Strings
agentTags string
agentTags map[string]string

// OpenTelemetry management
scrapeOtel bool
Expand Down Expand Up @@ -299,8 +299,8 @@ func (p *pktvisorBackend) Configure(logger *zap.Logger, repo policies.PolicyRepo
if p.adminAPIPort, prs = config["api_port"]; !prs {
return errors.New("you must specify pktvisor admin API port")
}
if agentTags, ok := config["agent_tags"]; ok {
p.agentTags = agentTags
if agentTags, ok := otelConfig["agent_tags"]; ok {
p.agentTags = agentTags.(map[string]string)
}

for k, v := range otelConfig {
Expand Down
6 changes: 3 additions & 3 deletions agent/otel/bridgeservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ type AgentBridgeService interface {
type AgentDataPerPolicy struct {
PolicyID string
Datasets string
AgentTags string
AgentTags map[string]string
}

var _ AgentBridgeService = (*bridgeService)(nil)

type bridgeService struct {
policyRepo policies.PolicyRepo
AgentTags string
AgentTags map[string]string
}

func NewBridgeService(policyRepo *policies.PolicyRepo, agentTags string) *bridgeService {
func NewBridgeService(policyRepo *policies.PolicyRepo, agentTags map[string]string) *bridgeService {
return &bridgeService{
policyRepo: *policyRepo,
AgentTags: agentTags,
Expand Down
26 changes: 20 additions & 6 deletions agent/otel/otlpmqttexporter/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,25 @@ func (e *exporter) injectAttribute(metricsRequest pmetricotlp.Request, attribute
metricItem := metrics.At(i)
switch metricItem.Type() {
case pmetric.MetricTypeExponentialHistogram:
metricsRequest.Metrics().ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(i).ExponentialHistogram().DataPoints().At(0).Attributes().PutStr(attribute, value)
for i := 0; i < metricItem.ExponentialHistogram().DataPoints().Len(); i++ {
metricItem.ExponentialHistogram().DataPoints().At(i).Attributes().PutStr(attribute, value)
}
case pmetric.MetricTypeGauge:
metricsRequest.Metrics().ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(i).Gauge().DataPoints().At(0).Attributes().PutStr(attribute, value)
for i := 0; i < metricItem.Gauge().DataPoints().Len(); i++ {
metricItem.Gauge().DataPoints().At(i).Attributes().PutStr(attribute, value)
}
case pmetric.MetricTypeHistogram:
metricsRequest.Metrics().ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(i).Histogram().DataPoints().At(0).Attributes().PutStr(attribute, value)
for i := 0; i < metricItem.Histogram().DataPoints().Len(); i++ {
metricItem.Gauge().DataPoints().At(i).Attributes().PutStr(attribute, value)
}
case pmetric.MetricTypeSum:
metricsRequest.Metrics().ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(i).Sum().DataPoints().At(0).Attributes().PutStr(attribute, value)
for i := 0; i < metricItem.Sum().DataPoints().Len(); i++ {
metricItem.Gauge().DataPoints().At(i).Attributes().PutStr(attribute, value)
}
case pmetric.MetricTypeSummary:
metricsRequest.Metrics().ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(i).Summary().DataPoints().At(0).Attributes().PutStr(attribute, value)
for i := 0; i < metricItem.Summary().DataPoints().Len(); i++ {
metricItem.Gauge().DataPoints().At(i).Attributes().PutStr(attribute, value)
}
default:
e.logger.Error("Unknown metric type: " + metricItem.Type().String())
}
Expand Down Expand Up @@ -204,7 +214,11 @@ func (e *exporter) pushMetrics(ctx context.Context, md pmetric.Metrics) error {
// injecting policy ID attribute on metrics
tr = e.injectAttribute(tr, "policy_id", e.policyID)
tr = e.injectAttribute(tr, "dataset_ids", datasets)
tr = e.injectAttribute(tr, "agent_tags", agentData.AgentTags)
// Insert pivoted agentTags
for key, value := range agentData.AgentTags {
tr = e.injectAttribute(tr, key, value)
}

e.logger.Info("scraped metrics for policy", zap.String("policy", e.policyName), zap.String("policy_id", e.policyID))
request, err := tr.MarshalProto()
if err != nil {
Expand Down
40 changes: 30 additions & 10 deletions sinker/otel/orbreceiver/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,25 @@ func (r *OrbReceiver) injectAttribute(metricsRequest pmetricotlp.Request, attrib
metricItem := metrics.At(i)
switch metricItem.Type() {
case pmetric.MetricTypeExponentialHistogram:
metricsRequest.Metrics().ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(i).ExponentialHistogram().DataPoints().At(0).Attributes().PutStr(attribute, value)
for i := 0; i < metricItem.ExponentialHistogram().DataPoints().Len(); i++ {
metricItem.ExponentialHistogram().DataPoints().At(i).Attributes().PutStr(attribute, value)
}
case pmetric.MetricTypeGauge:
metricsRequest.Metrics().ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(i).Gauge().DataPoints().At(0).Attributes().PutStr(attribute, value)
for i := 0; i < metricItem.Gauge().DataPoints().Len(); i++ {
metricItem.Gauge().DataPoints().At(i).Attributes().PutStr(attribute, value)
}
case pmetric.MetricTypeHistogram:
metricsRequest.Metrics().ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(i).Histogram().DataPoints().At(0).Attributes().PutStr(attribute, value)
for i := 0; i < metricItem.Histogram().DataPoints().Len(); i++ {
metricItem.Gauge().DataPoints().At(i).Attributes().PutStr(attribute, value)
}
case pmetric.MetricTypeSum:
metricsRequest.Metrics().ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(i).Sum().DataPoints().At(0).Attributes().PutStr(attribute, value)
for i := 0; i < metricItem.Sum().DataPoints().Len(); i++ {
metricItem.Gauge().DataPoints().At(i).Attributes().PutStr(attribute, value)
}
case pmetric.MetricTypeSummary:
metricsRequest.Metrics().ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(i).Summary().DataPoints().At(0).Attributes().PutStr(attribute, value)
for i := 0; i < metricItem.Summary().DataPoints().Len(); i++ {
metricItem.Gauge().DataPoints().At(i).Attributes().PutStr(attribute, value)
}
default:
r.cfg.Logger.Error("Unknown metric type: " + metricItem.Type().String())
}
Expand All @@ -191,15 +201,25 @@ func (r *OrbReceiver) deleteAttribute(metricsRequest pmetricotlp.Request, attrib
metricItem := metrics.At(i)
switch metricItem.Type() {
case pmetric.MetricTypeExponentialHistogram:
metricsRequest.Metrics().ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(i).ExponentialHistogram().DataPoints().At(0).Attributes().Remove(attribute)
for i := 0; i < metricItem.ExponentialHistogram().DataPoints().Len(); i++ {
metricItem.ExponentialHistogram().DataPoints().At(0).Attributes().Remove(attribute)
}
case pmetric.MetricTypeGauge:
metricsRequest.Metrics().ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(i).Gauge().DataPoints().At(0).Attributes().Remove(attribute)
for i := 0; i < metricItem.Gauge().DataPoints().Len(); i++ {
metricItem.ExponentialHistogram().DataPoints().At(0).Attributes().Remove(attribute)
}
case pmetric.MetricTypeHistogram:
metricsRequest.Metrics().ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(i).Histogram().DataPoints().At(0).Attributes().Remove(attribute)
for i := 0; i < metricItem.Histogram().DataPoints().Len(); i++ {
metricItem.ExponentialHistogram().DataPoints().At(0).Attributes().Remove(attribute)
}
case pmetric.MetricTypeSum:
metricsRequest.Metrics().ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(i).Sum().DataPoints().At(0).Attributes().Remove(attribute)
for i := 0; i < metricItem.Sum().DataPoints().Len(); i++ {
metricItem.ExponentialHistogram().DataPoints().At(0).Attributes().Remove(attribute)
}
case pmetric.MetricTypeSummary:
metricsRequest.Metrics().ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(i).Summary().DataPoints().At(0).Attributes().Remove(attribute)
for i := 0; i < metricItem.Summary().DataPoints().Len(); i++ {
metricItem.ExponentialHistogram().DataPoints().At(0).Attributes().Remove(attribute)
}
default:
r.cfg.Logger.Error("Unknown metric type: " + metricItem.Type().String())
}
Expand Down