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

feat/add histogram aggregator in defaultAggregator #226

Merged
merged 20 commits into from
May 30, 2022
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
979edfd
feat: support the histogram Gauge
NeJan2020 May 17, 2022
c56f5ba
fix: update Gauge model in each component
NeJan2020 May 17, 2022
0192eda
feat: add histogram aggregatorValues
NeJan2020 May 17, 2022
4b07104
fix: update Gauge model in each component
NeJan2020 May 17, 2022
7cc4751
fix: update test case
NeJan2020 May 17, 2022
75ee3ea
fix: support to aggregate the histogram Gauge
NeJan2020 May 18, 2022
cf0ab76
feat: a simple prometheus-exporter use prometheus-client
NeJan2020 May 17, 2022
7822c6d
feat:
NeJan2020 May 19, 2022
9b25ed7
feat: add explicit_boundaries config in histogram aggregation
NeJan2020 May 25, 2022
edfcb19
test: update test case
NeJan2020 May 26, 2022
f970214
style: Rename model.GaugeGroup
NeJan2020 May 26, 2022
faf0a1f
refactor: update swap function of labelKey
NeJan2020 May 26, 2022
ace35e5
rename: rename metricGroup to dataGroup
NeJan2020 May 26, 2022
9029ee8
config: remove histogram aggregation from default config
NeJan2020 May 26, 2022
f5aad62
perf: remove useless atomic exp
NeJan2020 May 26, 2022
f5a6075
fix: add a metric clear function for each type of metric
NeJan2020 May 26, 2022
02de63f
refactor: move defaultadapter to exporter.tools ; add histogram metri…
NeJan2020 May 27, 2022
c0356ce
rename: rename MetricGroupPool to DataGroupPool
NeJan2020 May 27, 2022
29a126c
fix: avoid `nullptr` when using otlp-exporter to export histogram data
NeJan2020 May 27, 2022
bf567ba
fix: add option to determine the attribute Type when using adapter
NeJan2020 May 27, 2022
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
14 changes: 7 additions & 7 deletions collector/analyzer/network/gauge_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import (

func createGaugeGroup() interface{} {
values := []*model.Gauge{
{Name: constvalues.ConnectTime, Value: 0},
{Name: constvalues.RequestSentTime, Value: 0},
{Name: constvalues.WaitingTtfbTime, Value: 0},
{Name: constvalues.ContentDownloadTime, Value: 0},
{Name: constvalues.RequestTotalTime, Value: 0},
{Name: constvalues.RequestIo, Value: 0},
{Name: constvalues.ResponseIo, Value: 0},
model.NewIntGauge(constvalues.ConnectTime, 0),
model.NewIntGauge(constvalues.RequestSentTime, 0),
model.NewIntGauge(constvalues.WaitingTtfbTime, 0),
model.NewIntGauge(constvalues.ContentDownloadTime, 0),
model.NewIntGauge(constvalues.RequestTotalTime, 0),
model.NewIntGauge(constvalues.RequestIo, 0),
model.NewIntGauge(constvalues.ResponseIo, 0),
}
gaugeGroup := model.NewGaugeGroup(constnames.NetRequestGaugeGroupName, model.NewAttributeMap(), uint64(time.Now().UnixNano()), values...)
return gaugeGroup
Expand Down
32 changes: 16 additions & 16 deletions collector/analyzer/network/network_analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,8 @@ func (na *NetworkAnalyzer) parseMultipleRequests(mps *messagePairs, parser *prot
func (na *NetworkAnalyzer) getConnectFailRecords(mps *messagePairs) []*model.GaugeGroup {
evt := mps.connects.event
ret := na.gaugeGroupPool.Get()
ret.UpdateAddGauge(constvalues.ConnectTime, int64(mps.connects.getDuration()))
ret.UpdateAddGauge(constvalues.RequestTotalTime, int64(mps.connects.getDuration()))
ret.UpdateAddIntGauge(constvalues.ConnectTime, int64(mps.connects.getDuration()))
ret.UpdateAddIntGauge(constvalues.RequestTotalTime, int64(mps.connects.getDuration()))
ret.Labels.UpdateAddIntValue(constlabels.Pid, int64(evt.GetPid()))
ret.Labels.UpdateAddStringValue(constlabels.SrcIp, evt.GetSip())
ret.Labels.UpdateAddStringValue(constlabels.DstIp, evt.GetDip())
Expand Down Expand Up @@ -526,13 +526,13 @@ func (na *NetworkAnalyzer) getRecords(mps *messagePairs, protocol string, attrib
labels.UpdateAddIntValue(constlabels.DnatPort, int64(mps.natTuple.ReplSrcPort))
}

ret.UpdateAddGauge(constvalues.ConnectTime, int64(mps.getConnectDuration()))
ret.UpdateAddGauge(constvalues.RequestSentTime, mps.getSentTime())
ret.UpdateAddGauge(constvalues.WaitingTtfbTime, mps.getWaitingTime())
ret.UpdateAddGauge(constvalues.ContentDownloadTime, mps.getDownloadTime())
ret.UpdateAddGauge(constvalues.RequestTotalTime, int64(mps.getConnectDuration()+mps.getDuration()))
ret.UpdateAddGauge(constvalues.RequestIo, int64(mps.getRquestSize()))
ret.UpdateAddGauge(constvalues.ResponseIo, int64(mps.getResponseSize()))
ret.UpdateAddIntGauge(constvalues.ConnectTime, int64(mps.getConnectDuration()))
ret.UpdateAddIntGauge(constvalues.RequestSentTime, mps.getSentTime())
ret.UpdateAddIntGauge(constvalues.WaitingTtfbTime, mps.getWaitingTime())
ret.UpdateAddIntGauge(constvalues.ContentDownloadTime, mps.getDownloadTime())
ret.UpdateAddIntGauge(constvalues.RequestTotalTime, int64(mps.getConnectDuration()+mps.getDuration()))
ret.UpdateAddIntGauge(constvalues.RequestIo, int64(mps.getRquestSize()))
ret.UpdateAddIntGauge(constvalues.ResponseIo, int64(mps.getResponseSize()))

ret.Timestamp = evt.GetStartTime()

Expand Down Expand Up @@ -574,13 +574,13 @@ func (na *NetworkAnalyzer) getRecordWithSinglePair(mps *messagePairs, mp *messag
labels.UpdateAddIntValue(constlabels.DnatPort, int64(mps.natTuple.ReplSrcPort))
}

ret.UpdateAddGauge(constvalues.ConnectTime, 0)
ret.UpdateAddGauge(constvalues.RequestSentTime, mp.getSentTime())
ret.UpdateAddGauge(constvalues.WaitingTtfbTime, mp.getWaitingTime())
ret.UpdateAddGauge(constvalues.ContentDownloadTime, mp.getDownloadTime())
ret.UpdateAddGauge(constvalues.RequestTotalTime, int64(mp.getDuration()))
ret.UpdateAddGauge(constvalues.RequestIo, int64(mp.getRquestSize()))
ret.UpdateAddGauge(constvalues.ResponseIo, int64(mp.getResponseSize()))
ret.UpdateAddIntGauge(constvalues.ConnectTime, 0)
ret.UpdateAddIntGauge(constvalues.RequestSentTime, mp.getSentTime())
ret.UpdateAddIntGauge(constvalues.WaitingTtfbTime, mp.getWaitingTime())
ret.UpdateAddIntGauge(constvalues.ContentDownloadTime, mp.getDownloadTime())
ret.UpdateAddIntGauge(constvalues.RequestTotalTime, int64(mp.getDuration()))
ret.UpdateAddIntGauge(constvalues.RequestIo, int64(mp.getRquestSize()))
ret.UpdateAddIntGauge(constvalues.ResponseIo, int64(mp.getResponseSize()))

ret.Timestamp = evt.GetStartTime()
return ret
Expand Down
4 changes: 2 additions & 2 deletions collector/analyzer/network/network_analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,9 @@ func (trace *Trace) Validate(t *testing.T, results []*model.GaugeGroup) {
for _, value := range result.Values {
expectValue, ok := expect.Values[value.Name]
if !ok {
t.Errorf("[Miss %s] want=nil, got=%d", value.Name, value.Value)
t.Errorf("[Miss %s] want=nil, got=%d", value.Name, value.GetInt().Value)
} else {
checkInt64Equal(t, value.Name, expectValue, value.Value)
checkInt64Equal(t, value.Name, expectValue, value.GetInt().Value)
}
}

Expand Down
15 changes: 3 additions & 12 deletions collector/analyzer/tcpmetricanalyzer/tcp_analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,7 @@ func (a *TcpMetricAnalyzer) generateRtt(event *model.KindlingEvent) (*model.Gaug
if rtt == 0 {
return nil, nil
}
gauge := &model.Gauge{
Name: constnames.TcpRttMetricName,
Value: int64(rtt),
}
gauge := model.NewIntGauge(constnames.TcpRttMetricName, int64(rtt))
return model.NewGaugeGroup(constnames.TcpGaugeGroupName, labels, event.Timestamp, gauge), nil
}

Expand All @@ -111,10 +108,7 @@ func (a *TcpMetricAnalyzer) generateRetransmit(event *model.KindlingEvent) (*mod
if err != nil {
return nil, err
}
gauge := &model.Gauge{
Name: constnames.TcpRetransmitMetricName,
Value: 1,
}
gauge := model.NewIntGauge(constnames.TcpRetransmitMetricName, 1)
return model.NewGaugeGroup(constnames.TcpGaugeGroupName, labels, event.Timestamp, gauge), nil
}

Expand All @@ -123,10 +117,7 @@ func (a *TcpMetricAnalyzer) generateDrop(event *model.KindlingEvent) (*model.Gau
if err != nil {
return nil, err
}
gauge := &model.Gauge{
Name: constnames.TcpDropMetricName,
Value: 1,
}
gauge := model.NewIntGauge(constnames.TcpDropMetricName, 1)
return model.NewGaugeGroup(constnames.TcpGaugeGroupName, labels, event.Timestamp, gauge), nil
}

Expand Down
4 changes: 2 additions & 2 deletions collector/consumer/exporter/otelexporter/consume.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ func (e *OtelExporter) exportMetric(result *defaultadapter.AdaptedResult) {
}
err := e.instrumentFactory.recordLastValue(gauge.Name, &model.GaugeGroup{
Name: gauge.Name,
Values: []*model.Gauge{{gauge.Name, gauge.Value}},
Values: []*model.Gauge{model.NewIntGauge(gauge.Name, gauge.GetInt().Value)},
Labels: result.AttrsMap,
Timestamp: result.Timestamp,
})
if err != nil {
e.telemetry.Logger.Error("Failed to record Gauge", zap.Error(err))
}
} else if ok {
measurements = append(measurements, e.instrumentFactory.getInstrument(gauge.Name, metricKind).Measurement(gauge.Value))
measurements = append(measurements, e.instrumentFactory.getInstrument(gauge.Name, metricKind).Measurement(gauge.GetInt().Value))
} else {
e.telemetry.Logger.Warn("Undefined metricKind for this Gauge", zap.String("GaugeName", gauge.Name))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ func TestAdapter_transform(t *testing.T) {
}),
123,
[]*model.Gauge{
{constvalues.RequestTotalTime, 123},
{constvalues.RequestIo, 456},
model.NewIntGauge(constvalues.RequestTotalTime, 123),
model.NewIntGauge(constvalues.RequestIo, 456),
}...),
},
want: model.NewAttributeMapWithValues(map[string]model.AttributeValue{
Expand Down Expand Up @@ -133,8 +133,8 @@ func TestAdapter_transform(t *testing.T) {
}),
123,
[]*model.Gauge{
{constvalues.RequestTotalTime, 123},
{constvalues.RequestIo, 456},
model.NewIntGauge(constvalues.RequestTotalTime, 123),
model.NewIntGauge(constvalues.RequestIo, 456),
}...),
},
want: model.NewAttributeMapWithValues(map[string]model.AttributeValue{
Expand Down Expand Up @@ -202,8 +202,8 @@ func TestAdapter_transform(t *testing.T) {
}),
123,
[]*model.Gauge{
{constvalues.RequestTotalTime, 123},
{constvalues.RequestIo, 456},
model.NewIntGauge(constvalues.RequestTotalTime, 123),
model.NewIntGauge(constvalues.RequestIo, 456),
}...),
},
want: model.NewAttributeMapWithValues(map[string]model.AttributeValue{
Expand Down Expand Up @@ -265,8 +265,8 @@ func TestAdapter_transform(t *testing.T) {
}),
123,
[]*model.Gauge{
{constvalues.RequestTotalTime, 123},
{constvalues.RequestIo, 456},
model.NewIntGauge(constvalues.RequestTotalTime, 123),
model.NewIntGauge(constvalues.RequestIo, 456),
}...),
},
want: model.NewAttributeMapWithValues(map[string]model.AttributeValue{
Expand Down Expand Up @@ -343,8 +343,8 @@ func TestAdapter_transform_protocol(t *testing.T) {
}),
123,
[]*model.Gauge{
{constvalues.RequestTotalTime, 123},
{constvalues.RequestIo, 456},
model.NewIntGauge(constvalues.RequestTotalTime, 123),
model.NewIntGauge(constvalues.RequestIo, 456),
}...),
},
want: model.NewAttributeMapWithValues(map[string]model.AttributeValue{
Expand All @@ -369,8 +369,8 @@ func TestAdapter_transform_protocol(t *testing.T) {
}),
123,
[]*model.Gauge{
{constvalues.RequestTotalTime, 123},
{constvalues.RequestIo, 456},
model.NewIntGauge(constvalues.RequestTotalTime, 123),
model.NewIntGauge(constvalues.RequestIo, 456),
}...),
},
want: model.NewAttributeMapWithValues(map[string]model.AttributeValue{
Expand All @@ -396,8 +396,8 @@ func TestAdapter_transform_protocol(t *testing.T) {
}),
123,
[]*model.Gauge{
{constvalues.RequestTotalTime, 123},
{constvalues.RequestIo, 456},
model.NewIntGauge(constvalues.RequestTotalTime, 123),
model.NewIntGauge(constvalues.RequestIo, 456),
}...),
},
want: model.NewAttributeMapWithValues(map[string]model.AttributeValue{
Expand All @@ -423,8 +423,8 @@ func TestAdapter_transform_protocol(t *testing.T) {
}),
123,
[]*model.Gauge{
{constvalues.RequestTotalTime, 123},
{constvalues.RequestIo, 456},
model.NewIntGauge(constvalues.RequestTotalTime, 123),
model.NewIntGauge(constvalues.RequestIo, 456),
}...),
},
want: model.NewAttributeMapWithValues(map[string]model.AttributeValue{
Expand Down Expand Up @@ -504,11 +504,11 @@ func TestAdapter_transform_single_net_gaugeGroup(t *testing.T) {
}),
123,
[]*model.Gauge{
{constvalues.RequestIo, 456},
{constvalues.RequestTotalTime, 123e6},
{constvalues.RequestSentTime, 201e6},
{constvalues.WaitingTtfbTime, 101e6},
{constvalues.ContentDownloadTime, 801e6},
model.NewIntGauge(constvalues.RequestIo, 456),
model.NewIntGauge(constvalues.RequestTotalTime, 123e6),
model.NewIntGauge(constvalues.RequestSentTime, 201e6),
model.NewIntGauge(constvalues.WaitingTtfbTime, 101e6),
model.NewIntGauge(constvalues.ContentDownloadTime, 801e6),
}...),
},
want: model.NewAttributeMapWithValues(map[string]model.AttributeValue{
Expand Down Expand Up @@ -587,11 +587,11 @@ func TestAdapter_transform_single_net_gaugeGroup(t *testing.T) {
}),
123*10e5,
[]*model.Gauge{
{constvalues.RequestTotalTime, 123},
{constvalues.RequestIo, 456},
{constvalues.RequestSentTime, 201},
{constvalues.WaitingTtfbTime, 101},
{constvalues.ContentDownloadTime, 801},
model.NewIntGauge(constvalues.RequestIo, 456),
model.NewIntGauge(constvalues.RequestTotalTime, 123e6),
model.NewIntGauge(constvalues.RequestSentTime, 201e6),
model.NewIntGauge(constvalues.WaitingTtfbTime, 101e6),
model.NewIntGauge(constvalues.ContentDownloadTime, 801e6),
}...),
},
want: model.NewAttributeMapWithValues(map[string]model.AttributeValue{
Expand Down Expand Up @@ -715,8 +715,8 @@ func TestAdapter_adapt(t *testing.T) {
}),
123,
[]*model.Gauge{
{constvalues.RequestTotalTime, 123},
{constvalues.RequestIo, 456},
model.NewIntGauge(constvalues.RequestTotalTime, 123),
model.NewIntGauge(constvalues.RequestIo, 456),
}...),
},
want: []attribute.KeyValue{
Expand Down Expand Up @@ -812,8 +812,8 @@ func TestAdapter_transform_async(t *testing.T) {
}),
123,
[]*model.Gauge{
{constvalues.RequestTotalTime, 123},
{constvalues.RequestIo, 456},
model.NewIntGauge(constvalues.RequestTotalTime, 123),
model.NewIntGauge(constvalues.RequestIo, 456),
}...),
},
want: model.NewAttributeMapWithValues(map[string]model.AttributeValue{
Expand Down Expand Up @@ -878,8 +878,8 @@ func TestAdapter_transform_async(t *testing.T) {
}),
123,
[]*model.Gauge{
{constvalues.RequestTotalTime, 123},
{constvalues.RequestIo, 456},
model.NewIntGauge(constvalues.RequestTotalTime, 123),
model.NewIntGauge(constvalues.RequestIo, 456),
}...),
},
want: model.NewAttributeMapWithValues(map[string]model.AttributeValue{
Expand Down Expand Up @@ -947,8 +947,8 @@ func TestAdapter_transform_async(t *testing.T) {
}),
123,
[]*model.Gauge{
{constvalues.RequestTotalTime, 123},
{constvalues.RequestIo, 456},
model.NewIntGauge(constvalues.RequestTotalTime, 123),
model.NewIntGauge(constvalues.RequestIo, 456),
}...),
},
want: model.NewAttributeMapWithValues(map[string]model.AttributeValue{
Expand Down Expand Up @@ -1010,8 +1010,8 @@ func TestAdapter_transform_async(t *testing.T) {
}),
123,
[]*model.Gauge{
{constvalues.RequestTotalTime, 123},
{constvalues.RequestIo, 456},
model.NewIntGauge(constvalues.RequestTotalTime, 123),
model.NewIntGauge(constvalues.RequestIo, 456),
}...),
},
want: model.NewAttributeMapWithValues(map[string]model.AttributeValue{
Expand Down
Loading