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

Service metrics txn events txn metrics #9819

Merged
merged 15 commits into from
Dec 27, 2022

Conversation

carsonip
Copy link
Member

@carsonip carsonip commented Dec 15, 2022

Motivation/summary

Add event.success_count to transaction events, transaction metrics and service metrics. It was previously available for service metrics at transaction.success_count by #9791

Checklist

How to test these changes

  1. Check that event.success_count is correct for transaction event, transaction metrics and service metrics
  2. Check that they work with avg aggregation
  3. Ensure event.success_count.sum is rounded under sampling setup (fixed in Round servicetxmetrics event.success_count.sum #10165)

Related issues

Closes #5243

@mergify
Copy link
Contributor

mergify bot commented Dec 15, 2022

This pull request is now in conflicts. Could you fix it @carsonip? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b service-metrics-txn-events-txn-metrics upstream/service-metrics-txn-events-txn-metrics
git merge upstream/main
git push upstream service-metrics-txn-events-txn-metrics

@mergify
Copy link
Contributor

mergify bot commented Dec 15, 2022

This pull request does not have a backport label. Could you fix it @carsonip? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-7.x is the label to automatically backport to the 7.x branch.
  • backport-7./d is the label to automatically backport to the 7./d branch. /d is the digit

NOTE: backport-skip has been added to this pull request.

@mergify mergify bot added the backport-skip Skip notification from the automated backport with mergify label Dec 15, 2022
@carsonip carsonip force-pushed the service-metrics-txn-events-txn-metrics branch 2 times, most recently from 190900f to ceeca21 Compare December 16, 2022 10:30
@apmmachine
Copy link
Contributor

apmmachine commented Dec 16, 2022

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2022-12-27T11:47:28.058+0000

  • Duration: 20 min 41 sec

Test stats 🧪

Test Results
Failed 0
Passed 154
Skipped 0
Total 154

🤖 GitHub comments

Expand to view the GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • /package : Generate and publish the docker images.

  • /test windows : Build & tests on Windows.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@apmmachine
Copy link
Contributor

apmmachine commented Dec 16, 2022

📚 Go benchmark report

Diff with the main branch

name                                          old time/op    new time/op    delta
pkg:github.com/elastic/apm-server/internal/agentcfg goos:linux goarch:amd64
pkg:github.com/elastic/apm-server/internal/beater/request goos:linux goarch:amd64
ContextReset/X-Forwarded-For_ipv6-12             919ns ± 4%     689ns ±26%  -25.07%  (p=0.008 n=5+5)
pkg:github.com/elastic/apm-server/internal/publish goos:linux goarch:amd64
pkg:github.com/elastic/apm-server/x-pack/apm-server/aggregation/spanmetrics goos:linux goarch:amd64
pkg:github.com/elastic/apm-server/x-pack/apm-server/aggregation/txmetrics goos:linux goarch:amd64
pkg:github.com/elastic/apm-server/x-pack/apm-server/sampling goos:linux goarch:amd64
pkg:github.com/elastic/apm-server/x-pack/apm-server/sampling/eventstorage goos:linux goarch:amd64
ReadEvents/nop_codec/100_events-12               154µs ± 9%     136µs ± 5%  -11.69%  (p=0.016 n=5+4)
IsTraceSampled/unknown-12                        369ns ± 3%     379ns ± 1%   +2.57%  (p=0.032 n=5+5)

name                                          old alloc/op   new alloc/op   delta
pkg:github.com/elastic/apm-server/internal/agentcfg goos:linux goarch:amd64
pkg:github.com/elastic/apm-server/internal/beater/request goos:linux goarch:amd64
pkg:github.com/elastic/apm-server/internal/publish goos:linux goarch:amd64
pkg:github.com/elastic/apm-server/x-pack/apm-server/aggregation/spanmetrics goos:linux goarch:amd64
pkg:github.com/elastic/apm-server/x-pack/apm-server/aggregation/txmetrics goos:linux goarch:amd64
pkg:github.com/elastic/apm-server/x-pack/apm-server/sampling goos:linux goarch:amd64
pkg:github.com/elastic/apm-server/x-pack/apm-server/sampling/eventstorage goos:linux goarch:amd64
ReadEvents/json_codec/1_events-12               9.04kB ± 0%    9.03kB ± 0%   -0.21%  (p=0.000 n=4+5)
ReadEvents/json_codec/10_events-12              83.4kB ± 0%    83.3kB ± 0%   -0.18%  (p=0.008 n=5+5)
ReadEvents/json_codec/100_events-12              830kB ± 0%     829kB ± 0%   -0.18%  (p=0.008 n=5+5)
ReadEvents/json_codec/199_events-12             1.10MB ± 0%    1.10MB ± 0%   -0.31%  (p=0.008 n=5+5)
ReadEvents/json_codec_big_tx/1_events-12        11.1kB ± 0%    11.0kB ± 0%   -0.14%  (p=0.016 n=5+4)
ReadEvents/json_codec_big_tx/10_events-12        104kB ± 0%     103kB ± 0%   -0.17%  (p=0.008 n=5+5)
ReadEvents/json_codec_big_tx/100_events-12      1.03MB ± 0%    1.03MB ± 0%   -0.20%  (p=0.008 n=5+5)
ReadEvents/json_codec_big_tx/199_events-12      1.43MB ± 0%    1.42MB ± 0%   -0.25%  (p=0.016 n=5+4)
ReadEvents/json_codec_big_tx/399_events-12      2.22MB ± 0%    2.22MB ± 0%   -0.22%  (p=0.008 n=5+5)
ReadEvents/nop_codec/10_events-12               25.7kB ± 0%    25.7kB ± 0%   -0.14%  (p=0.048 n=5+5)

name                                          old allocs/op  new allocs/op  delta
pkg:github.com/elastic/apm-server/internal/agentcfg goos:linux goarch:amd64
pkg:github.com/elastic/apm-server/internal/beater/request goos:linux goarch:amd64
pkg:github.com/elastic/apm-server/internal/publish goos:linux goarch:amd64
pkg:github.com/elastic/apm-server/x-pack/apm-server/aggregation/spanmetrics goos:linux goarch:amd64
pkg:github.com/elastic/apm-server/x-pack/apm-server/aggregation/txmetrics goos:linux goarch:amd64
pkg:github.com/elastic/apm-server/x-pack/apm-server/sampling goos:linux goarch:amd64
pkg:github.com/elastic/apm-server/x-pack/apm-server/sampling/eventstorage goos:linux goarch:amd64

report generated with https://pkg.go.dev/golang.org/x/perf/cmd/benchstat

@carsonip carsonip force-pushed the service-metrics-txn-events-txn-metrics branch from 633ae5a to abfbdbd Compare December 16, 2022 11:17
@carsonip carsonip requested a review from axw December 16, 2022 12:58
@carsonip
Copy link
Member Author

Keeping this in draft during review since it will have to go with elastic/apm-data#2

Copy link
Member

@axw axw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Just one minor comment.

@mergify
Copy link
Contributor

mergify bot commented Dec 19, 2022

This pull request is now in conflicts. Could you fix it @carsonip? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b service-metrics-txn-events-txn-metrics upstream/service-metrics-txn-events-txn-metrics
git merge upstream/main
git push upstream service-metrics-txn-events-txn-metrics

@carsonip carsonip force-pushed the service-metrics-txn-events-txn-metrics branch from a0200d6 to 5a4373a Compare December 19, 2022 09:35
Copy link
Contributor

@simitt simitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code mostly looks good, left a couple minor comments.

Please reflect that this PR depends on elastic/apm-data#2 in the description.

@@ -11,6 +11,7 @@ https://github.com/elastic/apm-server/compare/8.5\...main[View commits]
- `observer.id` and `observer.ephemeral_id` are no longer added to APM documents {pull}9412[9412]
- `timeseries.instance` has been removed from transaction metrics docs; it was never used {pull}9565[9565]
- `transaction.failure_count` has been removed. `transaction.success_count` type has changed to `aggregated_metric_double` {pull}9791[9791]
- `transaction.success_count` has been moved to `event.success_count` {pull}9819[9819]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changelog is missing that event.success_count has been introduced also for transaction events and transaction metrics. This changelog should contain all changes made to APM Server.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated changelog, but split the part about transaction events and transaction metrics outside "breaking changes".

@mergify
Copy link
Contributor

mergify bot commented Dec 23, 2022

This pull request is now in conflicts. Could you fix it @carsonip? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b service-metrics-txn-events-txn-metrics upstream/service-metrics-txn-events-txn-metrics
git merge upstream/main
git push upstream service-metrics-txn-events-txn-metrics

@carsonip carsonip force-pushed the service-metrics-txn-events-txn-metrics branch from 641e5db to 47c03e4 Compare December 23, 2022 12:16
@simitt
Copy link
Contributor

simitt commented Dec 23, 2022

@carsonip the PR looks pretty solid - are you planning on marking it ready for review soon?

@carsonip carsonip marked this pull request as ready for review December 23, 2022 15:43
@carsonip
Copy link
Member Author

@carsonip the PR looks pretty solid - are you planning on marking it ready for review soon?

Was trying to squash locally before making it ready for review but got into some local permission errors which I thought we fixed yesterday. Anyway, can do a squash merge after approval.

@carsonip carsonip requested a review from simitt December 23, 2022 15:45
Co-authored-by: Marc Lopez Rubio <marc5.12@outlook.com>
@simitt simitt merged commit b470c3b into elastic:main Dec 27, 2022
@simitt
Copy link
Contributor

simitt commented Dec 27, 2022

Merged, to unblock @marclop who is working on a PR touching the same code base.

@carsonip
Copy link
Member Author

Thanks @simitt

@lahsivjar
Copy link
Contributor

lahsivjar commented Mar 6, 2023

Tested with 8.7.0-BC4. The code used for testing generates data as following:

  1. 2 transactions for each unique name and transaction type.
  2. A total of 100 unique transactions (200 total transactions based on point 1).
  3. Equal number of unique transactions for success and failure.
Code used for generating traces for testing
package main

import (
	"fmt"
	"time"

	"go.elastic.co/apm/v2"
)

func main() {
	tracer := apm.DefaultTracer()
	tracer.SetSpanCompressionEnabled(false)             // Disable compression.
	tracer.SetExitSpanMinDuration(2 * time.Millisecond) // set duration to 2ms.
	for i := 0; i < 100; i++ {
		for _, duration := range []time.Duration{100, 1000} {
			tx := tracer.StartTransaction(fmt.Sprintf("tx-%d", i), fmt.Sprintf("type-%d", i))
			tx.Duration = time.Duration(duration) * time.Millisecond
			if i%2 == 0 {
				tx.Outcome = "success"
			} else {
				tx.Outcome = "failure"
			}
			tx.End()
		}
	}
	tracer.Flush(nil)
}
Check that event.success_count is correct for transaction event, transaction metrics and service metrics

Transaction Events

Asserted that the metric is recorded as byte.

Success
GET /traces-apm-default*/_search?filter_path=hits.hits
{
  "size": 1,
  "query": {
    "bool": {
      "must": [
        {"match": {"event.outcome": "success"}},
        {"match": {"service.name": "apm2"}}
      ]
    }
  }, 
  "_source": [false],
  "fields": [
    "event.success_count"
  ]
}
{
  "hits": {
    "hits": [
      {
        "_index": ".ds-traces-apm-default-2023.03.06-000001",
        "_id": "flwTtYYBNtUXE48ncG4T",
        "_score": 4.617365,
        "_source": {},
        "fields": {
          "event.success_count": [
            1
          ]
        }
      }
    ]
  }
}
Failure
GET /traces-apm-default*/_search?filter_path=hits.hits
{
  "size": 1,
  "query": {
    "bool": {
      "must": [
        {"match": {"event.outcome": "failure"}},
        {"match": {"service.name": "apm2"}}
      ]
    }
  }, 
  "_source": [false],
  "fields": [
    "event.success_count"
  ]
}
{
  "hits": {
    "hits": [
      {
        "_index": ".ds-traces-apm-default-2023.03.06-000001",
        "_id": "gFwTtYYBNtUXE48ncG4T",
        "_score": 9.915409,
        "_source": {},
        "fields": {
          "event.success_count": [
            0
          ]
        }
      }
    ]
  }
}

Transaction Metrics

Asserted that the metric is recorded as aggregate_metric_double with sum and value_count metrics.

Success
GET /metrics-apm.transaction*/_search?filter_path=hits.hits
{
  "size": 1,
  "query": {
    "bool": {
      "must": [
        {"match": {"event.outcome": "success"}},
        {"match": {"service.name": "apm2"}}
      ]
    }
  }, 
  "_source": [false],
  "fields": [
    "event.success_count"
  ]
}
{
  "hits": {
    "hits": [
      {
        "_index": ".ds-metrics-apm.transaction.1m-default-2023.03.06-000001",
        "_id": "aFwUtYYBNtUXE48nDm9C",
        "_score": 0.69894236,
        "_source": {},
        "fields": {
          "event.success_count": [
            {
              "sum": 2,
              "value_count": 2
            }
          ]
        }
      }
    ]
  }
}
Failure
GET /metrics-apm.transaction*/_search?filter_path=hits.hits
{
  "size": 1,
  "query": {
    "bool": {
      "must": [
        {"match": {"event.outcome": "failure"}},
        {"match": {"service.name": "apm2"}}
      ]
    }
  }, 
  "_source": [false],
  "fields": [
    "event.success_count"
  ]
}
{
  "hits": {
    "hits": [
      {
        "_index": ".ds-metrics-apm.transaction.1m-default-2023.03.06-000001",
        "_id": "alwUtYYBNtUXE48nDm9C",
        "_score": 0.7566507,
        "_source": {},
        "fields": {
          "event.success_count": [
            {
              "sum": 0,
              "value_count": 2
            }
          ]
        }
      }
    ]
  }
}

Service Transaction Metrics

Asserted that the metric is recorded as aggregate_metric_double with sum and value_count metrics.

Success
GET /metrics-apm.service_transaction*/_search?filter_path=hits.hits
{
  "size": 1,
  "query": {
    "bool": {
      "must": [
        {"match": {"transaction.type": "type-2"}},
        {"match": {"service.name": "apm2"}}
      ]
    }
  }, 
  "_source": [false],
  "fields": [
    "event.success_count"
  ]
}
{
  "hits": {
    "hits": [
      {
        "_index": ".ds-metrics-apm.service_transaction.1m-default-2023.03.06-000001",
        "_id": "olwUtYYBNtUXE48nDm9C",
        "_score": 4.2731586,
        "_source": {},
        "fields": {
          "event.success_count": [
            {
              "sum": 2,
              "value_count": 2
            }
          ]
        }
      }
    ]
  }
}
Failure
GET /metrics-apm.service_transaction*/_search?filter_path=hits.hits
{
  "size": 1,
  "query": {
    "bool": {
      "must": [
        {"match": {"transaction.type": "type-1"}},
        {"match": {"service.name": "apm2"}}
      ]
    }
  }, 
  "_source": [false],
  "fields": [
    "event.success_count"
  ]
}
{
  "hits": {
    "hits": [
      {
        "_index": ".ds-metrics-apm.service_transaction.1m-default-2023.03.06-000001",
        "_id": "l1wUtYYBNtUXE48nDm9C",
        "_score": 4.2731586,
        "_source": {},
        "fields": {
          "event.success_count": [
            {
              "sum": 0,
              "value_count": 2
            }
          ]
        }
      }
    ]
  }
}
Check that they work with avg aggregation

Transaction Events

GET /traces-apm-default*/_search?filter_path=aggregations
{
  "size": 1,
  "aggs": {
    "err_rate": {
      "filter": {
        "term": {
          "service.name": "apm2"
        }
      },
      "aggs": {
        "err_rate": {"avg": { "field": "event.success_count" }}
      }
    }
  }
}
{
  "aggregations": {
    "err_rate": {
      "doc_count": 200,
      "err_rate": {
        "value": 0.5
      }
    }
  }
}

Transaction Metrics

GET /metrics-apm.transaction*/_search?filter_path=aggregations
{
  "size": 1,
  "aggs": {
    "err_rate": {
      "filter": {
        "term": {
          "service.name": "apm2"
        }
      },
      "aggs": {
        "err_rate": {"avg": { "field": "event.success_count" }}
      }
    }
  }
}
{
  "aggregations": {
    "err_rate": {
      "doc_count": 200,
      "err_rate": {
        "value": 0.5
      }
    }
  }
}

Service Transaction Metrics

GET /metrics-apm.service_transaction*/_search?filter_path=aggregations
{
  "size": 1,
  "aggs": {
    "err_rate": {
      "filter": {
        "term": {
          "service.name": "apm2"
        }
      },
      "aggs": {
        "err_rate": {"avg": { "field": "event.success_count" }}
      }
    }
  }
}
{
  "aggregations": {
    "err_rate": {
      "doc_count": 200,
      "err_rate": {
        "value": 0.5
      }
    }
  }
}
Ensure event.success_count.sum is rounded under sampling setup

Asserted via test case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-skip Skip notification from the automated backport with mergify test-plan test-plan-ok v8.7.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

service metrics: add numeric outcome
6 participants