|
10 | 10 | import org.hypertrace.core.documentstore.expression.impl.ConstantExpression; |
11 | 11 | import org.hypertrace.core.documentstore.expression.impl.IdentifierExpression; |
12 | 12 | import org.hypertrace.core.documentstore.expression.impl.RelationalExpression; |
| 13 | +import org.hypertrace.core.documentstore.expression.impl.UnnestExpression; |
13 | 14 | import org.hypertrace.core.documentstore.expression.operators.RelationalOperator; |
14 | 15 | import org.hypertrace.core.documentstore.model.config.CustomMetricConfig; |
15 | 16 | import org.hypertrace.core.documentstore.query.Filter; |
|
22 | 23 | public class EntityMetricsReporter { |
23 | 24 |
|
24 | 25 | private static final String API_COUNT_METRIC_NAME = "api.entities.count"; |
| 26 | + private static final String API_CATEGORY_METRIC_NAME = "api.categories.count"; |
25 | 27 | private static final String RAW_ENTITIES_COLLECTION = "raw_entities"; |
26 | 28 | private static final String API_DISCOVERY_STATE_ENTITY_PATH = |
27 | 29 | "attributes.api_discovery_state.value.string"; |
| 30 | + private static final String API_CATEGORIES_ENTITY_PATH = "attributes.categories.valueList.values"; |
| 31 | + private static final String API_CATEGORY_ENTITY_PATH = |
| 32 | + "attributes.categories.valueList.values.value.string"; |
28 | 33 | private static final String API_DISCOVERY_STATE = "apiDiscoveryState"; |
| 34 | + private static final String API_CATEGORY = "category"; |
29 | 35 | private static final String TENANT_ID_ENTITY_PATH = "tenantId"; |
30 | 36 | private static final String ENTITY_TYPE_ENTITY_PATH = "entityType"; |
31 | 37 | private final DocStoreMetricsRegistry metricsRegistry; |
@@ -66,6 +72,31 @@ public void monitor() { |
66 | 72 | IdentifierExpression.of(API_DISCOVERY_STATE_ENTITY_PATH)) |
67 | 73 | .build()) |
68 | 74 | .build()) |
| 75 | + .build(), |
| 76 | + DocStoreCustomMetricReportingConfig.builder() |
| 77 | + .reportingInterval(Duration.ofHours(6)) |
| 78 | + .config( |
| 79 | + CustomMetricConfig.builder() |
| 80 | + .metricName(API_CATEGORY_METRIC_NAME) |
| 81 | + .collectionName(RAW_ENTITIES_COLLECTION) |
| 82 | + .query( |
| 83 | + Query.builder() |
| 84 | + .setFilter(getFilter()) |
| 85 | + .addFromClause( |
| 86 | + UnnestExpression.builder() |
| 87 | + .identifierExpression( |
| 88 | + IdentifierExpression.of(API_CATEGORIES_ENTITY_PATH)) |
| 89 | + .build()) |
| 90 | + .addSelection(IdentifierExpression.of(TENANT_ID_ENTITY_PATH)) |
| 91 | + .addSelection( |
| 92 | + IdentifierExpression.of(API_CATEGORY_ENTITY_PATH), API_CATEGORY) |
| 93 | + .addSelection( |
| 94 | + AggregateExpression.of(COUNT, ConstantExpression.of(1)), |
| 95 | + VALUE_KEY) |
| 96 | + .addAggregation(IdentifierExpression.of(TENANT_ID_ENTITY_PATH)) |
| 97 | + .addAggregation(IdentifierExpression.of(API_CATEGORY_ENTITY_PATH)) |
| 98 | + .build()) |
| 99 | + .build()) |
69 | 100 | .build()); |
70 | 101 |
|
71 | 102 | private Filter getFilter() { |
|
0 commit comments