Skip to content

Commit

Permalink
chore: Added a script that generates Dashboard json for reporting on …
Browse files Browse the repository at this point in the history
…libraries by version (#2267)
bizob2828 authored Jun 12, 2024

Verified

This commit was signed with the committer’s verified signature.
tzarc Nick Brassel
1 parent 8bbc8d2 commit d2877c1
Showing 4 changed files with 1,902 additions and 0 deletions.
71 changes: 71 additions & 0 deletions dashboards/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright 2024 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

'use strict'
const INSTRUMENTED_LIBRARIES = [
'@apollo/gateway',
'@apollo/server',
'@aws-sdk/client-bedrock-runtime',
'@aws-sdk/client-dynamodb',
'@aws-sdk/client-sns',
'@aws-sdk/client-sqs',
'@aws-sdk/lib-dynamodb',
'@aws-sdk/smithy-client',
'@elastic/elasticsearch',
'@grpc/grpc-js',
'@hapi/hapi',
'@hapi/vision',
'@koa/router',
'@langchain/core',
'@nestjs/cli',
'@nestjs/core',
'@node-redis/client',
'@prisma/client',
'@redis/client',
'@smithy/smithy-client',
'amqplib',
'apollo-server',
'apollo-server-express',
'apollo-server-fastify',
'apollo-server-hapi',
'apollo-server-koa',
'apollo-server-lambda',
'aws-sdk',
'bluebird',
'bunyan',
'cassandra-driver',
'connect',
'director',
'express',
'fastify',
'generic-pool',
'ioredis',
'kafkajs',
'koa',
'koa-route',
'koa-router',
'memcached',
'mongodb',
'mysql',
'mysql2',
'next',
'openai',
'pg',
'pg-native',
'pino',
'q',
'redis',
'restify',
'superagent',
'undici',
'when',
'winston'
]
const MIN_NODE_VERSION = 16

module.exports = {
INSTRUMENTED_LIBRARIES,
MIN_NODE_VERSION
}
49 changes: 49 additions & 0 deletions dashboards/generate-library-usage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2024 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

'use strict'
const fs = require('fs/promises')
const { INSTRUMENTED_LIBRARIES, MIN_NODE_VERSION } = require('./constants')
const { makeDashboard, makePage, makeWidget, libraryUsageQuery } = require('./utils')
const REPORT_NAME = process.env.REPORT_NAME || 'library-usage.json'

function makeLibraryWidgets(libs) {
const width = 4
const height = 3
let row = 1
let column = 1

return libs.map((lib, index) => {
const pos = index % height

// on a new row, set column to 1
if (pos === 0) {
column = 1
// add width to column
} else {
column += width
}

// start a new row
if (pos === 0 && index !== 0) {
row += height
}
const query = libraryUsageQuery({ lib, nodeVersion: MIN_NODE_VERSION })
return makeWidget({ title: lib, column, row, width, height, query })
})
}

async function main() {
const widgets = makeLibraryWidgets(INSTRUMENTED_LIBRARIES)
const page = makePage({
name: 'Instrumented Libraries',
description: 'Reports usage by library, agent, and node.js versions',
widgets
})
const dashboard = makeDashboard({ name: 'Node.js Library Usage', pages: [page] })
await fs.writeFile(REPORT_NAME, JSON.stringify(dashboard))
}

main()
1,666 changes: 1,666 additions & 0 deletions dashboards/library-usage.json

Large diffs are not rendered by default.

116 changes: 116 additions & 0 deletions dashboards/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* Copyright 2024 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

'use strict'
const utils = module.exports

/**
* @typedef {object} Page
* @property {string} name
* @property {description} description
* @property {Widget[]} widgets
*/

/**
* @typedef {object} Dashboard
* @property {string} name
* @property {Page[]} pages
*/

/**
* @typedef {object} Widget
* @property {string} title
* @property {number} column
* @property {number} row
* @property {number} width
* @property {number} height
* @property {string} query
*/

/**
* Makes object structure of a New Relic dashboard
*
* @param {object} params to function
* @param {string} params.name name of dashboard
* @param {Page[]} params.pages page contents
* @returns {Dashboard} dashboard object
*/
utils.makeDashboard = function makeDashboard({ name, pages }) {
return {
name,
description: null,
permissions: 'PUBLIC_READ_WRITE',
pages
}
}

/**
* Makes a page in a New Relic dashboard
* @param {object} params to function
* @param {string} params.name name of page
* @param {string} params.description description of page
* @param {Widget[]} params.widgets widgets in page
* @returns {Page} page object
*/
utils.makePage = function makePage({ name, description, widgets }) {
return {
name,
description,
widgets
}
}

/**
* Makes a widget in a New Relic page
* @param {object} params to function
* @param {string} params.title of widget
* @param {number} params.column column number
* @param {number} params.row row number
* @param {number} [params.width] width of widget
* @param {number} [params.height] height of widget
* @param {string} params.query nrql query
* @returns {Widget} widget object
*/
utils.makeWidget = function makeWidget({ title, column, row, width = 4, height = 3, query }) {
return {
title,
layout: {
column,
row,
width,
height
},
linkedEntityGuids: null,
visualization: {
id: 'viz.bar'
},
rawConfiguration: {
facet: {
showOtherSeries: false
},
nrqlQueries: [
{
accountIds: [1],
query
}
],
platformOptions: {
ignoreTimeRange: false
}
}
}
}

/**
* Constructs NRQL for library usage
*
* @param {object} params to function
* @param {string} params.lib name of library
* @param {string} params.nodeVersion minimum node version
* @returns {string} NRQL query
*/
utils.libraryUsageQuery = function libraryUsageQuery({ lib, nodeVersion }) {
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`
}

0 comments on commit d2877c1

Please sign in to comment.