Skip to content

Commit

Permalink
chore: Update API for korrel8r 0.7.3.
Browse files Browse the repository at this point in the history
  • Loading branch information
alanconway committed Nov 6, 2024
1 parent d4690d9 commit 01c298e
Show file tree
Hide file tree
Showing 13 changed files with 512 additions and 37 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/tmp/
/korrel8rcli
_covdata/
_korrel8rcli
bin
15 changes: 8 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@

all: lint test build

VERSION=0.0.3
VERSION=0.0.4

include .bingo/Variables.mk

VERSION_TXT=pkg/build/version.txt
SWAGGER_SPEC=swagger.json
SWAGGER_CLIENT=pkg/swagger
KORREL8RCLI=./korrel8rcli

lint: $(SWAGGER_CLIENT) $(GOLANGCI_LINT)
lint: $(VERSION_TXT) $(SWAGGER_CLIENT) $(GOLANGCI_LINT)
go mod tidy
$(GOLANGCI_LINT) run ./...
@if grep -q github.com/korrel8r/korrel8r go.mod; then \
echo "ERROR: bad dependency: remove 'github.com/korrel8r/korrel8r' from go.mod"; \
exit 1; \
fi

build: $(KORREL8RCLI)
$(KORREL8RCLI): $(VERSION_TXT) $(SWAGGER_CLIENT)
go build -o $@ ./cmd/korrel8rcli
build: lint
go build ./cmd/korrel8rcli

install: lint
go install ./cmd/korrel8rcli

test:
go test -cover -race ./...
go tool covdata percent -i pkg/cmd/_covdata

clean:
rm -rfv $(SWAGGER_CLIENT) $(SWAGGER_SPEC) $(KORREL8RCLI)
rm -rfv $(SWAGGER_CLIENT) $(SWAGGER_SPEC)
git clean -dfx

run:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ require (
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/loads v0.22.0 // indirect
github.com/go-openapi/spec v0.21.0 // indirect
github.com/go-openapi/validate v0.24.0 // indirect
github.com/go-openapi/validate v0.24.0
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.20.0 // indirect
Expand Down
2 changes: 1 addition & 1 deletion pkg/build/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.3
0.0.4
8 changes: 4 additions & 4 deletions pkg/cmd/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ func Test_domains(t *testing.T) {
require.NoError(t, err)

var domains []*models.Domain
require.NoError(t, yaml.Unmarshal([]byte(out), &domains), out)
require.NoError(t, yaml.Unmarshal([]byte(out), &domains), out, string(out))
var names []string
for _, d := range domains {
names = append(names, d.Name)
}
require.ElementsMatch(t, []string{"k8s", "alert", "log", "metric", "netflow", "mock"}, names)
require.ElementsMatch(t, []string{"k8s", "alert", "log", "metric", "netflow", "mock", "trace"}, names)
}

func Test_bad_parameters(t *testing.T) {
u := korrel8rServer(t)
out, err := korrel8rcli(t, "objects", "-u", u.String(), "this-is-not-a-query")
require.EqualError(t, err, "exit status 1: stderr: invalid query string: this-is-not-a-query\n")
require.Equal(t, "", out)
require.Equal(t, "", out)
}

var buildOnce sync.Once
Expand Down Expand Up @@ -65,7 +65,7 @@ func korrel8rcli(t *testing.T, args ...string) (out string, err error) {
}

// Start a korrel8r server, will shut down at end of test.
func korrel8r(t *testing.T, args ...string) *url.URL {
func korrel8r(t *testing.T) *url.URL {
t.Helper()
l, err := net.Listen("tcp", ":0")
require.NoError(t, err)
Expand Down
42 changes: 33 additions & 9 deletions pkg/cmd/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package cmd

import (
"errors"
"os"

"github.com/korrel8r/client/pkg/swagger/client/operations"
Expand Down Expand Up @@ -35,14 +36,13 @@ var domainsCmd = &cobra.Command{
c := newClient()
ok, err := c.Operations.GetDomains(&operations.GetDomainsParams{})
check(err)
p := NewPrinter(output.String(), os.Stdout)
for _, v := range ok.Payload {
p(v)
}
NewPrinter(output.String(), os.Stdout)(ok.Payload)
},
}

func init() { rootCmd.AddCommand(domainsCmd) }
func init() {
rootCmd.AddCommand(domainsCmd)
}

var (
objectsCmd = &cobra.Command{
Expand All @@ -53,10 +53,7 @@ var (
c := newClient()
ok, err := c.Operations.GetObjects(&operations.GetObjectsParams{Query: args[0]})
check(err)
p := NewPrinter(output.String(), os.Stdout)
for _, v := range ok.Payload {
p(v)
}
NewPrinter(output.String(), os.Stdout)(ok.Payload)
},
}
)
Expand Down Expand Up @@ -114,3 +111,30 @@ func init() {
neighboursCmd.Flags().Int64Var(&depth, "depth", 2, "Depth of neighbourhood search.")
commonFlags(goalsCmd)
}

var (
configVerbose *int64
configCmd = &cobra.Command{
Use: "config",
Short: "Change configuration settings on the server",
Run: func(cmd *cobra.Command, args []string) {
config := &operations.PutConfigParams{}
changes := false
if cmd.Flags().Changed("set-verbose") {
changes = true
config.Verbose = configVerbose
}
if !changes {
check(errors.New("No changes requested"))
}
c := newClient()
_, err := c.Operations.PutConfig(config)
check(err)
},
}
)

func init() {
configVerbose = configCmd.Flags().Int64("set-verbose", 0, "Set verbose level for logging")
rootCmd.AddCommand(configCmd)
}
39 changes: 39 additions & 0 deletions pkg/swagger/client/operations/operations_client.go

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

164 changes: 164 additions & 0 deletions pkg/swagger/client/operations/put_config_parameters.go

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

Loading

0 comments on commit 01c298e

Please sign in to comment.