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

Draft: Initial get_connection wrapper for redis metrics closes #1148 #1194

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

dbgoytia
Copy link

@dbgoytia dbgoytia commented Jul 16, 2022

Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Fixes #1148

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Test A

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@dbgoytia dbgoytia requested a review from a team July 16, 2022 19:03
@dbgoytia dbgoytia force-pushed the 1040-redis-instrumentation branch 2 times, most recently from 3639dc4 to ec35a24 Compare July 16, 2022 19:07
@dbgoytia dbgoytia changed the title Draft: Initial get_connection wrapper for redis metrics. Draft: Initial get_connection wrapper for redis metrics closes #1148 Jul 16, 2022
@srikanthccv srikanthccv marked this pull request as draft July 17, 2022 01:23
@dbgoytia dbgoytia force-pushed the 1040-redis-instrumentation branch 3 times, most recently from 97d31b6 to 9fcbe15 Compare July 20, 2022 23:40
@dbgoytia dbgoytia force-pushed the 1040-redis-instrumentation branch from 9fcbe15 to 113730d Compare July 20, 2022 23:43
Copy link
Member

@srikanthccv srikanthccv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if this instrumentation logic is correct

Comment on lines +164 to +178
connections_usage.add(
1,
{
"db.client.connection.usage.state": "used",
"db.client.connection.usage.name": instance.connection_pool.pid,
})
if callable(response_hook):
response_hook(span, instance, response)
finally:
connections_usage.add(
-1,
{
"db.client.connection.usage.state": "idle",
"db.client.connection.usage.name": instance.connection_pool.pid,
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you decide the state of connection yourself based on the command execution? This can't be correct right?

connections_usage.add(
1,
{
"db.client.connection.usage.state": "used",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is get connection same as used?

meter_provider
)
connections_usage = meter.create_up_down_counter(
name="db.client.connection.usage",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's "db.client.connections.usage"

connections_usage.add(
1,
{
"db.client.connection.usage.state": "used",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

according to the spec, the prefix "db.client.connection.usage" should be omitted. look the comment here: open-telemetry/opentelemetry-js-contrib#1220 (comment)
The name of the attribute is just "state"

1,
{
"db.client.connection.usage.state": "used",
"db.client.connection.usage.name": instance.connection_pool.pid,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

according to the spec, there is no attribute named db.client.connection.usage.name. But there is pool.name. see here: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/database-metrics.md

You can also see the conversation about pool.name I had here: open-telemetry/opentelemetry-specification#2958
It was specific for mysql in jacascript but still can give an idea about what is pool name.

response_hook(span, instance, response)
finally:
connections_usage.add(
-1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a cycle of using a connection:

  1. First you create a connection and it becomes part of the pool ( -> should add +1 to 'idle').
  2. Then you start using it ( -> should add +1 to 'used' and -1 to 'idle').
  3. Then you release/finish using it ( -> should add -1 to 'used', and +1 to 'idle').
  4. Finally it is removed from the pool ( -> should add -1 to 'idle')

You should find these events in the redis code and understand when a connection is created, used, removed etc. each of these events should be reflected in the number of 'idle' and/or 'used' connection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Metrics instrumentation redis
4 participants