18
18
19
19
import static com .google .cloud .spanner .MetricRegistryConstants .COUNT ;
20
20
import static com .google .cloud .spanner .MetricRegistryConstants .GET_SESSION_TIMEOUTS ;
21
- import static com .google .cloud .spanner .MetricRegistryConstants .IN_USE_SESSIONS ;
22
- import static com .google .cloud .spanner .MetricRegistryConstants .IN_USE_SESSIONS_DESCRIPTION ;
23
21
import static com .google .cloud .spanner .MetricRegistryConstants .MAX_ALLOWED_SESSIONS ;
24
22
import static com .google .cloud .spanner .MetricRegistryConstants .MAX_ALLOWED_SESSIONS_DESCRIPTION ;
25
23
import static com .google .cloud .spanner .MetricRegistryConstants .MAX_IN_USE_SESSIONS ;
26
24
import static com .google .cloud .spanner .MetricRegistryConstants .MAX_IN_USE_SESSIONS_DESCRIPTION ;
27
25
import static com .google .cloud .spanner .MetricRegistryConstants .NUM_ACQUIRED_SESSIONS ;
28
26
import static com .google .cloud .spanner .MetricRegistryConstants .NUM_ACQUIRED_SESSIONS_DESCRIPTION ;
27
+ import static com .google .cloud .spanner .MetricRegistryConstants .NUM_IN_USE_SESSIONS ;
28
+ import static com .google .cloud .spanner .MetricRegistryConstants .NUM_READ_SESSIONS ;
29
29
import static com .google .cloud .spanner .MetricRegistryConstants .NUM_RELEASED_SESSIONS ;
30
30
import static com .google .cloud .spanner .MetricRegistryConstants .NUM_RELEASED_SESSIONS_DESCRIPTION ;
31
+ import static com .google .cloud .spanner .MetricRegistryConstants .NUM_SESSIONS_BEING_PREPARED ;
32
+ import static com .google .cloud .spanner .MetricRegistryConstants .NUM_SESSIONS_IN_POOL ;
33
+ import static com .google .cloud .spanner .MetricRegistryConstants .NUM_SESSIONS_IN_POOL_DESCRIPTION ;
34
+ import static com .google .cloud .spanner .MetricRegistryConstants .NUM_WRITE_SESSIONS ;
31
35
import static com .google .cloud .spanner .MetricRegistryConstants .SESSIONS_TIMEOUTS_DESCRIPTION ;
32
36
import static com .google .cloud .spanner .MetricRegistryConstants .SPANNER_DEFAULT_LABEL_VALUES ;
33
37
import static com .google .cloud .spanner .MetricRegistryConstants .SPANNER_LABEL_KEYS ;
38
+ import static com .google .cloud .spanner .MetricRegistryConstants .SPANNER_LABEL_KEYS_WITH_TYPE ;
34
39
import static com .google .cloud .spanner .SpannerExceptionFactory .newSpannerException ;
35
40
36
41
import com .google .api .core .ApiFuture ;
71
76
import io .opencensus .trace .Status ;
72
77
import io .opencensus .trace .Tracer ;
73
78
import io .opencensus .trace .Tracing ;
79
+ import java .util .ArrayList ;
74
80
import java .util .Arrays ;
75
81
import java .util .HashSet ;
76
82
import java .util .Iterator ;
@@ -2030,15 +2036,6 @@ private void initMetricsCollection(MetricRegistry metricRegistry, List<LabelValu
2030
2036
.setLabelKeys (SPANNER_LABEL_KEYS )
2031
2037
.build ());
2032
2038
2033
- DerivedLongGauge numInUseSessionsMetric =
2034
- metricRegistry .addDerivedLongGauge (
2035
- IN_USE_SESSIONS ,
2036
- MetricOptions .builder ()
2037
- .setDescription (IN_USE_SESSIONS_DESCRIPTION )
2038
- .setUnit (COUNT )
2039
- .setLabelKeys (SPANNER_LABEL_KEYS )
2040
- .build ());
2041
-
2042
2039
DerivedLongCumulative sessionsTimeouts =
2043
2040
metricRegistry .addDerivedLongCumulative (
2044
2041
GET_SESSION_TIMEOUTS ,
@@ -2066,6 +2063,15 @@ private void initMetricsCollection(MetricRegistry metricRegistry, List<LabelValu
2066
2063
.setLabelKeys (SPANNER_LABEL_KEYS )
2067
2064
.build ());
2068
2065
2066
+ DerivedLongGauge numSessionsInPoolMetric =
2067
+ metricRegistry .addDerivedLongGauge (
2068
+ NUM_SESSIONS_IN_POOL ,
2069
+ MetricOptions .builder ()
2070
+ .setDescription (NUM_SESSIONS_IN_POOL_DESCRIPTION )
2071
+ .setUnit (COUNT )
2072
+ .setLabelKeys (SPANNER_LABEL_KEYS_WITH_TYPE )
2073
+ .build ());
2074
+
2069
2075
// The value of a maxSessionsInUse is observed from a callback function. This function is
2070
2076
// invoked whenever metrics are collected.
2071
2077
maxInUseSessionsMetric .createTimeSeries (
@@ -2090,18 +2096,6 @@ public long applyAsLong(SessionPoolOptions options) {
2090
2096
}
2091
2097
});
2092
2098
2093
- // The value of a numSessionsInUse is observed from a callback function. This function is
2094
- // invoked whenever metrics are collected.
2095
- numInUseSessionsMetric .createTimeSeries (
2096
- labelValues ,
2097
- this ,
2098
- new ToLongFunction <SessionPool >() {
2099
- @ Override
2100
- public long applyAsLong (SessionPool sessionPool ) {
2101
- return sessionPool .numSessionsInUse ;
2102
- }
2103
- });
2104
-
2105
2099
// The value of a numWaiterTimeouts is observed from a callback function. This function is
2106
2100
// invoked whenever metrics are collected.
2107
2101
sessionsTimeouts .createTimeSeries (
@@ -2133,5 +2127,53 @@ public long applyAsLong(SessionPool sessionPool) {
2133
2127
return sessionPool .numSessionsReleased ;
2134
2128
}
2135
2129
});
2130
+
2131
+ List <LabelValue > labelValuesWithBeingPreparedType = new ArrayList <>(labelValues );
2132
+ labelValuesWithBeingPreparedType .add (NUM_SESSIONS_BEING_PREPARED );
2133
+ numSessionsInPoolMetric .createTimeSeries (
2134
+ labelValuesWithBeingPreparedType ,
2135
+ this ,
2136
+ new ToLongFunction <SessionPool >() {
2137
+ @ Override
2138
+ public long applyAsLong (SessionPool sessionPool ) {
2139
+ return sessionPool .numSessionsBeingPrepared ;
2140
+ }
2141
+ });
2142
+
2143
+ List <LabelValue > labelValuesWithInUseType = new ArrayList <>(labelValues );
2144
+ labelValuesWithInUseType .add (NUM_IN_USE_SESSIONS );
2145
+ numSessionsInPoolMetric .createTimeSeries (
2146
+ labelValuesWithInUseType ,
2147
+ this ,
2148
+ new ToLongFunction <SessionPool >() {
2149
+ @ Override
2150
+ public long applyAsLong (SessionPool sessionPool ) {
2151
+ return sessionPool .numSessionsInUse ;
2152
+ }
2153
+ });
2154
+
2155
+ List <LabelValue > labelValuesWithReadType = new ArrayList <>(labelValues );
2156
+ labelValuesWithReadType .add (NUM_READ_SESSIONS );
2157
+ numSessionsInPoolMetric .createTimeSeries (
2158
+ labelValuesWithReadType ,
2159
+ this ,
2160
+ new ToLongFunction <SessionPool >() {
2161
+ @ Override
2162
+ public long applyAsLong (SessionPool sessionPool ) {
2163
+ return sessionPool .readSessions .size ();
2164
+ }
2165
+ });
2166
+
2167
+ List <LabelValue > labelValuesWithWriteType = new ArrayList <>(labelValues );
2168
+ labelValuesWithWriteType .add (NUM_WRITE_SESSIONS );
2169
+ numSessionsInPoolMetric .createTimeSeries (
2170
+ labelValuesWithWriteType ,
2171
+ this ,
2172
+ new ToLongFunction <SessionPool >() {
2173
+ @ Override
2174
+ public long applyAsLong (SessionPool sessionPool ) {
2175
+ return sessionPool .writePreparedSessions .size ();
2176
+ }
2177
+ });
2136
2178
}
2137
2179
}
0 commit comments