Skip to content

Commit

Permalink
Merge branch 'caraml-dev:main' into update_ui_dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
deadlycoconuts committed Sep 13, 2022
2 parents 6431813 + 2728e18 commit 6575502
Show file tree
Hide file tree
Showing 31 changed files with 355 additions and 1,796 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/plugins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
go-version: ${{ env.GO_VERSION }}

- name: Run Plugins test
run: make test-plugin
run: make test

release-rules:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ifeq ($(UNAME_S),Darwin)
endif

PB_URL="https://github.com/protocolbuffers/protobuf/releases"
PB_VERSION=3.15.8
PB_VERSION=3.19.4
PROTOC_VERSION=1.5.2
protoc_dir=${PWD}/.protoc

Expand Down
2 changes: 1 addition & 1 deletion clients/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/caraml-dev/xp/clients
go 1.18

require (
github.com/deepmap/oapi-codegen v1.8.2
github.com/caraml-dev/xp/common v0.0.0
github.com/deepmap/oapi-codegen v1.8.2
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.7.0
)
Expand Down
851 changes: 2 additions & 849 deletions clients/go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion common/pubsub/experiment.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion common/pubsub/message.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion common/pubsub/settings.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

365 changes: 183 additions & 182 deletions common/segmenters/segmenters.pb.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion management-service/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ require (
bou.ke/monkey v1.0.2
cloud.google.com/go/pubsub v1.3.1
github.com/Masterminds/sprig/v3 v3.2.2
github.com/caraml-dev/xp/common v0.0.0
github.com/deepmap/oapi-codegen v1.8.2
github.com/getkin/kin-openapi v0.75.0
github.com/go-chi/chi/v5 v5.0.3
github.com/go-playground/validator/v10 v10.9.0
github.com/gojek/mlp v1.4.9
github.com/caraml-dev/xp/common v0.0.0
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3
github.com/golang-migrate/migrate/v4 v4.14.1
github.com/golang/geo v0.0.0-20210211234256-740aa86cb551
Expand Down
1 change: 1 addition & 0 deletions plugins/turing/.golangci.yml
8 changes: 6 additions & 2 deletions plugins/turing/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ vendor:
# Code dependencies recipes
# ==================================

tidy-plugin:
tidy:
go mod tidy

lint:
@echo "Linting Turing Plugin Code..."
golangci-lint run

# ==================================
# Build recipes
# ==================================
Expand All @@ -38,7 +42,7 @@ build-image: vendor version
# Test recipes
# ==================================

test-plugin: tidy-plugin vendor
test: tidy vendor
@echo "> Running Turing Experiment Engine XP Plugin tests ..."
# Set -gcflags=-l to disable inlining for the tests, to have Monkey patching work reliably
go test -v ./... -coverpkg ./... -gcflags=-l -race -coverprofile cover.out.tmp -tags unit,integration
Expand Down
59 changes: 37 additions & 22 deletions plugins/turing/config/config.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
package config

import (
"fmt"
"sync"

"github.com/caraml-dev/turing/engines/experiment/pkg/request"
"github.com/go-playground/validator/v10"
)

// RequestParameter captures a single parameter's config for parsing the incoming
// request and extracting values
type RequestParameter struct {
// Parameter specifies the name of the parameter, expected by the XP API
Parameter string `json:"parameter" validate:"required"`
// Field specifies the name of the field in the incoming request header/payload
Field string `json:"field" validate:"required"`
// FieldSrc specifies whether the field is located in the request header or payload
FieldSrc request.FieldSource `json:"field_source" validate:"required,oneof=header payload"`
}
type FieldSource string

const (
// PayloadFieldSource is used to represent the request payload
PayloadFieldSource FieldSource = "payload"
// HeaderFieldSource is used to represent the request header
HeaderFieldSource FieldSource = "header"
// NoneFieldSource is used to represent that there is no field source,
// i.e., the variable has not been configured.
NoneFieldSource FieldSource = "none"
)

type RunnerDefaults struct {
Endpoint string `json:"endpoint"` // API host for the experiment runner
Expand All @@ -39,17 +40,17 @@ type ExperimentManagerConfig struct {

// ExperimentRunnerConfig is used to parse the XP runner config during initialization
type ExperimentRunnerConfig struct {
Endpoint string `json:"endpoint" validate:"required"`
ProjectID int `json:"project_id" validate:"required"`
Passkey string `json:"passkey" validate:"required"`
Timeout string `json:"timeout" validate:"required"`
RequestParameters []RequestParameter `json:"request_parameters" validate:"required,dive"`
Endpoint string `json:"endpoint" validate:"required"`
ProjectID int `json:"project_id" validate:"required"`
Passkey string `json:"passkey" validate:"required"`
Timeout string `json:"timeout" validate:"required"`
RequestParameters []Variable `json:"request_parameters" validate:"required,dive"`
}

type Variable struct {
Name string `json:"name" validate:"required"`
Field string `json:"field" validate:"required"`
FieldSource request.FieldSource `json:"field_source" validate:"required,oneof=header payload"`
Name string `json:"name" validate:"required"`
Field string `json:"field"`
FieldSource FieldSource `json:"field_source" validate:"required,oneof=none header payload"`
}

// ExperimentConfig is the experiment config saved on the Turing DB
Expand All @@ -60,6 +61,16 @@ type ExperimentConfig struct {
Variables []Variable `json:"variables" validate:"dive"`
}

// Custom validation for the Variable struct
func validateVariable(sl validator.StructLevel) {
field := sl.Current().Interface().(Variable)
if field.FieldSource == NoneFieldSource && field.Field != "" {
sl.ReportError(field.Field, "Field", "name", "Value must not be set if FieldSource is none", "")
} else if (field.FieldSource == HeaderFieldSource || field.FieldSource == PayloadFieldSource) && field.Field == "" {
sl.ReportError(field.Field, "Field", "name", "Value must be set if FieldSource is not none", fmt.Sprintf("%v", field.Field))
}
}

// Validate validates the fields in the ExperimentRunnerConfig for expected values
// and returns any errors
func (cfg *ExperimentRunnerConfig) Validate() error {
Expand All @@ -73,10 +84,14 @@ var expTreatmentValidatorOnce sync.Once

func newExperimentRunnerConfigValidator() *validator.Validate {
expTreatmentValidatorOnce.Do(func() {
v := validator.New()
// Save the validator to the global state
experimentRunnerConfigValidator = v
experimentRunnerConfigValidator = NewValidator()
})

return experimentRunnerConfigValidator
}

func NewValidator() *validator.Validate {
v := validator.New()
v.RegisterStructValidation(validateVariable, Variable{})
return v
}
Loading

0 comments on commit 6575502

Please sign in to comment.