|
17 | 17 | package com.google.cloud.spanner;
|
18 | 18 |
|
19 | 19 | import static com.google.cloud.spanner.MetricRegistryConstants.GET_SESSION_TIMEOUTS;
|
| 20 | +import static com.google.cloud.spanner.MetricRegistryConstants.IS_MULTIPLEXED_KEY; |
20 | 21 | import static com.google.cloud.spanner.MetricRegistryConstants.MAX_ALLOWED_SESSIONS;
|
21 | 22 | import static com.google.cloud.spanner.MetricRegistryConstants.MAX_IN_USE_SESSIONS;
|
22 | 23 | import static com.google.cloud.spanner.MetricRegistryConstants.METRIC_PREFIX;
|
|
31 | 32 | import static com.google.cloud.spanner.MetricRegistryConstants.NUM_WRITE_SESSIONS;
|
32 | 33 | import static com.google.cloud.spanner.MetricRegistryConstants.SPANNER_DEFAULT_LABEL_VALUES;
|
33 | 34 | import static com.google.cloud.spanner.MetricRegistryConstants.SPANNER_LABEL_KEYS;
|
| 35 | +import static com.google.cloud.spanner.MetricRegistryConstants.SPANNER_LABEL_KEYS_WITH_MULTIPLEXED_SESSIONS; |
34 | 36 | import static com.google.cloud.spanner.MetricRegistryConstants.SPANNER_LABEL_KEYS_WITH_TYPE;
|
35 | 37 | import static com.google.cloud.spanner.SpannerOptionsTest.runWithSystemProperty;
|
36 | 38 | import static com.google.common.truth.Truth.assertThat;
|
@@ -1769,19 +1771,70 @@ public void testOpenCensusSessionMetrics() throws Exception {
|
1769 | 1771 | assertThat(getSessionsTimeouts.get(0).keys()).isEqualTo(SPANNER_LABEL_KEYS);
|
1770 | 1772 | assertThat(getSessionsTimeouts.get(0).values()).isEqualTo(labelValues);
|
1771 | 1773 |
|
| 1774 | + List<LabelValue> labelValuesWithRegularSessions = new ArrayList<>(labelValues); |
| 1775 | + labelValuesWithRegularSessions.add(LabelValue.create("false")); |
| 1776 | + List<LabelValue> labelValuesWithMultiplexedSessions = new ArrayList<>(labelValues); |
| 1777 | + labelValuesWithMultiplexedSessions.add(LabelValue.create("true")); |
1772 | 1778 | List<PointWithFunction> numAcquiredSessions =
|
1773 | 1779 | record.getMetrics().get(METRIC_PREFIX + NUM_ACQUIRED_SESSIONS);
|
1774 |
| - assertThat(numAcquiredSessions.size()).isEqualTo(1); |
1775 |
| - assertThat(numAcquiredSessions.get(0).value()).isEqualTo(2L); |
1776 |
| - assertThat(numAcquiredSessions.get(0).keys()).isEqualTo(SPANNER_LABEL_KEYS); |
1777 |
| - assertThat(numAcquiredSessions.get(0).values()).isEqualTo(labelValues); |
| 1780 | + assertThat(numAcquiredSessions.size()).isEqualTo(2); |
| 1781 | + PointWithFunction regularSessionMetric = |
| 1782 | + numAcquiredSessions.stream() |
| 1783 | + .filter( |
| 1784 | + x -> |
| 1785 | + x.keys().contains(IS_MULTIPLEXED_KEY) |
| 1786 | + && x.values().contains(LabelValue.create("false"))) |
| 1787 | + .findFirst() |
| 1788 | + .get(); |
| 1789 | + PointWithFunction multiplexedSessionMetric = |
| 1790 | + numAcquiredSessions.stream() |
| 1791 | + .filter( |
| 1792 | + x -> |
| 1793 | + x.keys().contains(IS_MULTIPLEXED_KEY) |
| 1794 | + && x.values().contains(LabelValue.create("true"))) |
| 1795 | + .findFirst() |
| 1796 | + .get(); |
| 1797 | + // verify metrics for regular sessions |
| 1798 | + assertThat(regularSessionMetric.value()).isEqualTo(2L); |
| 1799 | + assertThat(regularSessionMetric.keys()).isEqualTo(SPANNER_LABEL_KEYS_WITH_MULTIPLEXED_SESSIONS); |
| 1800 | + assertThat(regularSessionMetric.values()).isEqualTo(labelValuesWithRegularSessions); |
| 1801 | + |
| 1802 | + // verify metrics for multiplexed sessions |
| 1803 | + assertThat(multiplexedSessionMetric.value()).isEqualTo(0L); |
| 1804 | + assertThat(multiplexedSessionMetric.keys()) |
| 1805 | + .isEqualTo(SPANNER_LABEL_KEYS_WITH_MULTIPLEXED_SESSIONS); |
| 1806 | + assertThat(multiplexedSessionMetric.values()).isEqualTo(labelValuesWithMultiplexedSessions); |
1778 | 1807 |
|
1779 | 1808 | List<PointWithFunction> numReleasedSessions =
|
1780 | 1809 | record.getMetrics().get(METRIC_PREFIX + NUM_RELEASED_SESSIONS);
|
1781 |
| - assertThat(numReleasedSessions.size()).isEqualTo(1); |
1782 |
| - assertThat(numReleasedSessions.get(0).value()).isEqualTo(0); |
1783 |
| - assertThat(numReleasedSessions.get(0).keys()).isEqualTo(SPANNER_LABEL_KEYS); |
1784 |
| - assertThat(numReleasedSessions.get(0).values()).isEqualTo(labelValues); |
| 1810 | + assertThat(numReleasedSessions.size()).isEqualTo(2); |
| 1811 | + |
| 1812 | + regularSessionMetric = |
| 1813 | + numReleasedSessions.stream() |
| 1814 | + .filter( |
| 1815 | + x -> |
| 1816 | + x.keys().contains(IS_MULTIPLEXED_KEY) |
| 1817 | + && x.values().contains(LabelValue.create("false"))) |
| 1818 | + .findFirst() |
| 1819 | + .get(); |
| 1820 | + multiplexedSessionMetric = |
| 1821 | + numReleasedSessions.stream() |
| 1822 | + .filter( |
| 1823 | + x -> |
| 1824 | + x.keys().contains(IS_MULTIPLEXED_KEY) |
| 1825 | + && x.values().contains(LabelValue.create("true"))) |
| 1826 | + .findFirst() |
| 1827 | + .get(); |
| 1828 | + // verify metrics for regular sessions |
| 1829 | + assertThat(regularSessionMetric.value()).isEqualTo(0L); |
| 1830 | + assertThat(regularSessionMetric.keys()).isEqualTo(SPANNER_LABEL_KEYS_WITH_MULTIPLEXED_SESSIONS); |
| 1831 | + assertThat(regularSessionMetric.values()).isEqualTo(labelValuesWithRegularSessions); |
| 1832 | + |
| 1833 | + // verify metrics for multiplexed sessions |
| 1834 | + assertThat(multiplexedSessionMetric.value()).isEqualTo(0L); |
| 1835 | + assertThat(multiplexedSessionMetric.keys()) |
| 1836 | + .isEqualTo(SPANNER_LABEL_KEYS_WITH_MULTIPLEXED_SESSIONS); |
| 1837 | + assertThat(multiplexedSessionMetric.values()).isEqualTo(labelValuesWithMultiplexedSessions); |
1785 | 1838 |
|
1786 | 1839 | List<PointWithFunction> maxAllowedSessions =
|
1787 | 1840 | record.getMetrics().get(METRIC_PREFIX + MAX_ALLOWED_SESSIONS);
|
@@ -1847,12 +1900,46 @@ public void testOpenCensusSessionMetrics() throws Exception {
|
1847 | 1900 |
|
1848 | 1901 | session1.close();
|
1849 | 1902 | numAcquiredSessions = record.getMetrics().get(METRIC_PREFIX + NUM_ACQUIRED_SESSIONS);
|
1850 |
| - assertThat(numAcquiredSessions.size()).isEqualTo(1); |
1851 |
| - assertThat(numAcquiredSessions.get(0).value()).isEqualTo(3L); |
| 1903 | + assertThat(numAcquiredSessions.size()).isEqualTo(2); |
| 1904 | + regularSessionMetric = |
| 1905 | + numAcquiredSessions.stream() |
| 1906 | + .filter( |
| 1907 | + x -> |
| 1908 | + x.keys().contains(IS_MULTIPLEXED_KEY) |
| 1909 | + && x.values().contains(LabelValue.create("false"))) |
| 1910 | + .findFirst() |
| 1911 | + .get(); |
| 1912 | + multiplexedSessionMetric = |
| 1913 | + numAcquiredSessions.stream() |
| 1914 | + .filter( |
| 1915 | + x -> |
| 1916 | + x.keys().contains(IS_MULTIPLEXED_KEY) |
| 1917 | + && x.values().contains(LabelValue.create("true"))) |
| 1918 | + .findFirst() |
| 1919 | + .get(); |
| 1920 | + assertThat(regularSessionMetric.value()).isEqualTo(3L); |
| 1921 | + assertThat(multiplexedSessionMetric.value()).isEqualTo(0L); |
1852 | 1922 |
|
1853 | 1923 | numReleasedSessions = record.getMetrics().get(METRIC_PREFIX + NUM_RELEASED_SESSIONS);
|
1854 |
| - assertThat(numReleasedSessions.size()).isEqualTo(1); |
1855 |
| - assertThat(numReleasedSessions.get(0).value()).isEqualTo(3L); |
| 1924 | + assertThat(numReleasedSessions.size()).isEqualTo(2); |
| 1925 | + regularSessionMetric = |
| 1926 | + numReleasedSessions.stream() |
| 1927 | + .filter( |
| 1928 | + x -> |
| 1929 | + x.keys().contains(IS_MULTIPLEXED_KEY) |
| 1930 | + && x.values().contains(LabelValue.create("false"))) |
| 1931 | + .findFirst() |
| 1932 | + .get(); |
| 1933 | + multiplexedSessionMetric = |
| 1934 | + numReleasedSessions.stream() |
| 1935 | + .filter( |
| 1936 | + x -> |
| 1937 | + x.keys().contains(IS_MULTIPLEXED_KEY) |
| 1938 | + && x.values().contains(LabelValue.create("true"))) |
| 1939 | + .findFirst() |
| 1940 | + .get(); |
| 1941 | + assertThat(regularSessionMetric.value()).isEqualTo(3L); |
| 1942 | + assertThat(multiplexedSessionMetric.value()).isEqualTo(0L); |
1856 | 1943 |
|
1857 | 1944 | maxInUseSessions = record.getMetrics().get(METRIC_PREFIX + MAX_IN_USE_SESSIONS);
|
1858 | 1945 | assertThat(maxInUseSessions.size()).isEqualTo(1);
|
|
0 commit comments