Repository navigation
ADP-2219:Flat collection custom metrics - #332
Open
KIRTIKUMARKK21 wants to merge 5 commits into
Open
KIRTIKUMARKK21 wants to merge 5 commits into
KIRTIKUMARKK21 wants to merge 5 commits into
Conversation
Co-authored-by: Cursor <cursoragent@cursor.com>
KIRTIKUMARKK21
requested review from
avinashkolluru,
kotharironak,
puneet-traceable,
skjindal93,
suddendust and
suresh-prakash
as code owners
December 3, 2026 07:44
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #332 +/- ##
============================================
+ Coverage 81.25% 81.27% +0.02%
- Complexity 1700 1703 +3
============================================
Files 243 243
Lines 7792 7796 +4
Branches 773 773
============================================
+ Hits 6331 6336 +5
+ Misses 961 960 -1
Partials 500 500
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
karshit-harness
approved these changes
Dec 3, 2026
puneet-traceable
approved these changes
Dec 3, 2026
Co-authored-by: Cursor <cursoragent@cursor.com>
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.
Description
Support custom metrics on flat Postgres collections
Why
DocStoreMetricsRegistrycustom metrics are currently hard-wired to nestedcollections.
BaseDocStoreMetricProviderImpl.getCustomMetricsresolves thetarget collection with
dataStore.getCollection(collectionName), and onPostgres that factory always returns a
NestedPostgresCollection— a tablewith a single JSONB document column. Worse, for Postgres it will create the
nested table if it does not already exist.
That makes it impossible to report a custom metric from a flat Postgres table
(one real column per attribute, native
TEXT[]/BIGINT/BOOLEANcolumns). Any attempt either fails to find the columns or silently points at
an empty, freshly created nested table.
This blocks entity-service: API and other entity types that have moved to
Postgres now live in flat tables (
entities_api_v1and friends), so theirmetrics —
api.entities.count,real.entities.discovered.count, and the rest— cannot be reported from the store the data actually lives in. Dashboards for
migrated tenants are stale as a result.
What changed
1.
CustomMetricConfigcarries the document typeAdded a
documentTypefield, defaulted toDocumentType.NESTED:The default keeps every existing caller behaving exactly as before — this is a
source- and behaviour-compatible addition.
2.
BaseDocStoreMetricProviderImplresolves the collection by typegetCustomMetricsno longer callsgetCollectionunconditionally. It nowroutes through a small helper:
NESTEDdeliberately keeps using the originalgetCollectionpath rather thangetCollectionForType(name, NESTED)so that existing nested-collectionbehaviour, including Mongo, is bit-for-bit unchanged.
No changes were needed in the query layer:
FlatPostgresFieldTransformeralready treats a dotted identifier such as
attributes.apiDiscoveryStateas aliteral quoted column name, and
PostgresFromTypeExpressionVisitoralreadyemits a native
unnest()for array columns on flat collections rather thanjsonb_array_elements(). Once the rightCollectionimplementation isselected, grouped counts and unnested-array counts work as-is.
Tests
Unit —
BaseDocumentStoreMetricProviderImplTestNew
CollectionResolutionTestnested class covering the routing decision:nestedDocumentType_usesGetCollection— assertsgetCollectionis used andgetCollectionForTypeis never touched.flatDocumentType_usesGetCollectionForType— asserts the flat path resolvesthrough
getCollectionForType(name, FLAT), nevergetCollection, and thatthe resulting rows are still mapped into
DocStoreMetricwith the correctname, value, and labels.
defaultDocumentType_isNested— pins the backwards-compatible default.Integration —
FlatCollectionWriteTestNew
CustomMetricTestsnested class running against a real Postgres flattable:
testGroupedCountOnFlatColumns— aCOUNT(*) GROUP BY itemcustom metricover plain flat columns, asserting both the metric name and the per-label
counts.
testUnnestedArrayCount— a custom metric that groups over anunnest()edTEXT[]column (categoryTags), which is the shape the entity-servicecategory and discovery-source metrics need.
Compatibility
Fully backwards compatible.
documentTypedefaults toNESTED, so everyexisting
CustomMetricConfigbuilder call compiles unchanged and resolves itscollection exactly as it does today.
Follow-up
entity-service will consume this to report entity metrics from whichever store
a tenant's read-write feature flag points at: flat Postgres
entities_<type>_v1for migrated tenants, Mongo
raw_entitiesotherwise, with metric names andlabels unchanged so dashboards and the api-count-metrics-exporter need no edits.
Checklist:
Documentation
Make sure that you have documented corresponding changes in this repository or hypertrace docs repo if required.