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

[Graph] Switch to core http #49487

Merged
merged 5 commits into from
Nov 4, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
36 changes: 21 additions & 15 deletions x-pack/legacy/plugins/graph/public/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import React from 'react';
import { Provider } from 'react-redux';
import { isColorDark, hexToRgb } from '@elastic/eui';

import { KibanaParsedUrl } from 'ui/url/kibana_parsed_url';
import { showSaveModal } from 'ui/saved_objects/show_saved_object_save_modal';
import { formatAngularHttpError } from 'ui/notify/lib';
import { addAppRedirectMessageToUrl } from 'ui/notify';

import appTemplate from './angular/templates/index.html';
Expand All @@ -39,6 +37,7 @@ import {
datasourceSelector,
hasFieldsSelector
} from './state_management';
import { formatHttpError } from './helpers/format_http_error';

export function initGraphApp(angularModule, deps) {
const {
Expand All @@ -56,7 +55,6 @@ export function initGraphApp(angularModule, deps) {
savedObjectRegistry,
capabilities,
coreStart,
$http,
Storage,
canEditDrillDownUrls,
graphSavePolicy,
Expand Down Expand Up @@ -208,49 +206,57 @@ export function initGraphApp(angularModule, deps) {

async function handleHttpError(error) {
checkLicense(kbnBaseUrl);
toastNotifications.addDanger(formatAngularHttpError(error));
toastNotifications.addDanger(formatHttpError(error));
}

// Replacement function for graphClientWorkspace's comms so
// that it works with Kibana.
function callNodeProxy(indexName, query, responseHandler) {
const request = {
index: indexName,
query: query
body: JSON.stringify({
index: indexName,
query: query
})
};
$scope.loading = true;
return $http.post('../api/graph/graphExplore', request)
.then(function (resp) {
if (resp.data.resp.timed_out) {
return coreStart.http.post('../api/graph/graphExplore', request)
.then(function (data) {
const response = data.resp;
if (response.timed_out) {
toastNotifications.addWarning(
i18n.translate('xpack.graph.exploreGraph.timedOutWarningText', {
defaultMessage: 'Exploration timed out',
})
);
}
responseHandler(resp.data.resp);
responseHandler(response);
})
.catch(handleHttpError)
.finally(() => {
$scope.loading = false;
$scope.$digest();
});
}


//Helper function for the graphClientWorkspace to perform a query
const callSearchNodeProxy = function (indexName, query, responseHandler) {
const request = {
index: indexName,
body: query
body: JSON.stringify({
index: indexName,
body: query
})
};
$scope.loading = true;
$http.post('../api/graph/searchProxy', request)
.then(function (resp) {
responseHandler(resp.data.resp);
coreStart.http.post('../api/graph/searchProxy', request)
.then(function (data) {
const response = data.resp;
responseHandler(response);
})
.catch(handleHttpError)
.finally(() => {
$scope.loading = false;
$scope.$digest();
});
};

Expand Down
27 changes: 27 additions & 0 deletions x-pack/legacy/plugins/graph/public/helpers/format_http_error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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 { i18n } from '@kbn/i18n';
import { IHttpFetchError } from 'kibana/public';

export function formatHttpError(error: IHttpFetchError) {
if (!error.response) {
return i18n.translate('xpack.graph.fatalError.unavailableServerErrorMessage', {
defaultMessage:
'An HTTP request has failed to connect. ' +
'Please check if the Kibana server is running and that your browser has a working connection, ' +
'or contact your system administrator.',
});
}
return i18n.translate('xpack.graph.fatalError.errorStatusMessage', {
defaultMessage: 'Error {errStatus} {errStatusText}: {errMessage}',
values: {
errStatus: error.body.status,
errStatusText: error.body.statusText,
errMessage: error.body.message,
},
});
}
1 change: 0 additions & 1 deletion x-pack/legacy/plugins/graph/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ async function getAngularInjectedDependencies(): Promise<LegacyAngularInjectedDe
const Private = injector.get<IPrivate>('Private');

return {
$http: injector.get('$http'),
savedObjectRegistry: Private(SavedObjectRegistryProvider),
kbnBaseUrl: injector.get('kbnBaseUrl'),
savedGraphWorkspaces: Private(SavedWorkspacesProvider),
Expand Down
4 changes: 0 additions & 4 deletions x-pack/legacy/plugins/graph/public/render_app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ export interface GraphDependencies extends LegacyAngularInjectedDependencies {
* These dependencies have to be migrated to their NP counterparts.
*/
export interface LegacyAngularInjectedDependencies {
/**
* angular $http service
*/
$http: any;
/**
* Instance of SavedObjectRegistryProvider
*/
Expand Down