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

[APM] [experimental] Service metrics on inventory page #140868

Merged
merged 26 commits into from
Sep 20, 2022

Conversation

kpatticha
Copy link
Contributor

@kpatticha kpatticha commented Sep 15, 2022

closes: #138527

By default the setting xpack.apm.searchAggregatedServiceMetrics is set to false .
Add kibana advanced setting to configure - #141147

  • Adds a getSearchAggregatedServiceMetrics() method which will determine, based on the date range and configuration setting whether aggregated service metrics should be used.
  • Adds getServiceAggregatedTransactionDetailedStatistics() query for the service metrics
  • Adds getServiceAggregatedTransactionStats query for the service metrics

Created separated queries for the fetching service metrics data cause the data model is quite different from aggregated transaction document (transaction.duration.histogram)

service metrics document example
{
"took": 0,
"timed_out": false,
"_shards": {
  "total": 3,
  "successful": 3,
  "skipped": 0,
  "failed": 0
},
"hits": {
  "total": {
    "value": 1,
    "relation": "eq"
  },
  "max_score": 0,
  "hits": [
    {
      "_index": ".ds-metrics-apm.internal-default-2022.09.19-000003",
      "_id": "wNGvVYMBJNnTUS6H_uDc",
      "_score": 0,
      "_source": {
        "agent": {
          "name": "go"
        },
        "data_stream.namespace": "default",
        "data_stream.type": "metrics",
        "processor": {
          "name": "metric",
          "event": "metric"
        },
        "tags": [
          "_geoip_database_unavailable_GeoLite2-City.mmdb"
        ],
        "metricset.name": "service",
        "observer": {
          "hostname": "DIXONS-JVC-TV",
          "id": "c42b6d9b-7ea6-4e65-b1fd-dd51cff84431",
          "type": "apm-server",
          "ephemeral_id": "61e84242-bfd9-4b41-8d97-89c078b96d45",
          "version": "8.5.0"
        },
        "@timestamp": "2022-09-19T12:18:00.000Z",
        "ecs": {
          "version": "1.12.0"
        },
        "service": {
          "environment": "production",
          "name": "web-go"
        },
        "data_stream.dataset": "apm.internal",
        "event": {
          "agent_id_status": "missing",
          "ingested": "2022-09-19T12:19:00Z"
        },
        "transaction": {
          "duration.summary": {
            "sum": 376492831,
            "value_count": 775
          },
          "success_count": 476,
          "failure_count": 151,
          "type": "request"
        }
      }
    }
  ]
}

To try this out, you'll need to enable aggregation in APM Server. See elastic/apm-server#8607
In order to test it locally you need to run the following:

  1. update apm-server.yml
aggregation:
    service:
      enabled: true
  1. run apm-server locally
    a. ./apm-server -c apm-server.yml -e -d "*"
  2. use synthrace to generate data
    node scripts/synthtrace packages/elastic-apm-synthtrace/src/scenarios/high_throughput.ts --local --maxDocs 100 --apm http://localhost:8200/ --username admin --skipPackageInstall --clean

TODO:

@github-actions
Copy link
Contributor

Documentation preview:

@kpatticha kpatticha force-pushed the 138527-service-metrics branch from d39f738 to 726e43d Compare September 19, 2022 08:59
@kpatticha kpatticha force-pushed the 138527-service-metrics branch from 6f2d526 to da16bc3 Compare September 19, 2022 10:07
@kpatticha kpatticha marked this pull request as ready for review September 19, 2022 13:56
@kpatticha kpatticha requested a review from a team as a code owner September 19, 2022 13:56
@botelastic botelastic bot added the Team:APM All issues that need APM UI Team support label Sep 19, 2022
@elasticmachine
Copy link
Contributor

Pinging @elastic/apm-ui (Team:APM)

Copy link
Contributor

@cauemarcondes cauemarcondes left a comment

Choose a reason for hiding this comment

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

Some small suggestions

Copy link
Member

@dgieselaar dgieselaar left a comment

Choose a reason for hiding this comment

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

I've left some comments, some more important than others, but generally don't wait on my approval as I'm under the weather atm and just wanted to have a quick look. Thanks for doing this!

@@ -12,12 +12,17 @@ export function getBucketSizeForAggregatedTransactions({
end,
numBuckets = 50,
searchAggregatedTransactions,
searchAggregatedServiceMetrics,
}: {
start: number;
end: number;
numBuckets?: number;
searchAggregatedTransactions?: boolean;
Copy link
Member

Choose a reason for hiding this comment

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

Can we collapse this into one (maybe required) prop?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Caue left a comment on this helper as well. #140868 (comment)
We could discuss and find what's the best in a follow up PR/ticket

@@ -34,6 +36,7 @@ export async function getServicesItems({
kuery: string;
setup: ServicesItemsSetup;
searchAggregatedTransactions: boolean;
searchAggregatedServiceMetrics: boolean;
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer one option here too. Not a dealbreaker, but I think it's better to make the decision (about what to search) in one place and then pass it on downwards.

Copy link
Member

Choose a reason for hiding this comment

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

@dgieselaar I think I agree. Are you suggesting to combine searchAggregatedTransactions and searchAggregatedServiceMetrics into a single option? In that case I suggest we deprecate searchAggregatedTransactions and remove searchAggregatedServiceMetrics , and create a new one like:

transactionSource: 'auto' | 'service-metrics' | 'transaction-metrics' | 'transactions'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The auto in which order should determine the source?

first 'service-metrics' then transaction-metrics?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that order. But we should only use service-metrics where it makes sense. Right now only on the inventory page.

@kpatticha kpatticha requested a review from Mpdreamz September 20, 2022 09:08
@kpatticha kpatticha force-pushed the 138527-service-metrics branch from 47b8e05 to e74ae86 Compare September 20, 2022 12:13
Mpdreamz added a commit to Mpdreamz/apm-server that referenced this pull request Sep 20, 2022
This to ensure proper bucket counts as discovered on

elastic/kibana#140868
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Copy link
Contributor

@cauemarcondes cauemarcondes left a comment

Choose a reason for hiding this comment

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

LGTM. Just some nits that don't block the merge.

return [
{
term: {
[METRICSET_NAME]: 'service',
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like we could have an enum for the possible metricsset.name values.

kuery: string;
}): Promise<{
searchAggregatedTransactions: boolean;
searchAggregatedServiceMetrics: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have to add Metrics at the end of the name? We don't do it for transactions.

Maybe to keep it consistent?

Suggested change
searchAggregatedServiceMetrics: boolean;
searchAggregatedServices: boolean;

Copy link
Member

Choose a reason for hiding this comment

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

I also noticed this inconsistency but I think we should keep "Metrics" and get rid of "Aggregated":

Suggested change
searchAggregatedServiceMetrics: boolean;
searchTransactionsMetrics: boolean;
searchServiceMetrics: boolean;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

let me address the additional feedback in a follow up PR.

Thank you all for the review!

...commonProps,
offset,
})
: Promise.resolve({}),
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you need Promise.resolve here. isn't that enough?

Suggested change
: Promise.resolve({}),
: {},

Copy link
Member

Choose a reason for hiding this comment

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

TypeScript will complain I think

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I can't reproduce this, but I've seen issues with TypeScript no longer being able to infer the return type. Maybe it was fixed in a recent version. Runtime a plain value should be fine in any case.

@kpatticha kpatticha merged commit b93dc5f into elastic:main Sep 20, 2022
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Sep 20, 2022
failedTransactions: number | null;
successfulTransactions: number | null;
}) {
if (isNull(failedTransactions) || failedTransactions === 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is up to you, just a preference:

Suggested change
if (isNull(failedTransactions) || failedTransactions === 0) {
if (!failedTransactions) {


const { apmEventClient, config } = setup;
const { searchAggregatedTransactions, searchAggregatedServiceMetrics } =
await getServiceInventorySearchSource({
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't environment be here too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

looking closer to this!

I think, if we want to be 100% accurate environment should be there, otherwise we ask if there is ANY document that matches the metricset.name: service and it might no be for the given environment.

but I'm wondering how is that different from getSearchAggregatedTransactions, why we don't include it as a filter for the aggregated transactions?

Copy link
Member

Choose a reason for hiding this comment

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

it should be there too. Not sure why it isn't, it may have been on setup before.

Copy link
Contributor Author

@kpatticha kpatticha Sep 21, 2022

Choose a reason for hiding this comment

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

I can create a ticket for it unless you want to

@@ -46,12 +46,15 @@ export const PROCESSOR_EVENT = 'processor.event';

export const TRANSACTION_DURATION = 'transaction.duration.us';
export const TRANSACTION_DURATION_HISTOGRAM = 'transaction.duration.histogram';
export const TRANSACTION_DURATION_SUMMARY = 'transaction.duration.summary';
Copy link
Member

@sorenlouv sorenlouv Sep 21, 2022

Choose a reason for hiding this comment

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

iirc we talked about splitting this file into several files, with one file per data source (eg. APM vs infra vs logs) we might also want to group the fields by doc type (transactions vs transaction metrics vs service metrics)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting release_note:enhancement Team:APM All issues that need APM UI Team support v8.5.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[APM] Support Service Metrics on the inventory overview page
9 participants