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

test: Updated ioredis tests to assert the host metric getting created on ioredis calls #2230

Merged
merged 1 commit into from
May 29, 2024
Merged
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
8 changes: 8 additions & 0 deletions test/versioned/ioredis/ioredis-3.tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,25 @@ const helper = require('../../lib/agent_helper')
const { removeMatchedModules } = require('../../lib/cache-buster')
require('../../lib/metrics_helper')
const params = require('../../lib/params')
const urltils = require('../../../lib/util/urltils')

// Indicates unique database in Redis. 0-15 supported.
const DB_INDEX = 4

tap.test('ioredis instrumentation', function (t) {
let agent
let redisClient
let METRIC_HOST_NAME
let HOST_ID

t.beforeEach(async function () {
const result = await setup(t)
agent = result.agent
redisClient = result.client
METRIC_HOST_NAME = urltils.isLocalhost(params.redis_host)
? agent.config.getHostnameSafe()
: params.redis_host
HOST_ID = METRIC_HOST_NAME + '/' + params.redis_port
})

t.afterEach(function () {
Expand All @@ -40,6 +47,7 @@ tap.test('ioredis instrumentation', function (t) {
[{ name: 'Datastore/Redis/all' }],
[{ name: 'Datastore/operation/Redis/set' }]
]
expected['Datastore/instance/Redis/' + HOST_ID] = 2
t.assertMetrics(tx.metrics, expected, false, false)
t.end()
})
Expand Down
8 changes: 8 additions & 0 deletions test/versioned/ioredis/ioredis.tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,27 @@ const tap = require('tap')
const helper = require('../../lib/agent_helper')
require('../../lib/metrics_helper')
const params = require('../../lib/params')
const urltils = require('../../../lib/util/urltils')

// Indicates unique database in Redis. 0-15 supported.
const DB_INDEX = 3

tap.test('ioredis instrumentation', (t) => {
let agent = null
let redisClient = null
let METRIC_HOST_NAME
let HOST_ID

t.autoend()
t.beforeEach(async () => {
agent = helper.instrumentMockedAgent()
const Redis = require('ioredis')
redisClient = new Redis(params.redis_port, params.redis_host)
await helper.flushRedisDb(redisClient, DB_INDEX)
METRIC_HOST_NAME = urltils.isLocalhost(params.redis_host)
? agent.config.getHostnameSafe()
: params.redis_host
HOST_ID = METRIC_HOST_NAME + '/' + params.redis_port

await new Promise(async (resolve, reject) => {
redisClient.select(DB_INDEX, (err) => {
Expand All @@ -48,6 +55,7 @@ tap.test('ioredis instrumentation', (t) => {
[{ name: 'Datastore/Redis/all' }],
[{ name: 'Datastore/operation/Redis/set' }]
]
expected['Datastore/instance/Redis/' + HOST_ID] = 2

t.assertMetrics(tx.metrics, expected, false, false)
t.end()
Expand Down
Loading