Saturday, 27 January 2018

Build performance reports for your Apollo React Components in 30 minutes. ⏲️

Build consolidated data — Setup AWS Athena

Athena is a service of Amazon that allow to run SQL queries against S3 files.

Configuring Athena is quite easy, you need to:

  1. create a database
  2. create a table by specifying a source and the data structure
  3. create a named query and save it

The data

Here is the raw data structure that Segment store to S3
(for the Perfomance.QueryLoadTime event)

You’ll notice that many field are not relevant for data analysis, so we’re gonna only keep a subset.

Create a database and a table

Note: The “Create table” UI available on AWS Athena do not allow to create table with complex data structure (nested field, union type field, etc), so we need to write a create table query, by hand ✍️

Athena use a Apache HIVE language to describe data, here is the wanted CREATE TABLE query :

The query expose the data format (JSON), data structure, the source and the destination

To do so, we can use a wonderful tool called hive-json-schema .
This is an open source project — recommended by AWS official documentation — to generate HIVE query from JSON raw data.

In short, given a JSON example file, it generate a corresponding CREATE TABLE query.

Read the doc, it’s really simple (take 5 minutes maximum).

Write and save a SELECT Query

The table is now ready, we can write a SELECT query.
Here’s ours:

SELECT
properties.ellapsedMs, properties.operationName, sentAt
FROM "segment"."perf" WHERE
event = 'Performance.QueryLoadTime'
ORDER BY sentAt DESC;

Since it’s plain SQL, you can select all the field available on this table.

Run the query and save it.

NB: each time a query is executed, Athena store the CSV result on your S3.
To know where (which bucket), go to Settings.

Problem

Athena do not propose to run a saved query periodically.
However, we can use the AWS Athena API to run a query remotely.
Next step, the lambda.

The post Build performance reports for your Apollo React Components in 30 minutes. ⏲️ appeared first on Crypto Currency Online.



source https://cryptocurrencyonline.co/build-performance-reports-for-your-apollo-react-components-in-30-minutes-%e2%8f%b2%ef%b8%8f/

No comments:

Post a Comment