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

[Infra UI] Test for metrics GraphQL endpoint #24179

Merged
merged 6 commits into from
Oct 19, 2018

Conversation

simianhacker
Copy link
Member

@simianhacker simianhacker commented Oct 17, 2018

This PR sets up the first API test for the metric GraphQL endpoint. This comes with:

  • Es archive of metricbeat and Filebeat data
  • InfraOps GraphQL client service for testing

I reused the same query we are using from the app so if something changes in there the test should blowup as expected by any good test 👍

To run the tests locally:

 node scripts/functional_test_runner.js --config x-pack/test/api_integration/config.js --grep InfraOps

BTW... The extra added bonus of this test is that because the metrics endpoint just re-routes the requests through the TSVB backend we get testing of TSVB for free!

package.json Outdated
@@ -83,6 +83,7 @@
"angular-route": "1.4.7",
"angular-sanitize": "1.5.7",
"angular-sortable-view": "0.0.15",
"apollo-boost": "^0.1.16",
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be in devDependencies instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

Er... that's weird. Good catch.

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Copy link
Member

@weltenwort weltenwort left a comment

Choose a reason for hiding this comment

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

That looks quite good. We could avoid having apollo-boost as a dependency though using the changes I suggested below.

On a different topic, is writing these tests in typescript supported?

* you may not use this file except in compliance with the Elastic License.
*/

import ApolloClient from 'apollo-boost'; // eslint-disable-line
Copy link
Member

Choose a reason for hiding this comment

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

We don't need to include apollo-boost at all if we import this...

Suggested change
import ApolloClient from 'apollo-boost'; // eslint-disable-line
import { InMemoryCache } from 'apollo-cache-inmemory';
import { ApolloClient } from 'apollo-client';
import { HttpLink } from 'apollo-link-http';

}
});
}
});
Copy link
Member

Choose a reason for hiding this comment

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

...and configure the ApolloClient like this:

  return new ApolloClient({
    cache: new InMemoryCache(),
    link: new HttpLink({
      credentials: 'same-origin',
      fetch,
      headers: {
        'kbn-xsrf': 'xxx',
      },
      uri: `${kbnURL}/api/infra/graphql`,
    }),
  });

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

*/

import expect from 'expect.js';
import { metricsQuery } from '../../../../plugins/infra/public/containers/metrics/metrics.gql_query';
Copy link
Member

Choose a reason for hiding this comment

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

As a practice in graphql tests, maybe we want to locally define the query so the whole test is more readable and less entangled with client code?

We should be able to just inline something here like

import gql from 'graphql-tag';

const metricsQuery = gql`
  ...
`;

Copy link
Contributor

Choose a reason for hiding this comment

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

It does test the query which we're actually using from the UI, isn't this a good thing?

Copy link
Member

Choose a reason for hiding this comment

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

In a way that's good, but I would almost consider that part of the e2e tests. To me it's very hard to answer the question "what aspect of the api does this test case cover?".

Maybe there's a way to have both: Have a test case like "should support the metric container query" per client-side query and other test cases that test specific things like "supports two metrics in one query" with a locally defined query.

Does that sound reasonable?

Copy link
Member Author

Choose a reason for hiding this comment

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

Seems reasonable

@simianhacker
Copy link
Member Author

@weltenwort I converted just the tests to typescript and they seem to be working. The only thing I don't know how to do (or where) is to fix the rules for the test directory so we can use default exports as the test loader expects, so I just disabled the linter for that specific line.

@weltenwort
Copy link
Member

nice! the linter override for that reason seems to be common practice in the test files

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@skh
Copy link
Contributor

skh commented Oct 19, 2018

Apologies for the late comment: Can we use infra instead of infraops for all the folder names? That way we're consistent with the x-pack/plugins folder structure.

@simianhacker
Copy link
Member Author

@skh I changed the names to infra so you will need to update as well. When we do the "Great Rename" PR we should change these to ingest to match.

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@simianhacker simianhacker merged commit 3c15067 into elastic:master Oct 19, 2018
simianhacker added a commit to simianhacker/kibana that referenced this pull request Oct 22, 2018
* [Infra UI] Test for metrics GraphQL endpoint

* Moving apollo-boost to devDeps

* Converting tests to typescript

* Renaming infraops to infra
simianhacker added a commit that referenced this pull request Oct 22, 2018
* [Infra UI] Test for metrics GraphQL endpoint

* Moving apollo-boost to devDeps

* Converting tests to typescript

* Renaming infraops to infra
@simianhacker simianhacker deleted the tests-metric-endpoint branch April 17, 2024 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants