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

feat(agent): Memcached instance metrics with host name #958

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from

Conversation

ZNeumann
Copy link
Contributor

These metrics can be used by the backend to create AWS relationship maps with memcached

@newrelic-php-agent-bot
Copy link

newrelic-php-agent-bot commented Aug 28, 2024

Test Suite Status Result
Multiverse 7/7 passing
SOAK 55/56 passing

INTERNAL_FUNCTION_PARAM_PASSTHRU);
}

static nr_datastore_instance_t* nr_php_memcached_create_datastore_instance(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The redis equivalent of this function is in the file agent/php_redis.c. I am ambivalent on whether to create an equal agent/php_memcached.c for just this helper or to keep it here.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would vote for creating a php_memcached.c even if it's just for one function (for now) for future readability.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

refactored in a0d261f

@codecov-commenter
Copy link

codecov-commenter commented Aug 28, 2024

Codecov Report

Attention: Patch coverage is 97.14286% with 2 lines in your changes missing coverage. Please review.

Project coverage is 78.36%. Comparing base (0ba870b) to head (c8c3637).
Report is 5 commits behind head on dev.

Files with missing lines Patch % Lines
agent/php_internal_instrument.c 97.56% 1 Missing ⚠️
agent/php_memcached.c 87.50% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #958      +/-   ##
==========================================
+ Coverage   78.32%   78.36%   +0.03%     
==========================================
  Files         194      195       +1     
  Lines       26880    26935      +55     
==========================================
+ Hits        21055    21108      +53     
- Misses       5825     5827       +2     
Flag Coverage Δ
agent-for-php-7.2 78.37% <97.14%> (+0.03%) ⬆️
agent-for-php-7.3 78.39% <97.14%> (+0.03%) ⬆️
agent-for-php-7.4 78.09% <97.14%> (+0.03%) ⬆️
agent-for-php-8.0 78.12% <97.05%> (+0.03%) ⬆️
agent-for-php-8.1 78.11% <97.05%> (+0.03%) ⬆️
agent-for-php-8.2 77.70% <97.05%> (+0.03%) ⬆️
agent-for-php-8.3 77.70% <97.05%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ZNeumann ZNeumann requested a review from zsistla August 29, 2024 12:50
Comment on lines +826 to +827
segment = nr_segment_start(NRPRG(txn), NULL, NULL);
nr_segment_datastore_end(&segment, &params);
Copy link
Contributor

Choose a reason for hiding this comment

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

This operation will probably result in an immediate (nanoseconds) segment duration. Is the rationale for this just that we have to send this data via a segment to the backend?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the datastore metric needs to be send to the backend, and the length here isn't entirely important for several reasons. 1) this datastore metric is only an instance metric, and is not associated with any operation. 2) the operation being wrapped, add_servers, is not a function that the customer will likely care about timings of

Copy link
Contributor

Choose a reason for hiding this comment

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

It sounds like we're going to be sending incorrect duration timings to the backend for this specific function call. I'm slightly worried that someone out there will care about these timings, but off the top of my head I can't think of a workaround that will generate all the segments we need in this manner without forcing a rewrite of our segment logic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It could call the metric creation function after the internal call and pass in the timing information to override the timings automatically generated by the segment start/end. It's not pretty, but would work

Copy link
Contributor

Choose a reason for hiding this comment

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

Or potentially a small function that can loop over a set of segments that have already had timings set and update segment->start_time and segment->stop_time to appropriate values? Store start and stop as variables within the wrapper function then passing them as the values to the custom function?
I don't know if that would have any side-effects...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But this does raise the important question: will these metrics -- even with correct timings -- confuse customers? There will be much longer instance metrics associated with all of the different datastore operations of the transaction, and then a few much shorter instance metrics at the start of each transaction that is not clear what they are

Copy link
Contributor

Choose a reason for hiding this comment

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

Torn on this as well- would be good to see how this will be displayed in the UI to try and gauge the "confusion" factor

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A correction to my previous statement. These instance metrics (with the host and port) are not created for other database operations because we don't have access to the host and port at those times. So these instance metrics will ONLY be the short-lived metrics created when adding a server, and the longer database metrics will be separated under operation metrics.

@@ -12,6 +12,36 @@
#include "util_sql.h"
#include "util_logging.h"

static bool create_instance_metric(nr_segment_t* segment,
Copy link
Contributor

Choose a reason for hiding this comment

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

could nix the bool return type entirely since it doesn't seem to get used in the below function calls

require_once(realpath (dirname ( __FILE__ )) . '/memcache.inc');

$memcached = new Memcached();
$memcached->addServers(array(
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a test case for the 0 port option that specifies a unix socket/localhost?

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.

5 participants