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

[Metrics UI] Remove TSVB dependency from Metrics Explorer APIs #74804

Conversation

simianhacker
Copy link
Member

@simianhacker simianhacker commented Aug 11, 2020

Summary

This PR removes the TSVB dependency from Metrics Explorer and introduces a new library called "Metrics API". The goal of this library is to create a replacement backend for both the Metrics Explorer, Snapshot APIs, and alert executors. This new library supports the following features:

  • Multiple group bys
  • Multiple metrics defined using ES native aggregations
  • Optional alignment of the timeseries to the end of the time range. By default ES aligns the buckets to the beginning of the time range
  • Drop last bucket, similar to how TSVB works
  • Auto bucketing with a floor, this uses the same syntax >=1m as TSVB
  • Paginate through groupings
  • Everything is Typescript
  • Doesn't depend on Metric UI's source or the KIbana request context

Here is an example of how to use this new service.

import { query } from 'server/lib/metrics';
import { MetricsAPIRequest, MetricsAPIResponse } from 'common/http_api';
import { createSearchClient } from 'server/lib/create_search_client';

const options: MetricsAPIRequest = {
  timerange: {
    field: '@timestamp',
    from: new Date('2020-01-01T00:00:00Z').getTime(),
    to: new Date('2020-01-01T01:00:00Z').getTime(),
    interval: '>=1m',
  },
  limit: 9,
  dropLastBucket: true,
  indexPattern: 'metrics-*',
  metrics: [
    { id: 'metric_0', aggregations: { metric_0: { avg: { field: 'system.cpu.user.pct' } } } },
  ],
};

const client = createSearchClient(requestContext, framework);
const response: MetricsAPIResponse = await query(client, options);

One of the goals of this new service is to provide a consistent way to query time series metrics from anywhere with in the Metrics UI app. The search client function can be swapped out with a function (with the same signature, ESSearchClient) that makes calls using a search strategy.

I plan to turn the Metrics API into a Search Strategy in a separate PR which will make using this library even more ubiquitous. I'm also going to submit a follow up PR to use this API for the backend for the Snapshot API.

Testing this PR

The goal of this PR is to go unnoticed by the user. The only change to the integration test was the ID field when the user didn't specify any group by's. Before this change it returned "Everything" as the ID, now it returns * and we display the "Everything" title only in the UI when it matches this value.

  • Ingest data from Metricbeat running on your localhost
  • Open Metrics Explorer on Master and create a visualization
  • Check out this new PR, the visualization and data should be identical.

Checklist

Delete any items that are not applicable to this PR.

@simianhacker simianhacker force-pushed the replace-tsvb-with-metric-api-for-metrics-explorer branch 7 times, most recently from 05ff5e0 to f15f325 Compare August 12, 2020 18:22
@simianhacker simianhacker force-pushed the replace-tsvb-with-metric-api-for-metrics-explorer branch from f15f325 to ad02fdf Compare August 12, 2020 18:54
@simianhacker simianhacker added Feature:Metrics UI Metrics UI feature Team:Infra Monitoring UI - DEPRECATED DEPRECATED - Label for the Infra Monitoring UI team. Use Team:obs-ux-infra_services v7.10.0 v8.0.0 release_note:skip Skip the PR/issue when compiling release notes labels Aug 12, 2020
@simianhacker simianhacker marked this pull request as ready for review August 12, 2020 19:03
@simianhacker simianhacker requested a review from a team as a code owner August 12, 2020 19:03
@elasticmachine
Copy link
Contributor

Pinging @elastic/logs-metrics-ui (Team:logs-metrics-ui)

Copy link
Contributor

@Zacqary Zacqary left a comment

Choose a reason for hiding this comment

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

Couple style nits but looks good overall

@simianhacker simianhacker requested a review from a team August 12, 2020 22:47
@simianhacker simianhacker requested review from Zacqary and removed request for a team August 12, 2020 22:55
Copy link
Contributor

@Zacqary Zacqary left a comment

Choose a reason for hiding this comment

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

Small typo in how many days are in a year

Co-authored-by: Zacqary Adam Xeper <[email protected]>
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Build metrics

@kbn/optimizer bundle module count

id value diff baseline
infra 1057 +1 1056

async chunks size

id value diff baseline
infra 3.5MB +3.5KB 3.5MB

page load bundle size

id value diff baseline
infra 275.5KB +431.0B 275.1KB

History

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

Copy link
Contributor

@Zacqary Zacqary left a comment

Choose a reason for hiding this comment

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

Checked out and tested this and it seems to be working! Thanks for doing this!

@simianhacker simianhacker merged commit 1632391 into elastic:master Aug 14, 2020
simianhacker added a commit to simianhacker/kibana that referenced this pull request Aug 14, 2020
…ic#74804)

* [Metrics UI] Remove TSVB dependency from Metrics Explorer APIs

