Instrument ActiveSupport Caches - #74294
Open
Hamms wants to merge 3 commits into
Open
Conversation
Hamms
commented
Jul 31, 2026
Comment on lines
65
to
75
| # Convenience method to put a single metric to CloudWatch. | ||
| # Accepts a single '[namespace]/[metric_name]' name parameter | ||
| # and a standard Ruby hash to specify dimension key/values. | ||
| # Accepts a namespace, a metric_name, and a standard Ruby | ||
| # hash to specify dimension key/values. | ||
| # | ||
| # @param [String] name in the form of 'namespace'/'metric_name' | ||
| # @param [String] namespace | ||
| # @param [String] metric_name | ||
| # @param [Number] value | ||
| # @param [Hash{Symbol => String}] dimensions | ||
| # @param [Hash] options Additional keyword arguments to be merged | ||
| # into the {Aws::CloudWatch::Types::MetricDatum} object. | ||
| def self.put(namespace, metric_name, value, dimensions, **options) |
Contributor
Author
There was a problem hiding this comment.
Looks like the jerk who updated this method signature failed to update the comment to match, so I'm fixing it up while I'm in the area 🙃
Hamms
marked this pull request as ready for review
July 31, 2026 19:58
cat5inthecradle
approved these changes
Aug 4, 2026
cat5inthecradle
left a comment
Contributor
There was a problem hiding this comment.
LGTM with one CloudWatch namespacing suggestion.
Comment on lines
+3
to
+12
| Cdo::Metrics.put( | ||
| 'Infrastructure', | ||
| 'ActiveSupportCacheRead', | ||
| 1, | ||
| { | ||
| Environment: CDO.rack_env, | ||
| Hit: event.payload[:hit].to_s, | ||
| Store: event.payload[:store] | ||
| } | ||
| ) |
Contributor
There was a problem hiding this comment.
What about doing two metrics: ActiveSupportCacheHit and ActiveSupportCacheMiss, keeping Environment and Store as dimensions and toggling which metric based on event.payload[:hit]? I think that aligns more with what I'm used to seeing in CloudWatch.
| Environment | Store | Hit | Name |
|---|---|---|---|
| production | mystore | true | ActiveSupportCacheRead |
| production | mystore | false | ActiveSupportCacheRead |
vs
| Environment | Store | Name |
|---|---|---|
| production | mystore | ActiveSupportCacheHit |
| production | mystore | ActiveSupportCacheMiss |
| production | mystore | ActiveSupportCacheBytesRead |
Functionally the same, but it'll play nicer in the CloudWatch UI, and puts it right next to the other metric in this PR.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of our ongoing work to address runaway memory usage on frontend web application servers by reexamining our caching strategy.
I want to track hit rate to get better insight into how per-process versus per-server caches improve our efficiency, as well as just generally to get a look at how well we're using our cache. I'd like to track total bytes read out of the cache so we can evaluate whether it would be feasible to fetch it over the network; from Redis, for example.
Links
https://guides.rubyonrails.org/active_support_instrumentation.html#active-support-caching
Testing story
Tested on an adhoc; repeatedly fetched
/courses/allthethingscourse/units/1with curl, and confirmed that results are as expected:Follow-up work
We probably want to remove the byte size metric after we've gathered a representative amount of data, since it's both gross and is adding a little bit of extra work to a very high-throughput method. I don't anticipate it being a problem in the short term, though.