Skip to content

Commit

Permalink
fix order of fields when listing resources (#2474)
Browse files Browse the repository at this point in the history
* fix order of fields when listing resources

* fix tests

* adapt resource manager to replace mapstructure with yaml decoding

* patch polling profiles

* patch demos

* patch data stores

* patch config resource

* patch provisioner to use new yaml library and fix test data

* fix resource manager mocked tests
  • Loading branch information
mathnogueira authored and schoren committed May 9, 2023
1 parent 1b55c2b commit 88791b1
Show file tree
Hide file tree
Showing 13 changed files with 217 additions and 230 deletions.
75 changes: 5 additions & 70 deletions go.work.sum

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions server/config/configresource/config_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ var Operations = []resourcemanager.Operation{
}

type Config struct {
ID id.ID `mapstructure:"id"`
Name string `mapstructure:"name"`
ID id.ID `json:"id"`
Name string `json:"name"`

AnalyticsEnabled bool `mapstructure:"analyticsEnabled"`
AnalyticsEnabled bool `json:"analyticsEnabled"`
}

func (c Config) HasID() bool {
Expand Down
24 changes: 12 additions & 12 deletions server/config/demoresource/demo_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ var Operations = []resourcemanager.Operation{
}

type Demo struct {
ID id.ID `mapstructure:"id"`
Name string `mapstructure:"name"`
Type DemoType `mapstructure:"type"`
Enabled bool `mapstructure:"enabled"`
Pokeshop *PokeshopDemo `mapstructure:"pokeshop,omitempty"`
OpenTelemetryStore *OpenTelemetryStoreDemo `mapstructure:"opentelemetryStore,omitempty"`
ID id.ID `json:"id"`
Name string `json:"name"`
Type DemoType `json:"type"`
Enabled bool `json:"enabled"`
Pokeshop *PokeshopDemo `json:"pokeshop,omitempty"`
OpenTelemetryStore *OpenTelemetryStoreDemo `json:"opentelemetryStore,omitempty"`
}

func (d Demo) HasID() bool {
Expand All @@ -49,15 +49,15 @@ func (d Demo) Validate() error {
}

type PokeshopDemo struct {
HTTPEndpoint string `mapstructure:"httpEndpoint,omitempty"`
GRPCEndpoint string `mapstructure:"grpcEndpoint,omitempty"`
HTTPEndpoint string `json:"httpEndpoint,omitempty"`
GRPCEndpoint string `json:"grpcEndpoint,omitempty"`
}

type OpenTelemetryStoreDemo struct {
FrontendEndpoint string `mapstructure:"frontendEndpoint,omitempty"`
ProductCatalogEndpoint string `mapstructure:"productCatalogEndpoint,omitempty"`
CartEndpoint string `mapstructure:"cartEndpoint,omitempty"`
CheckoutEndpoint string `mapstructure:"checkoutEndpoint,omitempty"`
FrontendEndpoint string `json:"frontendEndpoint,omitempty"`
ProductCatalogEndpoint string `json:"productCatalogEndpoint,omitempty"`
CartEndpoint string `json:"cartEndpoint,omitempty"`
CheckoutEndpoint string `json:"checkoutEndpoint,omitempty"`
}

type Repository struct {
Expand Down
14 changes: 7 additions & 7 deletions server/environment/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ import (

type (
Environment struct {
ID id.ID `mapstructure:"id"`
Name string `mapstructure:"name"`
Description string `mapstructure:"description"`
CreatedAt string `mapstructure:"createdAt"`
Values []EnvironmentValue `mapstructure:"values"`
ID id.ID `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
CreatedAt string `json:"createdAt"`
Values []EnvironmentValue `json:"values"`
}

EnvironmentValue struct {
Key string `mapstructure:"key"`
Value string `mapstructure:"value"`
Key string `json:"key"`
Value string `json:"value"`
}
)

Expand Down
14 changes: 7 additions & 7 deletions server/executor/pollingprofile/polling_profile_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ var DefaultPollingProfile = PollingProfile{
}

type PollingProfile struct {
ID id.ID `mapstructure:"id"`
Name string `mapstructure:"name"`
Default bool `mapstructure:"default"`
Strategy Strategy `mapstructure:"strategy"`
Periodic *PeriodicPollingConfig `mapstructure:"periodic"`
ID id.ID `json:"id"`
Name string `json:"name"`
Default bool `json:"default"`
Strategy Strategy `json:"strategy"`
Periodic *PeriodicPollingConfig `json:"periodic"`
}

type PeriodicPollingConfig struct {
RetryDelay string `mapstructure:"retryDelay"`
Timeout string `mapstructure:"timeout"`
RetryDelay string `json:"retryDelay"`
Timeout string `json:"timeout"`
}

func (ppc *PeriodicPollingConfig) TimeoutDuration() time.Duration {
Expand Down
7 changes: 6 additions & 1 deletion server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,12 @@ require (
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/elastic/elastic-transport-go/v8 v8.0.0-20211216131617-bbee439d559c // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/felixge/httpsnoop v1.0.2 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-redis/redis/v7 v7.4.1 // indirect
github.com/goccy/go-yaml v1.11.0 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 // indirect
Expand All @@ -85,6 +87,8 @@ require (
github.com/klauspost/compress v1.15.6 // indirect
github.com/knadh/koanf v1.4.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/mostynb/go-grpc-compression v1.1.16 // indirect
Expand All @@ -109,8 +113,9 @@ require (
go.uber.org/zap v1.21.0 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/text v0.7.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/genproto v0.0.0-20221227171554-f9683d7f8bef // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
)
Expand Down
14 changes: 14 additions & 0 deletions server/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,8 @@ github.com/evanphx/json-patch v4.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLi
github.com/evanphx/json-patch v4.11.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/felixge/httpsnoop v1.0.2 h1:+nS9g82KMXccJ/wp0zyRW9ZBHFETmMGtkk+2CTTrW4o=
Expand Down Expand Up @@ -725,6 +727,8 @@ github.com/gobuffalo/packd v0.1.0/go.mod h1:M2Juc+hhDXf/PnmBANFCqx4DM3wRbgDvnVWe
github.com/gobuffalo/packr/v2 v2.0.9/go.mod h1:emmyGweYTm6Kdper+iywB6YK5YzuKchGtJQZ0Odn4pQ=
github.com/gobuffalo/packr/v2 v2.2.0/go.mod h1:CaAwI0GPIAv+5wKLtv8Afwl+Cm78K/I/VCm/3ptBN+0=
github.com/gobuffalo/syncx v0.0.0-20190224160051-33c29581e754/go.mod h1:HhnNqWY95UYwwW3uSASeV7vtgYkT2t16hJgV3AEPUpw=
github.com/goccy/go-yaml v1.11.0 h1:n7Z+zx8S9f9KgzG6KtQKf+kwqXZlLNR2F6018Dgau54=
github.com/goccy/go-yaml v1.11.0/go.mod h1:H+mJrWtjPTJAHvRbV09MCK9xYwODM+wRTVFFTWckfng=
github.com/gocql/gocql v0.0.0-20210515062232-b7ef815b4556/go.mod h1:DL0ekTmBSTdlNF25Orwt/JMzqIq3EJ4MVa/J/uK64OY=
github.com/godbus/dbus v0.0.0-20151105175453-c7fdd8b5cd55/go.mod h1:/YcGZj5zSblfDWMMoOzV4fas9FZnQYTkDnsGvmh2Grw=
github.com/godbus/dbus v0.0.0-20180201030542-885f9cc04c9c/go.mod h1:/YcGZj5zSblfDWMMoOzV4fas9FZnQYTkDnsGvmh2Grw=
Expand Down Expand Up @@ -1176,6 +1180,9 @@ github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVc
github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-ieproxy v0.0.1/go.mod h1:pYabZ6IHcRpFh7vIaLfK7rdcWgFEb3SFJ6/gNWuh88E=
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
Expand All @@ -1186,6 +1193,8 @@ github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2y
github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-shellwords v1.0.3/go.mod h1:3xCvwCdWdlDJUrvuMn7Wuy9eWs4pE8vqg+NOMyg4B2o=
Expand Down Expand Up @@ -2129,6 +2138,7 @@ golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20210903071746-97244b99971b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210906170528-6f6e22806c34/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210908233432-aa78b53d3365/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211116061358-0a5406a5449c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand All @@ -2143,6 +2153,8 @@ golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
Expand Down Expand Up @@ -2273,6 +2285,8 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk=
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8=
gonum.org/v1/gonum v0.0.0-20180816165407-929014505bf4/go.mod h1:Y+Yx5eoAFn32cQvJDxZx5Dpnq+c3wtXuadVZAcxbbBo=
gonum.org/v1/gonum v0.0.0-20181121035319-3f7ecaa7e8ca/go.mod h1:Y+Yx5eoAFn32cQvJDxZx5Dpnq+c3wtXuadVZAcxbbBo=
gonum.org/v1/gonum v0.6.0/go.mod h1:9mxDZsDKxgMAuccQkewq682L+0eCu4dCN2yonUJTCLU=
Expand Down
2 changes: 1 addition & 1 deletion server/provisioning/provisioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"io"
"os"

"github.com/goccy/go-yaml"
"github.com/kubeshop/tracetest/server/resourcemanager"
"gopkg.in/yaml.v2"
)

func WithResourceProvisioners(provs ...resourcemanager.Provisioner) option {
Expand Down
2 changes: 1 addition & 1 deletion server/provisioning/testdata/all_settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ spec:
type: otelstore
enabled: true
opentelemetryStore:
FrontendEndpoint: http://frontend:8080/
frontendEndpoint: http://frontend:8080/
3 changes: 2 additions & 1 deletion server/resourcemanager/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"fmt"
"net/http"

"gopkg.in/yaml.v2"
"github.com/goccy/go-yaml"
)

type encoder interface {
Expand Down Expand Up @@ -52,6 +52,7 @@ func (e basicEncoder) Accepts(contentType string) bool {
func (e basicEncoder) Marshal(in interface{}) (out []byte, err error) {
return e.marshalFn(in)
}

func (e basicEncoder) Unmarshal(in []byte, out interface{}) (err error) {
return e.unmarshalFn(in, out)
}
Expand Down
Loading

0 comments on commit 88791b1

Please sign in to comment.