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

Initial work on uptime for observability homepage API #70135

Merged
merged 8 commits into from
Jul 1, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion x-pack/plugins/uptime/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"configPath": ["xpack", "uptime"],
"id": "uptime",
"kibanaVersion": "kibana",
"optionalPlugins": ["capabilities", "data", "home"],
"optionalPlugins": ["capabilities", "data", "home", "observability"],
"requiredPlugins": [
"alerts",
"embeddable",
Expand Down
15 changes: 15 additions & 0 deletions x-pack/plugins/uptime/public/apps/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
PluginInitializerContext,
AppMountParameters,
} from 'kibana/public';
import { UptimeFetchDataResponse } from '../../../observability/public/typings/fetch_data_response';
import { DEFAULT_APP_CATEGORIES } from '../../../../../src/core/public';
import { UMFrontendLibs } from '../lib/lib';
import { PLUGIN } from '../../common/constants';
Expand All @@ -27,10 +28,14 @@ import {
} from '../../../../../src/plugins/data/public';
import { alertTypeInitializers } from '../lib/alert_types';
import { kibanaService } from '../state/kibana_service';
import { fetchIndexStatus } from '../state/api';
import { ObservabilityPluginSetup } from '../../../observability/public';
import { fetchUptimeOverviewData } from './uptime_overview_fetcher';

export interface ClientPluginsSetup {
data: DataPublicPluginSetup;
home: HomePublicPluginSetup;
observability: ObservabilityPluginSetup;
triggers_actions_ui: TriggersAndActionsUIPublicPluginSetup;
}

Expand Down Expand Up @@ -63,6 +68,16 @@ export class UptimePlugin
});
}

// This doesn't actually work
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @andrewvc I checked out your branch and I didn't see any problem. Can you tell me why you mentioned that it doesn't work?

shahzad31 marked this conversation as resolved.
Show resolved Hide resolved
plugins.observability.dashboard.register({
appName: 'uptime',
hasData: async () => {
const status = await fetchIndexStatus();
return status.docCount > 0;
},
fetchData: fetchUptimeOverviewData,
});

core.application.register({
appRoute: '/app/uptime#/',
id: PLUGIN.ID,
Expand Down
52 changes: 52 additions & 0 deletions x-pack/plugins/uptime/public/apps/uptime_overview_fetcher.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { fetchPingHistogram, fetchSnapshotCount } from '../state/api';
import { UptimeFetchDataResponse } from '../../../observability/public/typings/fetch_data_response';

export async function fetchUptimeOverviewData({ startTime, endTime, bucketSize }) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I noticed you're not using the bucketSize, could you tell me why? We want to show the same information in the x-axis for all charts in the Observability page.

Copy link
Contributor

Choose a reason for hiding this comment

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

@cauemarcondes i have updated to use the bucketSize

const snapshot = await fetchSnapshotCount({
cauemarcondes marked this conversation as resolved.
Show resolved Hide resolved
dateRangeStart: startTime,
dateRangeEnd: endTime,
});
const pings = await fetchPingHistogram({ dateStart: startTime, dateEnd: endTime });
const response: UptimeFetchDataResponse = {
title: 'Uptime',
appLink: '/app/uptime#/', // Todo is there some sort of helper that handles subpaths?
shahzad31 marked this conversation as resolved.
Show resolved Hide resolved
stats: {
monitors: {
type: 'number',
label: 'Monitors',
value: snapshot.total,
},
up: {
type: 'number',
label: 'Up',
value: snapshot.up,
},
down: {
type: 'number',
label: 'Down',
value: snapshot.down,
},
},
series: {
up: {
label: 'Up',
coordinates: pings.histogram.map((p) => {
return { x: p.x!, y: p.upCount || 0 };
}),
},
down: {
label: 'Down',
coordinates: pings.histogram.map((p) => {
return { x: p.x!, y: p.downCount || 0 };
}),
},
},
};
return response;
}