Skip to content

Update EUI Analytics Scripts #8300

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
22 changes: 21 additions & 1 deletion packages/eui-usage-analytics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,29 @@ This script must be run from this directory.

```
CLOUD_ID_SECRET=****** AUTH_APIKEY_SECRET=****** node index.js

# Repository roots can be overridden as well. Check --help for more info
CLOUD_ID_SECRET=****** AUTH_APIKEY_SECRET=****** node index.js --kibana-root=/path/to/kibana
```

To do a dry run for testing:
```
node index.js --dry
```

## If you ever need to delete a bad scan:
```
POST /eui_components/_delete_by_query
{
"query": {
"term": {
"@timestamp": "2024-07-22T20:39:38.992Z"
}
}
}
```

## Schema
## Record Schema

This script will store data in an Elastic index named `eui_components`.

Expand Down
58 changes: 41 additions & 17 deletions packages/eui-usage-analytics/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,57 @@
*/

const { scan } = require('./scan');
const yargs = require('yargs/yargs');
const { hideBin } = require('yargs/helpers');

const { Client } = require('@elastic/elasticsearch');

if (!process.env.CLOUD_ID_SECRET || !process.env.AUTH_APIKEY_SECRET) {
console.error(
'CLOUD_ID_SECRET and AUTH_APIKEY_SECRET environment variables must be set before running this script.'
);
process.exit(1);
}
const argv = yargs(hideBin(process.argv))
.option('kibana-root', {
type: 'string',
describe: 'Path to Kibana repo root',
})
.option('dry', {
type: 'boolean',
describe: 'Path to Kibana repo root',
})
.help().argv;

let client;

const client = new Client({
cloud: {
id: process.env.CLOUD_ID_SECRET,
},
auth: {
apiKey: process.env.AUTH_APIKEY_SECRET,
},
});
if (!argv['dry']) {
if (!process.env.CLOUD_ID_SECRET || !process.env.AUTH_APIKEY_SECRET) {
console.error(
'CLOUD_ID_SECRET and AUTH_APIKEY_SECRET environment variables must be set before running this script.'
);
process.exit(1);
}

client = new Client({
cloud: {
id: process.env.CLOUD_ID_SECRET,
},
auth: {
apiKey: process.env.AUTH_APIKEY_SECRET,
},
});
}

const run = async () => {
const result = await scan();
const result = await scan({
kibanaRoot: argv['kibana-root'],
cloudRoot: argv['cloud-root'],
});
const operations = result.flatMap((doc) => [
{ index: { _index: 'eui_components' } },
doc,
]);
const response = await client.bulk({ refresh: true, operations });
console.log(response);
if (client) {
const response = await client.bulk({ refresh: true, operations });
console.log(response);
} else {
console.log(result);
}
};

run().catch((e) => console.error(e));
9 changes: 8 additions & 1 deletion packages/eui-usage-analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
"@elastic/elasticsearch": "^8.14.0",
"codeowners": "^5.1.1",
"escodegen-wallaby": "^1.6.44",
"react-scanner": "^1.1.0"
"react-scanner": "^1.1.0",
"yargs": "^17.7.2"
},
"scripts": {
"test": "jest"
},
"devDependencies": {
"jest": "^29.7.0"
}
}
Loading
Loading