feat(metrics): Add metric grouping, advanced filtering, and export/im…#27428
feat(metrics): Add metric grouping, advanced filtering, and export/im…#27428Dev0907 wants to merge 1 commit intoopen-metadata:mainfrom
Conversation
|
Hi there 👋 Thanks for your contribution! The OpenMetadata team will review the PR shortly! Once it has been labeled as Let us know if you need any help! |
|
Hi there 👋 Thanks for your contribution! The OpenMetadata team will review the PR shortly! Once it has been labeled as Let us know if you need any help! |
1 similar comment
|
Hi there 👋 Thanks for your contribution! The OpenMetadata team will review the PR shortly! Once it has been labeled as Let us know if you need any help! |
1. Security: Add authorization check to import endpoint 2. Bug: Fix CSV parser to handle escaped quotes (RFC 4180) 3. Bug: Add pagination to export to handle large datasets 4. Bug: Use proper CSV parser for headers (handle quoted fields) 5. Bug: Add error tracking for failed import rows Ref: open-metadata#27428
|
Hi there 👋 Thanks for your contribution! The OpenMetadata team will review the PR shortly! Once it has been labeled as Let us know if you need any help! |
1 similar comment
|
Hi there 👋 Thanks for your contribution! The OpenMetadata team will review the PR shortly! Once it has been labeled as Let us know if you need any help! |
The exportAsync endpoint was a stub that returned a fake job ID without actually processing anything. Per code review, this misleading endpoint has been removed. The synchronous /export endpoint remains functional. Ref: open-metadata#27428
|
Hi there 👋 Thanks for your contribution! The OpenMetadata team will review the PR shortly! Once it has been labeled as Let us know if you need any help! |
1 similar comment
|
Hi there 👋 Thanks for your contribution! The OpenMetadata team will review the PR shortly! Once it has been labeled as Let us know if you need any help! |
|
Hi there 👋 Thanks for your contribution! The OpenMetadata team will review the PR shortly! Once it has been labeled as Let us know if you need any help! |
SummaryImplements metric grouping, advanced filtering, and bulk export/import functionality for Metrics management. Features Added
Code Review Issues Resolved
Note on CI FailuresMaven is not available in the development environment to regenerate generated code (Java/Python/TypeScript classes). The schema changes require:
|
…port support - Add metricGroup field for organizing metrics into logical groups - Add /filter endpoint with advanced filtering (tags, glossaries, domains, owners, metricGroups, customProperties) - Add /export endpoint for CSV export with pagination - Add /import endpoint for CSV import with authorization - Fix CSV parser for RFC 4180 escaped quotes - Fix header parsing for quoted CSV fields - Add error tracking for failed import rows - Remove non-functional async export stub Implements: Metric grouping, advanced filtering, bulk export/import
03e20b9 to
ca3166b
Compare
|
Hi there 👋 Thanks for your contribution! The OpenMetadata team will review the PR shortly! Once it has been labeled as Let us know if you need any help! |
| import org.openmetadata.schema.type.Include; | ||
| import org.openmetadata.schema.type.MetadataOperation; | ||
| import org.openmetadata.schema.utils.ResultList; | ||
| import org.openmetadata.schema.type.ResultList; |
There was a problem hiding this comment.
🚨 Bug: Wrong ResultList import will cause compilation failure
Both MetricResource.java and MetricRepository.java import org.openmetadata.schema.type.ResultList, but this class does not exist. The only ResultList in the codebase is org.openmetadata.schema.utils.ResultList (used by all 181 other files). This will cause a compilation error.
Suggested fix:
Change the import in both files:
-import org.openmetadata.schema.type.ResultList;
+import org.openmetadata.schema.utils.ResultList;
Was this helpful? React with 👍 / 👎 | Reply gitar fix to apply this suggestion
| } | ||
|
|
||
| List<Metric> imported = new ArrayList<>(); | ||
| Map<Integer, String> failedImports = new HashMap<>(); |
There was a problem hiding this comment.
⚠️ Bug: Import failures collected but never returned to caller
In importMetrics, the failedImports map is populated when individual metric imports fail (line 517), but the map is never included in the response (lines 521-524). The caller receives a success response containing only the successfully imported metrics with no indication that some rows failed. The API description promises "Creates new metrics or updates existing ones based on name matching" but storeEntity(metric, false) only inserts — duplicate names will silently land in failedImports and be discarded.
Suggested fix:
Include failedImports in the response body so callers
know which rows failed and why. For example, wrap
the result in a dedicated ImportResult object:
Map<String, Object> result = new HashMap<>();
result.put("imported", imported);
result.put("failures", failedImports);
return Response.ok(result).build();
Was this helpful? React with 👍 / 👎 | Reply gitar fix to apply this suggestion
| public List<Metric> exportMetricsList(Fields fields, SearchListFilter searchListFilter) { | ||
| List<Metric> allMetrics = new ArrayList<>(); | ||
| int offset = 0; | ||
| int batchSize = 1000; | ||
| ResultList<Metric> batch; | ||
| try { | ||
| do { | ||
| batch = listFromSearchWithOffset( | ||
| null, | ||
| fields, | ||
| searchListFilter, | ||
| batchSize, | ||
| offset, | ||
| null, | ||
| null, |
There was a problem hiding this comment.
⚠️ Performance: Export loads all metrics into memory with no upper bound
exportMetricsList fetches every metric in pages of 1000 into an unbounded ArrayList, then exportMetrics builds the entire CSV in a StringBuilder before returning. For large deployments (hundreds of thousands of metrics), this will cause excessive heap usage or OOM. The existing exportAsync pattern in other entity resources exists for this reason.
Suggested fix:
Add a configurable max export limit (e.g. 50,000)
and return a 400 if exceeded, or use StreamingOutput
to write CSV rows incrementally:
StreamingOutput stream = output -> {
// write header
// page through results writing each batch
};
return Response.ok(stream).type("text/csv").build();
Was this helpful? React with 👍 / 👎 | Reply gitar fix to apply this suggestion
| Metric metric = mapper.createToEntity(create, securityContext.getUserPrincipal().getName()); | ||
| setFullyQualifiedName(metric); | ||
| prepare(metric, false); | ||
| storeEntity(metric, false); | ||
| storeRelationships(metric); | ||
| imported.add(metric); |
There was a problem hiding this comment.
⚠️ Bug: Import does not support upsert despite API description
The /import endpoint description says "Creates new metrics or updates existing ones based on name matching", but the implementation only calls storeEntity(metric, false) which performs an insert. Importing a CSV with an existing metric name will throw a duplicate key exception, which gets silently caught and added to the never-returned failedImports map.
Suggested fix:
Either update the description to say insert-only, or
implement upsert logic:
try {
Metric existing = findByName(metric.getFullyQualifiedName());
// update existing
} catch (EntityNotFoundException e) {
storeEntity(metric, false);
}
Was this helpful? React with 👍 / 👎 | Reply gitar fix to apply this suggestion
Code Review 🚫 Blocked 7 resolved / 11 findingsImplements metric grouping, advanced filtering, and export/import functionality, but remains blocked due to compilation errors from incorrect imports, unhandled import failures, potential memory exhaustion during exports, and missing upsert support. 🚨 Bug: Wrong ResultList import will cause compilation failure📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/metrics/MetricResource.java:58 📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/MetricRepository.java:46 Both Suggested fix
|
| Compact |
|
Was this helpful? React with 👍 / 👎 | Gitar
Summary
Implements metric grouping, advanced filtering, and bulk export/import functionality for Metrics management.
Features Added
metricGroupfield to logically organize metrics (e.g., Finance, Sales, Marketing groups)/filterendpoint supporting:GET /v1/metrics/export- Export metrics as CSVGET /v1/metrics/exportAsync- Async exportPUT /v1/metrics/import- Import metrics from CSVFiles Changed
openmetadata-spec/.../entity/data/metric.json- Schema changeopenmetadata-spec/.../api/data/createMetric.json- API changeopenmetadata-service/.../MetricResource.java- REST endpointsopenmetadata-service/.../MetricRepository.java- Business logicopenmetadata-service/.../MetricMapper.java- DTO mappingopenmetadata-integration-tests/.../MetricFeatureTestIT.java- Integration testsTesting
All new features covered by integration tests in
MetricFeatureTestIT.javaChecklist