|
19 | 19 |
|
20 | 20 | package org.apache.iotdb.db.schemaengine.metric; |
21 | 21 |
|
| 22 | +import org.apache.iotdb.commons.schema.table.TsTable; |
| 23 | +import org.apache.iotdb.commons.schema.table.column.FieldColumnSchema; |
22 | 24 | import org.apache.iotdb.commons.service.metric.MetricService; |
| 25 | +import org.apache.iotdb.commons.service.metric.enums.Tag; |
23 | 26 | import org.apache.iotdb.db.schemaengine.rescon.MemSchemaEngineStatistics; |
24 | 27 | import org.apache.iotdb.db.schemaengine.rescon.MemSchemaRegionStatistics; |
| 28 | +import org.apache.iotdb.db.schemaengine.table.DataNodeTableCache; |
| 29 | +import org.apache.iotdb.db.schemaengine.table.ITableCache; |
25 | 30 | import org.apache.iotdb.metrics.config.MetricConfig; |
26 | 31 | import org.apache.iotdb.metrics.config.MetricConfigDescriptor; |
27 | 32 | import org.apache.iotdb.metrics.metricsets.IMetricSet; |
|
30 | 35 | import org.apache.iotdb.metrics.utils.MetricInfo; |
31 | 36 | import org.apache.iotdb.metrics.utils.MetricLevel; |
32 | 37 |
|
| 38 | +import org.apache.tsfile.enums.TSDataType; |
| 39 | +import org.apache.tsfile.file.metadata.enums.CompressionType; |
| 40 | +import org.apache.tsfile.file.metadata.enums.TSEncoding; |
33 | 41 | import org.junit.After; |
34 | 42 | import org.junit.Before; |
35 | 43 | import org.junit.Test; |
|
51 | 59 | public class SchemaMemMetricTableTest { |
52 | 60 |
|
53 | 61 | private static final String TABLE = "t1"; |
| 62 | + private static final String DATABASE = "root.prometheus_metric_test"; |
| 63 | + private static final int SCHEMA_REGION_ID = 4321; |
54 | 64 |
|
55 | 65 | private final MetricService service = MetricService.getInstance(); |
56 | 66 | private final MetricConfig config = MetricConfigDescriptor.getInstance().getMetricConfig(); |
@@ -95,6 +105,39 @@ public void testSchemaRegionTableMetrics() { |
95 | 105 | checkTableMetrics(metric, metric::bindTableMetrics, table2DevicesNum); |
96 | 106 | } |
97 | 107 |
|
| 108 | + @Test |
| 109 | + public void testSchemaRegionSeriesMetricsIncludeTableMeasurements() { |
| 110 | + final ITableCache tableCache = DataNodeTableCache.getInstance(); |
| 111 | + tableCache.invalid(DATABASE); |
| 112 | + final TsTable table = new TsTable(TABLE); |
| 113 | + table.addColumnSchema( |
| 114 | + new FieldColumnSchema("s1", TSDataType.INT32, TSEncoding.RLE, CompressionType.GZIP)); |
| 115 | + table.addColumnSchema( |
| 116 | + new FieldColumnSchema("s2", TSDataType.INT32, TSEncoding.RLE, CompressionType.GZIP)); |
| 117 | + tableCache.preUpdateTable(DATABASE, table, null); |
| 118 | + tableCache.commitUpdateTable(DATABASE, TABLE, null); |
| 119 | + |
| 120 | + final MemSchemaRegionStatistics statistics = |
| 121 | + new MemSchemaRegionStatistics(SCHEMA_REGION_ID, new MemSchemaEngineStatistics()); |
| 122 | + statistics.addMeasurement(2); |
| 123 | + statistics.addView(1); |
| 124 | + statistics.getTable2DevicesNumMap().put(TABLE, 3L); |
| 125 | + final SchemaRegionMemMetric metric = new SchemaRegionMemMetric(statistics, DATABASE); |
| 126 | + |
| 127 | + service.addMetricSet(metric); |
| 128 | + try { |
| 129 | + assertEquals( |
| 130 | + 9, getSchemaRegionGauge("schema_region_series_cnt", SCHEMA_REGION_ID).getValue(), 0); |
| 131 | + assertEquals( |
| 132 | + 8, |
| 133 | + getSchemaRegionGauge("schema_region_non_view_series_cnt", SCHEMA_REGION_ID).getValue(), |
| 134 | + 0); |
| 135 | + } finally { |
| 136 | + service.removeMetricSet(metric); |
| 137 | + tableCache.invalid(DATABASE); |
| 138 | + } |
| 139 | + } |
| 140 | + |
98 | 141 | private void checkTableMetrics( |
99 | 142 | final IMetricSet metric, |
100 | 143 | final Consumer<String> bindTableMetrics, |
@@ -130,4 +173,16 @@ private IMetric findTableGauge() { |
130 | 173 | } |
131 | 174 | return null; |
132 | 175 | } |
| 176 | + |
| 177 | + private AutoGauge getSchemaRegionGauge(final String name, final int schemaRegionId) { |
| 178 | + for (final Map.Entry<MetricInfo, IMetric> entry : service.getAllMetrics().entrySet()) { |
| 179 | + if (name.equals(entry.getKey().getTags().get(Tag.NAME.toString())) |
| 180 | + && ("SchemaRegion[" + schemaRegionId + "]") |
| 181 | + .equals(entry.getKey().getTags().get(Tag.REGION.toString()))) { |
| 182 | + return (AutoGauge) entry.getValue(); |
| 183 | + } |
| 184 | + } |
| 185 | + throw new AssertionError( |
| 186 | + "Gauge " + name + " for SchemaRegion[" + schemaRegionId + "] is missing"); |
| 187 | + } |
133 | 188 | } |
0 commit comments