-
Notifications
You must be signed in to change notification settings - Fork 115
/
experiment_config.go
45 lines (38 loc) · 1.15 KB
/
experiment_config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package experimentstore
import (
"github.com/golang/protobuf/ptypes/any"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/anypb"
experimentationv1 "github.com/lyft/clutch/backend/api/chaos/experimentation/v1"
)
type ExperimentConfig struct {
Id string
// TODO(Augustyniak): Remove Config property once all of its existing usages are removed. Use Message property instead.
Config *any.Any
Message proto.Message
}
func NewExperimentConfig(id string, stringifedData string) (*ExperimentConfig, error) {
data := &any.Any{}
if err := protojson.Unmarshal([]byte(stringifedData), data); err != nil {
return nil, err
}
message, err := anypb.UnmarshalNew(data, proto.UnmarshalOptions{})
if err != nil {
return nil, err
}
return &ExperimentConfig{
Id: id,
Config: data,
Message: message,
}, nil
}
func (ec *ExperimentConfig) CreateProperties() ([]*experimentationv1.Property, error) {
return []*experimentationv1.Property{
{
Id: "config_identifier",
Label: "Config Identifier",
Value: &experimentationv1.Property_StringValue{StringValue: ec.Id},
},
}, nil
}