Skip to content

Commit

Permalink
Add service metrics transaction.success_count
Browse files Browse the repository at this point in the history
  • Loading branch information
carsonip committed Dec 12, 2022
1 parent 06b1a97 commit 9331523
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 19 deletions.
3 changes: 3 additions & 0 deletions apmpackage/apm/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
- description: Enable synthetic source for metrics data streams
type: enhancement
link: https://github.com/elastic/apm-server/pull/9756
- description: Change transaction.success_count type to aggregate_metric_double
type: enhancement
link: https://github.com/elastic/apm-server/pull/9791
- version: "8.6.0"
changes:
- description: Change `ecs.version` to a `constant_keyword` field
Expand Down
3 changes: 0 additions & 3 deletions apmpackage/apm/data_stream/internal_metrics/fields/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,6 @@
- name: transaction.failure_count
type: long
description: "Count of transactions with 'event.outcome: failure'"
- name: transaction.success_count
type: long
description: "Count of transactions with 'event.outcome: success'"
- name: transaction.duration.histogram
type: histogram
description: |
Expand Down
6 changes: 5 additions & 1 deletion apmpackage/apm/data_stream/internal_metrics/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ elasticsearch:
properties:
summary:
type: aggregate_metric_double
metrics: [sum, value_count]
metrics: [ sum, value_count ]
default_metric: sum
success_count:
type: aggregate_metric_double
metrics: [ sum, value_count ]
default_metric: sum
settings:
index:
sort.field: "@timestamp"
Expand Down
2 changes: 2 additions & 0 deletions internal/model/modeldecoder/v2/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ func TestDecodeMapToTransactionModel(t *testing.T) {
"DurationSummary.Sum",
"FailureCount",
"SuccessCount",
"SuccessCount.Count",
"SuccessCount.Sum",
"Root":
return true
}
Expand Down
17 changes: 7 additions & 10 deletions internal/model/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,11 @@ type Transaction struct {
// is subject to removal.
FailureCount int

// SuccessCount holds an aggregated count of transactions with the
// outcome "success". If SuccessCount is zero, it will be omitted from
// the output event.
//
// NOTE(axw) this is used only for service metrics, which are in technical
// preview. Do not use this field without discussion, as the field mapping
// is subject to removal.
SuccessCount int
// SuccessCount holds an aggregated count of transactions with different
// outcomes. A "failure" adds to the Count and a "success" adds to both
// the Count and the Sum. If Count is zero, it will be omitted from the
// output event.
SuccessCount SummaryMetric

Marks TransactionMarks
Message *Message
Expand Down Expand Up @@ -115,8 +112,8 @@ func (e *Transaction) fields() mapstr.M {
if e.FailureCount != 0 {
transaction.set("failure_count", e.FailureCount)
}
if e.SuccessCount != 0 {
transaction.set("success_count", e.SuccessCount)
if e.SuccessCount.Count != 0 {
transaction.maybeSetMapStr("success_count", e.SuccessCount.fields())
}
transaction.maybeSetString("name", e.Name)
transaction.maybeSetString("result", e.Result)
Expand Down
10 changes: 8 additions & 2 deletions systemtest/approvals/TestServiceMetricsAggregation.approved.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@
"value_count": 2
}
},
"success_count": 2,
"success_count": {
"sum": 2,
"value_count": 2
},
"type": "type1"
}
},
Expand Down Expand Up @@ -84,7 +87,10 @@
"value_count": 2
}
},
"success_count": 2,
"success_count": {
"sum": 2,
"value_count": 2
},
"type": "type2"
}
}
Expand Down
5 changes: 4 additions & 1 deletion x-pack/apm-server/aggregation/servicemetrics/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,10 @@ func makeMetricset(key aggregationKey, metrics serviceMetrics) model.APMEvent {
Transaction: &model.Transaction{
Type: key.transactionType,
FailureCount: int(math.Round(metrics.failureCount)),
SuccessCount: int(math.Round(metrics.successCount)),
SuccessCount: model.SummaryMetric{
Count: int64(math.Round(metrics.successCount + metrics.failureCount)),
Sum: metrics.successCount,
},
DurationSummary: model.SummaryMetric{
Count: metricCount,
Sum: float64(time.Duration(math.Round(metrics.transactionDuration)).Microseconds()),
Expand Down
10 changes: 8 additions & 2 deletions x-pack/apm-server/aggregation/servicemetrics/aggregator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ func TestAggregatorRun(t *testing.T) {
Count: 6,
Sum: 6000, // 6ms in micros
},
SuccessCount: 2,
SuccessCount: model.SummaryMetric{
Count: 5,
Sum: 2,
},
FailureCount: 3,
},
}, {
Expand Down Expand Up @@ -279,7 +282,10 @@ func TestAggregatorMaxGroups(t *testing.T) {
Count: 1,
Sum: 100000,
},
SuccessCount: 1,
SuccessCount: model.SummaryMetric{
Count: 1,
Sum: 1,
},
},
Metricset: &model.Metricset{Name: "service", DocCount: 1},
}, m)
Expand Down

0 comments on commit 9331523

Please sign in to comment.