-
Notifications
You must be signed in to change notification settings - Fork 32
Improve custom metrics documentation with clearer explanations #3789
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
Conversation
This commit enhances the custom metrics documentation to better help application developers understand how to implement and use custom metrics: - Add "How Custom Metrics Work" section explaining change detection behavior with concrete examples showing when events are created - Add "Supported Data Types" section with clear examples of valid and invalid data types (numbers, strings, booleans, null) - Improve "POST vs PATCH" section with clearer examples and explicit guidance on when to use each method - Add "Best Practices" section covering sending frequency, change detection efficiency, method selection, and naming conventions - Add "Troubleshooting" section addressing common issues like missing events, metrics not appearing, and duplicate events These changes address common confusion points identified through codebase analysis and make the documentation more actionable for developers instrumenting their applications. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
✅ Deploy Preview for replicated-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for replicated-docs-upgrade ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
docs/vendor/custom-metrics.md
Outdated
|
|
||
| [View a larger version of this image](/images/custom-metrics-flow.png) | ||
|
|
||
| Custom metrics use a change-detection system to efficiently track meaningful change events from the previous value: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this part is a bit redundant to the click-through link about how all events are calculated, and maybe it should move there. The main thing I wanted to incorporate was more clarity to the example. Vendors have been struggling to understand how the concept of "event" (which is essentially change in value) and the idea of a "metric" that's continuously reported and stored by VP
docs/vendor/custom-metrics.md
Outdated
| **Not supported**: Nested objects or arrays | ||
|
|
||
| For example, if a component of your application sends the following via the `POST` method: | ||
| **Example:** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to keep this part because i have to look this up myself all the time.
| ## Export Custom Metrics | ||
|
|
||
| You can use the Vendor API v3 `/app/{app_id}/events` endpoint to programatically access historical timeseries data containing instance level events, including any custom metrics that you have defined. For more information about the endpoint, see [Export Customer and Instance Data](/vendor/instance-data-export). | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Best practices and Troubleshooting clearly add a lot more content to this page, but I thought the AI suggestion to add them were actually quite helpful and so I've left them in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I shuffled the best practices a bit so that they each live with the relevant content, rather than being in a separate Best Practices heading. For example, info about naming custom metrics in under the new "Define custom metrics" heading, and info about frequency of sending metrics lives in a subheading under "Send Custom Metrics". The other best practices were a little redundant (eg, restating the use cases for post vs patch which is already covered in "PATCH vs POST" section)
For the troubleshooting info, I reformatted so that they follow our style guide. I also made these edits:
- Removed "I'm not seeing any events", for which the stated cause was "Events are only created when values change." It seemed like it wasn't really providing troubleshooting info so much as restating the info about how the Vendor Portal generates events. Also wasn't sure it was fair to state definitively that the cause for this is "Events are only created when values change."
- Updated the copy to add more context and make sure everything's a full sentence
paigecalvert
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @AmberAlston lgtm! details on my edits in comments
| ## Export Custom Metrics | ||
|
|
||
| You can use the Vendor API v3 `/app/{app_id}/events` endpoint to programatically access historical timeseries data containing instance level events, including any custom metrics that you have defined. For more information about the endpoint, see [Export Customer and Instance Data](/vendor/instance-data-export). | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I shuffled the best practices a bit so that they each live with the relevant content, rather than being in a separate Best Practices heading. For example, info about naming custom metrics in under the new "Define custom metrics" heading, and info about frequency of sending metrics lives in a subheading under "Send Custom Metrics". The other best practices were a little redundant (eg, restating the use cases for post vs patch which is already covered in "PATCH vs POST" section)
For the troubleshooting info, I reformatted so that they follow our style guide. I also made these edits:
- Removed "I'm not seeing any events", for which the stated cause was "Events are only created when values change." It seemed like it wasn't really providing troubleshooting info so much as restating the info about how the Vendor Portal generates events. Also wasn't sure it was fair to state definitively that the cause for this is "Events are only created when values change."
- Updated the copy to add more context and make sure everything's a full sentence
| - Ensure that the application instance is using the Replicated SDK version 1.0.0-beta.12 or later. If your application is using the `PATCH` and `DELETE` methods, version 1.0.0-beta.23 or later of the SDK is required. | ||
| - Verify that your payload only contains scalar values (no nested objects or arrays), and is valid JSON with proper content type headers | ||
| - Test network connectivity by confirming that the application can reach `http://replicated:3000` | ||
| - Check that your application is using the intended method (PATCH or POST). If a metric payload is sent using the POST method, any existing metrics that are not included in the payload are removed from the instance summary. For more information, see [PATCH vs POST](#patch-vs-post). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Check that your application is using the intended method (PATCH or POST). If a metric payload is sent using the POST method, any existing metrics that are not included in the payload are removed from the instance summary. For more information, see PATCH vs POST.
Added this one. Could remove if it seems unlikely
| To troubleshoot this issue: | ||
| - Review your metric collection logic to ensure consistent value calculation | ||
| - Check for floating-point precision issues with numeric values | ||
| - Verify that boolean values are consistently true or false and are not truthy or falsy conversions No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left in this "Duplicate events for unchanged values" troubleshooting item, but wasn't sure how likely it was. Floating-point precision issues and truthy or falsy conversions seemed like very low level/rare issues
| 10:10 AM → Send {"users": 150, "region": "us-west"} | ||
| Creates one event: users changed to 150 | ||
| No event for region because the value is unchanged | ||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did end up moving this example over to the linked page about how the vendor portal generates events, since that info is not specific to custom metrics
| * The SDK API accepts only JSON scalar values for metrics. Any requests containing nested objects or arrays are rejected. | ||
|
|
||
| ## Configure Custom Metrics | ||
| ## Define Custom Metrics in JSON Payload |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the h2s on this page so that we have Define Custom Metrics and Send Custom Metrics. This gives us space to talk about requirements for the json payload itself and how to name custom metrics (ie, "define custom metrics") as well as space to talk about patch v post and how often to send payloads to the sdk (ie, "send custom metrics")
| "active_users": 150, // Number | ||
| "cpu_usage_percent": 75.5, // Number | ||
| "sso_enabled": true, // Boolean | ||
| "deployment_region": "us-east-1", // String |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: I removed the one item in this example that was showing an unsupported format (array). It felt like it would be easy for people to just skim this example and think that the array was supported
|
Excellent edits, thanks for the collaboration @paigecalvert |
Summary
This PR enhances the custom metrics documentation to better help application developers understand how to implement and use custom metrics effectively.
Preview: https://deploy-preview-3789--replicated-docs.netlify.app/vendor/custom-metrics
Original page: https://docs.replicated.com/vendor/custom-metrics#overview
Changes
1. Added "How Custom Metrics Work" Section
2. Added "Supported Data Types" Section
3. Improved "POST vs PATCH" Section
4. Added "Best Practices" Section
5. Added "Troubleshooting" Section
Motivation
These improvements address common confusion points identified through codebase analysis:
Related Research
Based on internal codebase analysis documented in
vandoor/research_custom_metrics_system.md🤖 Generated with Claude Code