Fix missing values in context created with common.BackgroundContext (#950)

* Fix missing values in context when created through common.BackgroundContext

* pin to mysql 5.7.22
This commit is contained in:
Dario Domizioli
2018-04-20 17:29:27 +01:00
committed by Owen Cliffe
parent 07388774db
commit 0a72cb3ef4
4 changed files with 31 additions and 23 deletions

View File

@@ -2,10 +2,9 @@ package common
import ( import (
"context" "context"
"time"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"go.opencensus.io/tag"
"go.opencensus.io/trace"
) )
type contextKey string type contextKey string
@@ -34,25 +33,34 @@ func LoggerWithFields(ctx context.Context, fields logrus.Fields) (context.Contex
return ctx, l return ctx, l
} }
// contextWithNoDeadline is an implementation of context.Context which delegates
// Value() to its parent, but it has no deadline and it is never cancelled, just
// like a context.Background().
type contextWithNoDeadline struct {
original context.Context
}
func (ctx *contextWithNoDeadline) Deadline() (deadline time.Time, ok bool) {
return context.Background().Deadline()
}
func (ctx *contextWithNoDeadline) Done() <-chan struct{} {
return context.Background().Done()
}
func (ctx *contextWithNoDeadline) Err() error {
return context.Background().Err()
}
func (ctx *contextWithNoDeadline) Value(key interface{}) interface{} {
return ctx.original.Value(key)
}
// BackgroundContext returns a context that is specifically not a child of the // BackgroundContext returns a context that is specifically not a child of the
// provided parent context wrt any cancellation or deadline of the parent, // provided parent context wrt any cancellation or deadline of the parent,
// returning a context that contains all values only. At present, this is a // so that it contains all values only.
// best effort as there is not a great way to extract all values, known values:
// * logger
// * span
// * tags
// (TODO(reed): we could have our own context.Context implementer that stores
// all values from WithValue in a bucket we could extract more easily?)
func BackgroundContext(ctx context.Context) context.Context { func BackgroundContext(ctx context.Context) context.Context {
logger := Logger(ctx) return &contextWithNoDeadline{
span := trace.FromContext(ctx) original: ctx,
tagMap := tag.FromContext(ctx) }
// fresh context
ctx = context.Background()
ctx = tag.NewContext(ctx, tagMap)
ctx = trace.WithSpan(ctx, span)
ctx = WithLogger(ctx, logger)
return ctx
} }

View File

@@ -15,7 +15,7 @@ case "$1" in
"mysql" ) "mysql" )
DB_CONTAINER="func-mysql-test" DB_CONTAINER="func-mysql-test"
docker rm -fv ${DB_CONTAINER} || echo No prev mysql test db container docker rm -fv ${DB_CONTAINER} || echo No prev mysql test db container
docker run --name ${DB_CONTAINER} -p 3306:3306 -e MYSQL_DATABASE=funcs -e MYSQL_ROOT_PASSWORD=root -d mysql docker run --name ${DB_CONTAINER} -p 3306:3306 -e MYSQL_DATABASE=funcs -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7.22
MYSQL_HOST=`host ${DB_CONTAINER}` MYSQL_HOST=`host ${DB_CONTAINER}`
MYSQL_PORT=3306 MYSQL_PORT=3306
export FN_DB_URL="mysql://root:root@tcp(${MYSQL_HOST}:${MYSQL_PORT})/funcs" export FN_DB_URL="mysql://root:root@tcp(${MYSQL_HOST}:${MYSQL_PORT})/funcs"

View File

@@ -20,7 +20,7 @@ case "$1" in
"mysql" ) "mysql" )
DB_CONTAINER="func-mysql-system-test" DB_CONTAINER="func-mysql-system-test"
docker rm -fv ${DB_CONTAINER} || echo No prev mysql test db container docker rm -fv ${DB_CONTAINER} || echo No prev mysql test db container
docker run --name ${DB_CONTAINER} -p 3307:3306 -e MYSQL_DATABASE=funcs -e MYSQL_ROOT_PASSWORD=root -d mysql docker run --name ${DB_CONTAINER} -p 3307:3306 -e MYSQL_DATABASE=funcs -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7.22
MYSQL_HOST=`host ${DB_CONTAINER}` MYSQL_HOST=`host ${DB_CONTAINER}`
MYSQL_PORT=3307 MYSQL_PORT=3307
export FN_DB_URL="mysql://root:root@tcp(${MYSQL_HOST}:${MYSQL_PORT})/funcs" export FN_DB_URL="mysql://root:root@tcp(${MYSQL_HOST}:${MYSQL_PORT})/funcs"

View File

@@ -8,7 +8,7 @@ source ./helpers.sh
remove_containers remove_containers
docker run --name func-postgres-test -e "POSTGRES_DB=funcs" -e "POSTGRES_PASSWORD=root" -p 5432:5432 -d postgres:9.3-alpine docker run --name func-postgres-test -e "POSTGRES_DB=funcs" -e "POSTGRES_PASSWORD=root" -p 5432:5432 -d postgres:9.3-alpine
docker run --name func-mysql-test -p 3306:3306 -e MYSQL_DATABASE=funcs -e MYSQL_ROOT_PASSWORD=root -d mysql docker run --name func-mysql-test -p 3306:3306 -e MYSQL_DATABASE=funcs -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7.22
docker run -d -p 9000:9000 --name func-minio-test -e "MINIO_ACCESS_KEY=admin" -e "MINIO_SECRET_KEY=password" minio/minio server /data docker run -d -p 9000:9000 --name func-minio-test -e "MINIO_ACCESS_KEY=admin" -e "MINIO_SECRET_KEY=password" minio/minio server /data
MYSQL_HOST=`host func-mysql-test` MYSQL_HOST=`host func-mysql-test`