Skip to content

Commit d2877c1

Browse files
authoredJun 12, 2024··
chore: Added a script that generates Dashboard json for reporting on libraries by version (#2267)
1 parent 8bbc8d2 commit d2877c1

File tree

4 files changed

+1902
-0
lines changed

4 files changed

+1902
-0
lines changed
 

‎dashboards/constants.js

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright 2024 New Relic Corporation. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
'use strict'
7+
const INSTRUMENTED_LIBRARIES = [
8+
'@apollo/gateway',
9+
'@apollo/server',
10+
'@aws-sdk/client-bedrock-runtime',
11+
'@aws-sdk/client-dynamodb',
12+
'@aws-sdk/client-sns',
13+
'@aws-sdk/client-sqs',
14+
'@aws-sdk/lib-dynamodb',
15+
'@aws-sdk/smithy-client',
16+
'@elastic/elasticsearch',
17+
'@grpc/grpc-js',
18+
'@hapi/hapi',
19+
'@hapi/vision',
20+
'@koa/router',
21+
'@langchain/core',
22+
'@nestjs/cli',
23+
'@nestjs/core',
24+
'@node-redis/client',
25+
'@prisma/client',
26+
'@redis/client',
27+
'@smithy/smithy-client',
28+
'amqplib',
29+
'apollo-server',
30+
'apollo-server-express',
31+
'apollo-server-fastify',
32+
'apollo-server-hapi',
33+
'apollo-server-koa',
34+
'apollo-server-lambda',
35+
'aws-sdk',
36+
'bluebird',
37+
'bunyan',
38+
'cassandra-driver',
39+
'connect',
40+
'director',
41+
'express',
42+
'fastify',
43+
'generic-pool',
44+
'ioredis',
45+
'kafkajs',
46+
'koa',
47+
'koa-route',
48+
'koa-router',
49+
'memcached',
50+
'mongodb',
51+
'mysql',
52+
'mysql2',
53+
'next',
54+
'openai',
55+
'pg',
56+
'pg-native',
57+
'pino',
58+
'q',
59+
'redis',
60+
'restify',
61+
'superagent',
62+
'undici',
63+
'when',
64+
'winston'
65+
]
66+
const MIN_NODE_VERSION = 16
67+
68+
module.exports = {
69+
INSTRUMENTED_LIBRARIES,
70+
MIN_NODE_VERSION
71+
}

‎dashboards/generate-library-usage.js

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2024 New Relic Corporation. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
'use strict'
7+
const fs = require('fs/promises')
8+
const { INSTRUMENTED_LIBRARIES, MIN_NODE_VERSION } = require('./constants')
9+
const { makeDashboard, makePage, makeWidget, libraryUsageQuery } = require('./utils')
10+
const REPORT_NAME = process.env.REPORT_NAME || 'library-usage.json'
11+
12+
function makeLibraryWidgets(libs) {
13+
const width = 4
14+
const height = 3
15+
let row = 1
16+
let column = 1
17+
18+
return libs.map((lib, index) => {
19+
const pos = index % height
20+
21+
// on a new row, set column to 1
22+
if (pos === 0) {
23+
column = 1
24+
// add width to column
25+
} else {
26+
column += width
27+
}
28+
29+
// start a new row
30+
if (pos === 0 && index !== 0) {
31+
row += height
32+
}
33+
const query = libraryUsageQuery({ lib, nodeVersion: MIN_NODE_VERSION })
34+
return makeWidget({ title: lib, column, row, width, height, query })
35+
})
36+
}
37+
38+
async function main() {
39+
const widgets = makeLibraryWidgets(INSTRUMENTED_LIBRARIES)
40+
const page = makePage({
41+
name: 'Instrumented Libraries',
42+
description: 'Reports usage by library, agent, and node.js versions',
43+
widgets
44+
})
45+
const dashboard = makeDashboard({ name: 'Node.js Library Usage', pages: [page] })
46+
await fs.writeFile(REPORT_NAME, JSON.stringify(dashboard))
47+
}
48+
49+
main()

‎dashboards/library-usage.json

+1,666
Large diffs are not rendered by default.

‎dashboards/utils.js

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*
2+
* Copyright 2024 New Relic Corporation. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
'use strict'
7+
const utils = module.exports
8+
9+
/**
10+
* @typedef {object} Page
11+
* @property {string} name
12+
* @property {description} description
13+
* @property {Widget[]} widgets
14+
*/
15+
16+
/**
17+
* @typedef {object} Dashboard
18+
* @property {string} name
19+
* @property {Page[]} pages
20+
*/
21+
22+
/**
23+
* @typedef {object} Widget
24+
* @property {string} title
25+
* @property {number} column
26+
* @property {number} row
27+
* @property {number} width
28+
* @property {number} height
29+
* @property {string} query
30+
*/
31+
32+
/**
33+
* Makes object structure of a New Relic dashboard
34+
*
35+
* @param {object} params to function
36+
* @param {string} params.name name of dashboard
37+
* @param {Page[]} params.pages page contents
38+
* @returns {Dashboard} dashboard object
39+
*/
40+
utils.makeDashboard = function makeDashboard({ name, pages }) {
41+
return {
42+
name,
43+
description: null,
44+
permissions: 'PUBLIC_READ_WRITE',
45+
pages
46+
}
47+
}
48+
49+
/**
50+
* Makes a page in a New Relic dashboard
51+
* @param {object} params to function
52+
* @param {string} params.name name of page
53+
* @param {string} params.description description of page
54+
* @param {Widget[]} params.widgets widgets in page
55+
* @returns {Page} page object
56+
*/
57+
utils.makePage = function makePage({ name, description, widgets }) {
58+
return {
59+
name,
60+
description,
61+
widgets
62+
}
63+
}
64+
65+
/**
66+
* Makes a widget in a New Relic page
67+
* @param {object} params to function
68+
* @param {string} params.title of widget
69+
* @param {number} params.column column number
70+
* @param {number} params.row row number
71+
* @param {number} [params.width] width of widget
72+
* @param {number} [params.height] height of widget
73+
* @param {string} params.query nrql query
74+
* @returns {Widget} widget object
75+
*/
76+
utils.makeWidget = function makeWidget({ title, column, row, width = 4, height = 3, query }) {
77+
return {
78+
title,
79+
layout: {
80+
column,
81+
row,
82+
width,
83+
height
84+
},
85+
linkedEntityGuids: null,
86+
visualization: {
87+
id: 'viz.bar'
88+
},
89+
rawConfiguration: {
90+
facet: {
91+
showOtherSeries: false
92+
},
93+
nrqlQueries: [
94+
{
95+
accountIds: [1],
96+
query
97+
}
98+
],
99+
platformOptions: {
100+
ignoreTimeRange: false
101+
}
102+
}
103+
}
104+
}
105+
106+
/**
107+
* Constructs NRQL for library usage
108+
*
109+
* @param {object} params to function
110+
* @param {string} params.lib name of library
111+
* @param {string} params.nodeVersion minimum node version
112+
* @returns {string} NRQL query
113+
*/
114+
utils.libraryUsageQuery = function libraryUsageQuery({ lib, nodeVersion }) {
115+
return `FROM NodeMetadataSummary SELECT uniqueCount(entity.guid) where \`${lib}.version\` IS NOT NULL and node.version.major >= '${nodeVersion}' facet \`${lib}.version\`, agentVersion, node.version.major limit max`
116+
}

0 commit comments

Comments
 (0)
Please sign in to comment.