* Update x-pack/plugins/infra/public/pages/metrics/metrics_explorer/components/chart_title.tsx

Co-authored-by: Zacqary Adam Xeper <[email protected]>

* Update x-pack/plugins/infra/server/lib/metrics/lib/calculate_bucket_size/calculate_auto.ts

Co-authored-by: Zacqary Adam Xeper <[email protected]>

* Update x-pack/plugins/infra/server/lib/metrics/lib/calculate_bucket_size/calculate_auto.ts

Co-authored-by: Zacqary Adam Xeper <[email protected]>

* Update x-pack/plugins/infra/server/lib/metrics/lib/convert_histogram_buckets_to_timeseries.ts

Co-authored-by: Zacqary Adam Xeper <[email protected]>

* Update x-pack/plugins/infra/server/lib/metrics/lib/convert_histogram_buckets_to_timeseries.ts

Co-authored-by: Zacqary Adam Xeper <[email protected]>

* Update x-pack/plugins/infra/server/routes/metrics_explorer/lib/find_interval_for_metrics.ts

Co-authored-by: Zacqary Adam Xeper <[email protected]>

* Fixing some names, changing some units

* Reverting TSVB calculate_auto; fixing names in infra

* Fixing translation names

* Fixing typo

Co-authored-by: Zacqary Adam Xeper <[email protected]>

Co-authored-by: Zacqary Adam Xeper <[email protected]>
simianhacker added a commit that referenced this pull request Aug 14, 2020
… (#75017)

* [Metrics UI] Remove TSVB dependency from Metrics Explorer APIs

* Update x-pack/plugins/infra/public/pages/metrics/metrics_explorer/components/chart_title.tsx

Co-authored-by: Zacqary Adam Xeper <[email protected]>

* Update x-pack/plugins/infra/server/lib/metrics/lib/calculate_bucket_size/calculate_auto.ts

Co-authored-by: Zacqary Adam Xeper <[email protected]>

* Update x-pack/plugins/infra/server/lib/metrics/lib/calculate_bucket_size/calculate_auto.ts

Co-authored-by: Zacqary Adam Xeper <[email protected]>

* Update x-pack/plugins/infra/server/lib/metrics/lib/convert_histogram_buckets_to_timeseries.ts

Co-authored-by: Zacqary Adam Xeper <[email protected]>

* Update x-pack/plugins/infra/server/lib/metrics/lib/convert_histogram_buckets_to_timeseries.ts

Co-authored-by: Zacqary Adam Xeper <[email protected]>

* Update x-pack/plugins/infra/server/routes/metrics_explorer/lib/find_interval_for_metrics.ts

Co-authored-by: Zacqary Adam Xeper <[email protected]>

* Fixing some names, changing some units

* Reverting TSVB calculate_auto; fixing names in infra

* Fixing translation names

* Fixing typo

Co-authored-by: Zacqary Adam Xeper <[email protected]>

Co-authored-by: Zacqary Adam Xeper <[email protected]>

Co-authored-by: Zacqary Adam Xeper <[email protected]>
gmmorris added a commit to gmmorris/kibana that referenced this pull request Aug 14, 2020
* master: (23 commits)
  Adding API test for custom link transaction example (elastic#74238)
  [Uptime] Singular alert (elastic#74659)
  Revert "attempt excluding a codeowners directory" (elastic#75023)
  [Metrics UI] Remove TSVB dependency from Metrics Explorer APIs (elastic#74804)
  Remove degraded state from ES status service (elastic#75007)
  [Reporting/Functional] unskip pagination test (elastic#74973)
  [Resolver] Stale query string values are removed when resolver's component instance ID changes. (elastic#74979)
  Add public url to Workplace Search plugin (elastic#74991)
  [Reporting] Update more Server Types for TaskManager (elastic#74915)
  [I18n] verify select icu-message options are in english (elastic#74963)
  Make data.search.aggs available on the server. (elastic#74472)
  [Security Solution][Resolver] Graph Control Tests and Update Simulator Selectors (elastic#74680)
  attempt excluding a codeowners directory
  [ML] DF Analytics: allow failed job to be stopped by force via the UI (elastic#74710)
  Add kibana-core-ui-designers team (elastic#74970)
  [Metrics UI] Fix inventory footer misalignment (elastic#74707)
  Remove legacy optimizer (elastic#73154)
  Update design-specific GH code-owners (elastic#74877)
  skip test Reporting paginates content elastic#74922
  [Metrics UI] Add Jest tests for alert previews (elastic#74890)
  ...
@simianhacker simianhacker deleted the replace-tsvb-with-metric-api-for-metrics-explorer branch April 17, 2024 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Metrics UI Metrics UI feature release_note:skip Skip the PR/issue when compiling release notes Team:Infra Monitoring UI - DEPRECATED DEPRECATED - Label for the Infra Monitoring UI team. Use Team:obs-ux-infra_services v7.10.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants