Skip to content
This repository has been archived by the owner on Sep 10, 2024. It is now read-only.

Commit

Permalink
downsampled search strategy usage on client
Browse files Browse the repository at this point in the history
Signed-off-by: inge4pres <francesco.gualazzi@elastic.co>
  • Loading branch information
inge4pres committed Mar 4, 2022
1 parent fc8ed85 commit ac06ea3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/plugins/profiling/public/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { Services } from './services';

type Props = Services;

function App({ fetchTopN, fetchElasticFlamechart, fetchPixiFlamechart }: Props) {
function App({ fetchTopN, fetchElasticFlamechart, fetchPixiFlamechart, fetchTopNData }: Props) {
const [topn, setTopN] = useState({
samples: [],
series: new Map(),
Expand Down
21 changes: 16 additions & 5 deletions src/plugins/profiling/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,29 @@
* Side Public License, v 1.
*/

import { AppMountParameters, CoreSetup, CoreStart, Plugin } from '../../../core/public';
import { AppMountParameters, CoreSetup, CoreStart, Plugin } from 'kibana/public';
import { getServices } from './services';
import { DataPublicPluginSetup, DataPublicPluginStart } from '../../data/public';

export class ProdfilerPlugin implements Plugin {
public setup(core: CoreSetup) {
export interface ProdfilerPluginStartDeps {
data: DataPublicPluginStart;
}

export interface ProdfilerPluginSetupDeps {
data: DataPublicPluginSetup;
}

export class ProdfilerPlugin
implements Plugin<void, void, ProdfilerPluginSetupDeps, ProdfilerPluginStartDeps>
{
public setup(core: CoreSetup<ProdfilerPluginStartDeps>) {
// Register an application into the side navigation menu
core.application.register({
id: 'prodfiler',
title: 'Prodfiler',
async mount({ element }: AppMountParameters) {
const [coreStart] = await core.getStartServices();
const startServices = getServices(coreStart);
const [coreStart, dataPlugin] = await core.getStartServices();
const startServices = getServices(coreStart, dataPlugin);
const { renderApp } = await import('./app');
return renderApp(startServices, element);
},
Expand Down
30 changes: 29 additions & 1 deletion src/plugins/profiling/public/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@

import { CoreStart, HttpFetchError, HttpFetchQuery } from 'kibana/public';
import { getRemoteRoutePaths } from '../common';
import { ProdfilerPluginStartDeps } from './plugin';
import { DownsampledRequest, DownsampledTopNResponse } from '../common/types';

export interface Services {
fetchTopN: (type: string, seconds: string) => Promise<any[] | HttpFetchError>;
fetchElasticFlamechart: (seconds: string) => Promise<any[] | HttpFetchError>;
fetchPixiFlamechart: (seconds: string) => Promise<any[] | HttpFetchError>;
// FIXME
fetchTopNData?: (searchField: string, seconds: string) => Promise<DownsampledTopNResponse>;
}

function getFetchQuery(seconds: string): HttpFetchQuery {
Expand All @@ -27,11 +31,35 @@ function getFetchQuery(seconds: string): HttpFetchQuery {
} as HttpFetchQuery;
}

export function getServices(core: CoreStart): Services {
export function getServices(core: CoreStart, data?: ProdfilerPluginStartDeps): Services {
// To use local fixtures instead, use getLocalRoutePaths
const paths = getRemoteRoutePaths();

return {
fetchTopNData: (searchField: string, seconds: string): Promise<DownsampledTopNResponse> => {
const unixTime = Math.floor(Date.now() / 1000);
return (
data!.data.search
.search<DownsampledRequest, DownsampledTopNResponse>(
{
params: {
projectID: 5,
timeFrom: unixTime - parseInt(seconds, 10),
timeTo: unixTime,
// FIXME remove hard-coded value for topN items length and expose it through the UI
topNItems: 100,
searchField,
},
},
{
strategy: 'downsampledTopN',
}
)
// get the results and prepare the Promise
.toPromise<DownsampledTopNResponse>()
);
},

fetchTopN: async (type: string, seconds: string) => {
try {
const query = getFetchQuery(seconds);
Expand Down

0 comments on commit ac06ea3

Please sign in to comment.