Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rahul2393 committed Jul 19, 2024
1 parent af5ec99 commit d7bb22a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 25 deletions.
5 changes: 1 addition & 4 deletions spanner/kokoro/presubmit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License..

# TODO(deklerk): Add integration tests when it's secure to do so. b/64723143

# Fail on any error
set -eo pipefail

Expand All @@ -30,7 +28,6 @@ export GOCLOUD_HOME=$KOKORO_ARTIFACTS_DIR/google-cloud-go/
export PATH="$GOPATH/bin:$PATH"
export GO111MODULE=on
export GOPROXY=https://proxy.golang.org

# Move code into artifacts dir
mkdir -p $GOCLOUD_HOME
git clone . $GOCLOUD_HOME
Expand All @@ -47,7 +44,7 @@ exit_code=0
case $JOB_TYPE in
integration-with-multiplexed-session )
GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS=true
echo "running presubmits with multiplexed sessions enbled: $GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS"
echo "running presubmit with multiplexed sessions enabled: $GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS"
;;
esac

Expand Down
7 changes: 4 additions & 3 deletions spanner/ot_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,11 @@ func registerSessionPoolOTMetrics(pool *sessionPool) error {

o.ObserveInt64(otConfig.openSessionCount, int64(pool.numOpened), metric.WithAttributes(attributes...))
o.ObserveInt64(otConfig.maxAllowedSessionsCount, int64(pool.SessionPoolConfig.MaxOpened), metric.WithAttributes(attributes...))
o.ObserveInt64(otConfig.sessionsCount, int64(pool.numInUse), metric.WithAttributes(attributesInUseSessions...))
o.ObserveInt64(otConfig.sessionsCount, int64(pool.numInUse), metric.WithAttributes(append(attributesInUseSessions, attribute.Key("is_multiplexed").String("false"))...))
o.ObserveInt64(otConfig.sessionsCount, int64(pool.multiplexedSessionInUse), metric.WithAttributes(append(attributesInUseSessions, attribute.Key("is_multiplexed").String("true"))...))
o.ObserveInt64(otConfig.sessionsCount, int64(pool.numSessions), metric.WithAttributes(attributesAvailableSessions...))
o.ObserveInt64(otConfig.maxInUseSessionsCount, int64(pool.maxNumInUse), metric.WithAttributes(attributes...))

o.ObserveInt64(otConfig.maxInUseSessionsCount, int64(pool.maxNumInUse), metric.WithAttributes(append(attributes, attribute.Key("is_multiplexed").String("false"))...))
o.ObserveInt64(otConfig.maxInUseSessionsCount, int64(pool.maxMultiplexedSessionInUse), metric.WithAttributes(append(attributes, attribute.Key("is_multiplexed").String("true"))...))
return nil
},
otConfig.openSessionCount,
Expand Down
20 changes: 7 additions & 13 deletions spanner/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -1312,14 +1312,14 @@ func (p *sessionPool) remove(s *session, isExpire bool, wasInUse bool) bool {
p.mu.Lock()
defer p.mu.Unlock()
if s.isMultiplexed {
p.multiplexedSession = nil
} else {
if isExpire && (p.numOpened <= p.MinOpened || s.getIdleList() == nil) {
// Don't expire session if the session is not in idle list (in use), or
// if number of open sessions is going below p.MinOpened.
return false
}
return false
}
if isExpire && (p.numOpened <= p.MinOpened || s.getIdleList() == nil) {
// Don't expire session if the session is not in idle list (in use), or
// if number of open sessions is going below p.MinOpened.
return false
}

ol := s.setIdleList(nil)
ctx := context.Background()
// If the session is in the idlelist, remove it.
Expand All @@ -1336,12 +1336,6 @@ func (p *sessionPool) remove(s *session, isExpire bool, wasInUse bool) bool {
p.decNumInUseLocked(ctx)
}
p.recordStat(ctx, OpenSessionCount, int64(p.numOpened))
// Broadcast that a session has been destroyed.
if s.isMultiplexed {
close(p.mayGetMultiplexedSession)
p.mayGetMultiplexedSession = make(chan struct{})
return true
}
close(p.mayGetSession)
p.mayGetSession = make(chan struct{})
return true
Expand Down
26 changes: 21 additions & 5 deletions spanner/test/opentelemetry/test/ot_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ func TestOTMetrics_SessionPool(t *testing.T) {
defer teardown()
client.Single().ReadRow(context.Background(), "Users", spanner.Key{"alice"}, []string{"email"})

expectedOpenSessionCount := int64(25)
expectedMaxInUseWithMultiplexed := int64(0)
expectedMaxInUse := int64(1)
if isMultiplexEnabled == "true" {
expectedOpenSessionCount = 0
expectedMaxInUse = 0
expectedMaxInUseWithMultiplexed = 1
}
for _, test := range []struct {
name string
expectedMetric metricdata.Metrics
Expand All @@ -87,7 +95,7 @@ func TestOTMetrics_SessionPool(t *testing.T) {
DataPoints: []metricdata.DataPoint[int64]{
{
Attributes: attribute.NewSet(getAttributes(client.ClientID())...),
Value: 25,
Value: expectedOpenSessionCount,
},
},
},
Expand Down Expand Up @@ -118,8 +126,12 @@ func TestOTMetrics_SessionPool(t *testing.T) {
Data: metricdata.Gauge[int64]{
DataPoints: []metricdata.DataPoint[int64]{
{
Attributes: attribute.NewSet(getAttributes(client.ClientID())...),
Value: 1,
Attributes: attribute.NewSet(append(getAttributes(client.ClientID()), attribute.Key("is_multiplexed").String("false"))...),
Value: expectedMaxInUse,
},
{
Attributes: attribute.NewSet(append(getAttributes(client.ClientID()), attribute.Key("is_multiplexed").String("true"))...),
Value: expectedMaxInUseWithMultiplexed,
},
},
},
Expand Down Expand Up @@ -192,7 +204,7 @@ func TestOTMetrics_SessionPool_SessionsCount(t *testing.T) {

client.Single().ReadRow(context.Background(), "Users", spanner.Key{"alice"}, []string{"email"})

attributesNumInUseSessions := append(getAttributes(client.ClientID()), attribute.Key("type").String("num_in_use_sessions"))
//attributesNumInUseSessions := append(getAttributes(client.ClientID()), attribute.Key("type").String("num_in_use_sessions"))
attributesNumSessions := append(getAttributes(client.ClientID()), attribute.Key("type").String("num_sessions"))

expectedMetricData := metricdata.Metrics{
Expand All @@ -202,7 +214,11 @@ func TestOTMetrics_SessionPool_SessionsCount(t *testing.T) {
Data: metricdata.Gauge[int64]{
DataPoints: []metricdata.DataPoint[int64]{
{
Attributes: attribute.NewSet(attributesNumInUseSessions...),
Attributes: attribute.NewSet(append(getAttributes(client.ClientID()), attribute.Key("type").String("num_in_use_sessions"), attribute.Key("is_multiplexed").String("true"))...),
Value: 0,
},
{
Attributes: attribute.NewSet(append(getAttributes(client.ClientID()), attribute.Key("type").String("num_in_use_sessions"), attribute.Key("is_multiplexed").String("false"))...),
Value: 0,
},
{
Expand Down

0 comments on commit d7bb22a

Please sign in to comment.