diff --git a/cmd/meroxa/root/apps/logs.go b/cmd/meroxa/root/apps/logs.go index 3ae35b3e3..c82416f8f 100644 --- a/cmd/meroxa/root/apps/logs.go +++ b/cmd/meroxa/root/apps/logs.go @@ -117,7 +117,7 @@ func (l *Logs) Execute(ctx context.Context) error { return getErr } - output := display.AppLogsTable(appLogs) + output := display.LogsTable(appLogs) l.logger.Info(ctx, output) l.logger.JSON(ctx, appLogs) diff --git a/cmd/meroxa/root/apps/logs_test.go b/cmd/meroxa/root/apps/logs_test.go index 2ef21f836..a4c593f6d 100644 --- a/cmd/meroxa/root/apps/logs_test.go +++ b/cmd/meroxa/root/apps/logs_test.go @@ -107,7 +107,7 @@ func TestApplicationLogsExecution(t *testing.T) { } gotLeveledOutput := logger.LeveledOutput() - wantLeveledOutput := display.AppLogsTable(appLogs) + wantLeveledOutput := display.LogsTable(appLogs) // N.B. This comparison is undeterminstic when the test data map contains // more than one key. Maps in golang are not guaranteed ordered so the result @@ -198,7 +198,7 @@ func TestApplicationLogsExecutionWithPath(t *testing.T) { } gotLeveledOutput := logger.LeveledOutput() - wantLeveledOutput := display.AppLogsTable(appLogs) + wantLeveledOutput := display.LogsTable(appLogs) if !strings.Contains(gotLeveledOutput, wantLeveledOutput) { t.Fatalf(cmp.Diff(wantLeveledOutput, gotLeveledOutput)) diff --git a/cmd/meroxa/root/flink/flink.go b/cmd/meroxa/root/flink/flink.go index 8f945d2f7..56b2a7629 100644 --- a/cmd/meroxa/root/flink/flink.go +++ b/cmd/meroxa/root/flink/flink.go @@ -52,6 +52,7 @@ func (*Job) SubCommands() []*cobra.Command { return []*cobra.Command{ builder.BuildCobraCommand(&Deploy{}), builder.BuildCobraCommand(&Describe{}), + builder.BuildCobraCommand(&Logs{}), builder.BuildCobraCommand(&Remove{}), builder.BuildCobraCommand(&List{}), } diff --git a/cmd/meroxa/root/flink/logs.go b/cmd/meroxa/root/flink/logs.go new file mode 100644 index 000000000..633a222eb --- /dev/null +++ b/cmd/meroxa/root/flink/logs.go @@ -0,0 +1,98 @@ +/* +Copyright © 2022 Meroxa Inc + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package flink + +import ( + "context" + "errors" + + "github.com/meroxa/cli/cmd/meroxa/builder" + "github.com/meroxa/cli/log" + "github.com/meroxa/cli/utils/display" + "github.com/meroxa/meroxa-go/pkg/meroxa" +) + +var ( + _ builder.CommandWithAliases = (*Logs)(nil) + _ builder.CommandWithDocs = (*Logs)(nil) + _ builder.CommandWithArgs = (*Logs)(nil) + _ builder.CommandWithClient = (*Logs)(nil) + _ builder.CommandWithLogger = (*Logs)(nil) + _ builder.CommandWithExecute = (*Logs)(nil) +) + +type Logs struct { + client flinkLogsClient + logger log.Logger + + args struct { + NameOrUUID string + } +} + +type flinkLogsClient interface { + GetFlinkLogsV2(ctx context.Context, nameOrUUID string) (*meroxa.Logs, error) +} + +func (*Logs) Aliases() []string { + return []string{"log"} +} + +func (l *Logs) Usage() string { + return `logs [NameOrUUID] [--path pwd]` +} + +func (l *Logs) Docs() builder.Docs { + return builder.Docs{ + Short: "View relevant logs to the state of the given Flink Job", + Example: `meroxa jobs logs my-flink-job-name +meroxa jobs logs my-flink-job-uuid`, + } +} + +func (l *Logs) Execute(ctx context.Context) error { + nameOrUUID := l.args.NameOrUUID + + appLogs, getErr := l.client.GetFlinkLogsV2(ctx, nameOrUUID) + if getErr != nil { + return getErr + } + + output := display.LogsTable(appLogs) + + l.logger.Info(ctx, output) + l.logger.JSON(ctx, appLogs) + + return nil +} + +func (l *Logs) Client(client meroxa.Client) { + l.client = client +} + +func (l *Logs) Logger(logger log.Logger) { + l.logger = logger +} + +func (l *Logs) ParseArgs(args []string) error { + if len(args) < 1 { + return errors.New("requires Flink Job name or UUID") + } + + l.args.NameOrUUID = args[0] + return nil +} diff --git a/cmd/meroxa/root/flink/logs_test.go b/cmd/meroxa/root/flink/logs_test.go new file mode 100644 index 000000000..61817cb8d --- /dev/null +++ b/cmd/meroxa/root/flink/logs_test.go @@ -0,0 +1,104 @@ +package flink + +import ( + "context" + "encoding/json" + "errors" + "reflect" + "strings" + "testing" + "time" + + "github.com/meroxa/cli/utils" + + "github.com/golang/mock/gomock" + "github.com/google/go-cmp/cmp" + "github.com/meroxa/cli/log" + "github.com/meroxa/cli/utils/display" + "github.com/meroxa/meroxa-go/pkg/meroxa" + "github.com/meroxa/meroxa-go/pkg/mock" +) + +func TestLogsFlinkJobArgs(t *testing.T) { + tests := []struct { + args []string + err error + name string + }{ + {args: nil, err: errors.New("requires Flink Job name or UUID"), name: ""}, + {args: []string{"job-name"}, err: nil, name: "job-name"}, + } + + for _, tt := range tests { + l := &Logs{} + err := l.ParseArgs(tt.args) + + if err != nil && tt.err.Error() != err.Error() { + t.Fatalf("expected \"%s\" got \"%s\"", tt.err, err) + } + + if tt.name != l.args.NameOrUUID { + t.Fatalf("expected \"%s\" got \"%s\"", tt.name, l.args.NameOrUUID) + } + } +} + +func TestFlinkLogsExecution(t *testing.T) { + ctx := context.Background() + ctrl := gomock.NewController(t) + client := mock.NewMockClient(ctrl) + logger := log.NewTestLogger() + + fj := utils.GenerateFlinkJob() + + flinkLogs := &meroxa.Logs{ + Data: []meroxa.LogData{ + { + Timestamp: time.Now().UTC(), + Log: "log just logging", + Source: "connector", + }, + { + Timestamp: time.Now().UTC(), + Log: "another log", + Source: "flink-job", + }, + }, + Metadata: meroxa.Metadata{ + End: time.Now().UTC(), + Start: time.Now().UTC().Add(-12 * time.Hour), + Limit: 10, + }, + } + + client.EXPECT().GetFlinkLogsV2(ctx, fj.Name).Return(flinkLogs, nil) + + l := &Logs{ + client: client, + logger: logger, + } + l.args.NameOrUUID = fj.Name + + err := l.Execute(ctx) + if err != nil { + t.Fatalf("not expected error, got %q", err.Error()) + } + + gotLeveledOutput := logger.LeveledOutput() + wantLeveledOutput := display.LogsTable(flinkLogs) + + if !strings.Contains(gotLeveledOutput, wantLeveledOutput) { + t.Fatalf(cmp.Diff(wantLeveledOutput, gotLeveledOutput)) + } + + gotJSONOutput := logger.JSONOutput() + var gotAppLogs meroxa.Logs + err = json.Unmarshal([]byte(gotJSONOutput), &gotAppLogs) + if err != nil { + t.Fatalf("not expected error, got %q", err.Error()) + } + + if !reflect.DeepEqual(gotAppLogs, *flinkLogs) { + t.Fatalf(cmp.Diff(*flinkLogs, gotAppLogs)) + } +} diff --git a/etc/man/man1/meroxa-account-list.1 b/etc/man/man1/meroxa-account-list.1 index a34092252..d2b9c0258 100644 --- a/etc/man/man1/meroxa-account-list.1 +++ b/etc/man/man1/meroxa-account-list.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-account-set.1 b/etc/man/man1/meroxa-account-set.1 index 941db739e..96bd76ee8 100644 --- a/etc/man/man1/meroxa-account-set.1 +++ b/etc/man/man1/meroxa-account-set.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-account.1 b/etc/man/man1/meroxa-account.1 index 90aa68479..e31587819 100644 --- a/etc/man/man1/meroxa-account.1 +++ b/etc/man/man1/meroxa-account.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-api.1 b/etc/man/man1/meroxa-api.1 index 922b6e383..2b6986fac 100644 --- a/etc/man/man1/meroxa-api.1 +++ b/etc/man/man1/meroxa-api.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-apps-deploy.1 b/etc/man/man1/meroxa-apps-deploy.1 index 5a8fd3801..fc56aad52 100644 --- a/etc/man/man1/meroxa-apps-deploy.1 +++ b/etc/man/man1/meroxa-apps-deploy.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-apps-describe.1 b/etc/man/man1/meroxa-apps-describe.1 index a9305de7a..22d8e62c9 100644 --- a/etc/man/man1/meroxa-apps-describe.1 +++ b/etc/man/man1/meroxa-apps-describe.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-apps-init.1 b/etc/man/man1/meroxa-apps-init.1 index 4503b104a..f4febc5c6 100644 --- a/etc/man/man1/meroxa-apps-init.1 +++ b/etc/man/man1/meroxa-apps-init.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-apps-list.1 b/etc/man/man1/meroxa-apps-list.1 index 4f3e525c6..ca9c459c4 100644 --- a/etc/man/man1/meroxa-apps-list.1 +++ b/etc/man/man1/meroxa-apps-list.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-apps-logs.1 b/etc/man/man1/meroxa-apps-logs.1 index 69b865b00..c90de6cdd 100644 --- a/etc/man/man1/meroxa-apps-logs.1 +++ b/etc/man/man1/meroxa-apps-logs.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-apps-open.1 b/etc/man/man1/meroxa-apps-open.1 index 490c1095f..48f60b2ff 100644 --- a/etc/man/man1/meroxa-apps-open.1 +++ b/etc/man/man1/meroxa-apps-open.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-apps-remove.1 b/etc/man/man1/meroxa-apps-remove.1 index b1f0c1dc2..8217bf0df 100644 --- a/etc/man/man1/meroxa-apps-remove.1 +++ b/etc/man/man1/meroxa-apps-remove.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-apps-run.1 b/etc/man/man1/meroxa-apps-run.1 index 0f76d0a50..aca18d599 100644 --- a/etc/man/man1/meroxa-apps-run.1 +++ b/etc/man/man1/meroxa-apps-run.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-apps-upgrade.1 b/etc/man/man1/meroxa-apps-upgrade.1 index 6e4cb0c15..19f99ea73 100644 --- a/etc/man/man1/meroxa-apps-upgrade.1 +++ b/etc/man/man1/meroxa-apps-upgrade.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-apps.1 b/etc/man/man1/meroxa-apps.1 index f13f0306a..58ee936de 100644 --- a/etc/man/man1/meroxa-apps.1 +++ b/etc/man/man1/meroxa-apps.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-auth-login.1 b/etc/man/man1/meroxa-auth-login.1 index 85df98413..e95fccdaf 100644 --- a/etc/man/man1/meroxa-auth-login.1 +++ b/etc/man/man1/meroxa-auth-login.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-auth-logout.1 b/etc/man/man1/meroxa-auth-logout.1 index 3dd2fc253..e6f945993 100644 --- a/etc/man/man1/meroxa-auth-logout.1 +++ b/etc/man/man1/meroxa-auth-logout.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-auth-whoami.1 b/etc/man/man1/meroxa-auth-whoami.1 index f26965a5f..064c30f01 100644 --- a/etc/man/man1/meroxa-auth-whoami.1 +++ b/etc/man/man1/meroxa-auth-whoami.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-auth.1 b/etc/man/man1/meroxa-auth.1 index 9c5c52b21..419457fa7 100644 --- a/etc/man/man1/meroxa-auth.1 +++ b/etc/man/man1/meroxa-auth.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-billing.1 b/etc/man/man1/meroxa-billing.1 index 010e75248..f2e2efa17 100644 --- a/etc/man/man1/meroxa-billing.1 +++ b/etc/man/man1/meroxa-billing.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-builds-describe.1 b/etc/man/man1/meroxa-builds-describe.1 index 713711f5d..402411747 100644 --- a/etc/man/man1/meroxa-builds-describe.1 +++ b/etc/man/man1/meroxa-builds-describe.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-builds-logs.1 b/etc/man/man1/meroxa-builds-logs.1 index 2b2b77b96..20501ab11 100644 --- a/etc/man/man1/meroxa-builds-logs.1 +++ b/etc/man/man1/meroxa-builds-logs.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-builds.1 b/etc/man/man1/meroxa-builds.1 index 8af5920c6..b832f062e 100644 --- a/etc/man/man1/meroxa-builds.1 +++ b/etc/man/man1/meroxa-builds.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-completion.1 b/etc/man/man1/meroxa-completion.1 index d28469735..3dc66b291 100644 --- a/etc/man/man1/meroxa-completion.1 +++ b/etc/man/man1/meroxa-completion.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-config-describe.1 b/etc/man/man1/meroxa-config-describe.1 index a39a8c903..2d2bac3e1 100644 --- a/etc/man/man1/meroxa-config-describe.1 +++ b/etc/man/man1/meroxa-config-describe.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-config-set.1 b/etc/man/man1/meroxa-config-set.1 index b9c1ecce0..d54fc2183 100644 --- a/etc/man/man1/meroxa-config-set.1 +++ b/etc/man/man1/meroxa-config-set.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-config.1 b/etc/man/man1/meroxa-config.1 index 4b398f719..604844810 100644 --- a/etc/man/man1/meroxa-config.1 +++ b/etc/man/man1/meroxa-config.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-environments-create.1 b/etc/man/man1/meroxa-environments-create.1 index 1c3c3c6b7..42ce100af 100644 --- a/etc/man/man1/meroxa-environments-create.1 +++ b/etc/man/man1/meroxa-environments-create.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-environments-describe.1 b/etc/man/man1/meroxa-environments-describe.1 index 30f7723e1..2437c2df2 100644 --- a/etc/man/man1/meroxa-environments-describe.1 +++ b/etc/man/man1/meroxa-environments-describe.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-environments-list.1 b/etc/man/man1/meroxa-environments-list.1 index e0966b211..9d3d85b2d 100644 --- a/etc/man/man1/meroxa-environments-list.1 +++ b/etc/man/man1/meroxa-environments-list.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-environments-remove.1 b/etc/man/man1/meroxa-environments-remove.1 index 2f718930d..96b7ae9dd 100644 --- a/etc/man/man1/meroxa-environments-remove.1 +++ b/etc/man/man1/meroxa-environments-remove.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-environments-repair.1 b/etc/man/man1/meroxa-environments-repair.1 index 52400798e..e6c217726 100644 --- a/etc/man/man1/meroxa-environments-repair.1 +++ b/etc/man/man1/meroxa-environments-repair.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-environments-update.1 b/etc/man/man1/meroxa-environments-update.1 index 337660411..48f9e6a07 100644 --- a/etc/man/man1/meroxa-environments-update.1 +++ b/etc/man/man1/meroxa-environments-update.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-environments.1 b/etc/man/man1/meroxa-environments.1 index 1e84789e0..2c9774a14 100644 --- a/etc/man/man1/meroxa-environments.1 +++ b/etc/man/man1/meroxa-environments.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-login.1 b/etc/man/man1/meroxa-login.1 index 1f71ec075..230d40e11 100644 --- a/etc/man/man1/meroxa-login.1 +++ b/etc/man/man1/meroxa-login.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-logout.1 b/etc/man/man1/meroxa-logout.1 index 328a0c885..810a7ac9a 100644 --- a/etc/man/man1/meroxa-logout.1 +++ b/etc/man/man1/meroxa-logout.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-open-billing.1 b/etc/man/man1/meroxa-open-billing.1 index 925fa02ea..cce1c5380 100644 --- a/etc/man/man1/meroxa-open-billing.1 +++ b/etc/man/man1/meroxa-open-billing.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-open.1 b/etc/man/man1/meroxa-open.1 index 8f15a3635..b6053dd64 100644 --- a/etc/man/man1/meroxa-open.1 +++ b/etc/man/man1/meroxa-open.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-resources-create.1 b/etc/man/man1/meroxa-resources-create.1 index 59f034c31..c2697fd3b 100644 --- a/etc/man/man1/meroxa-resources-create.1 +++ b/etc/man/man1/meroxa-resources-create.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-resources-describe.1 b/etc/man/man1/meroxa-resources-describe.1 index 91f810221..58b3c62f9 100644 --- a/etc/man/man1/meroxa-resources-describe.1 +++ b/etc/man/man1/meroxa-resources-describe.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-resources-list.1 b/etc/man/man1/meroxa-resources-list.1 index b3a372ad9..cfaba4bcd 100644 --- a/etc/man/man1/meroxa-resources-list.1 +++ b/etc/man/man1/meroxa-resources-list.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-resources-remove.1 b/etc/man/man1/meroxa-resources-remove.1 index 7e835ebdb..93dc081d6 100644 --- a/etc/man/man1/meroxa-resources-remove.1 +++ b/etc/man/man1/meroxa-resources-remove.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-resources-rotate-tunnel-key.1 b/etc/man/man1/meroxa-resources-rotate-tunnel-key.1 index 804a8e3d8..161fc4a0b 100644 --- a/etc/man/man1/meroxa-resources-rotate-tunnel-key.1 +++ b/etc/man/man1/meroxa-resources-rotate-tunnel-key.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-resources-update.1 b/etc/man/man1/meroxa-resources-update.1 index 573aa52f6..2ccf3cb44 100644 --- a/etc/man/man1/meroxa-resources-update.1 +++ b/etc/man/man1/meroxa-resources-update.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-resources-validate.1 b/etc/man/man1/meroxa-resources-validate.1 index 62256703a..e3b77fa9c 100644 --- a/etc/man/man1/meroxa-resources-validate.1 +++ b/etc/man/man1/meroxa-resources-validate.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-resources.1 b/etc/man/man1/meroxa-resources.1 index fa414ada7..062b87af7 100644 --- a/etc/man/man1/meroxa-resources.1 +++ b/etc/man/man1/meroxa-resources.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-transforms-list.1 b/etc/man/man1/meroxa-transforms-list.1 index aa49f720c..64dd44b96 100644 --- a/etc/man/man1/meroxa-transforms-list.1 +++ b/etc/man/man1/meroxa-transforms-list.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-transforms.1 b/etc/man/man1/meroxa-transforms.1 index 690a77171..31497e8a3 100644 --- a/etc/man/man1/meroxa-transforms.1 +++ b/etc/man/man1/meroxa-transforms.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-version.1 b/etc/man/man1/meroxa-version.1 index bc3dbcf9e..e5e4ebfe9 100644 --- a/etc/man/man1/meroxa-version.1 +++ b/etc/man/man1/meroxa-version.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa-whoami.1 b/etc/man/man1/meroxa-whoami.1 index fa5eb2b2d..930b0311a 100644 --- a/etc/man/man1/meroxa-whoami.1 +++ b/etc/man/man1/meroxa-whoami.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/etc/man/man1/meroxa.1 b/etc/man/man1/meroxa.1 index 6aad7652a..ac630bd2d 100644 --- a/etc/man/man1/meroxa.1 +++ b/etc/man/man1/meroxa.1 @@ -1,5 +1,5 @@ .nh -.TH "Meroxa" "1" "May 2023" "Meroxa CLI " "Meroxa Manual" +.TH "Meroxa" "1" "Aug 2023" "Meroxa CLI " "Meroxa Manual" .SH NAME .PP diff --git a/go.mod b/go.mod index abe1631e1..e3a4e355c 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/manifoldco/promptui v0.9.0 github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-runewidth v0.0.13 // indirect - github.com/meroxa/meroxa-go v0.0.0-20230818143040-4b0824efc9e7 + github.com/meroxa/meroxa-go v0.0.0-20230825083516-b71959984f10 github.com/nirasan/go-oauth-pkce-code-verifier v0.0.0-20170819232839-0fbfe93532da github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4 github.com/rivo/uniseg v0.2.0 // indirect diff --git a/go.sum b/go.sum index 7c2ec676b..e44aeeae9 100644 --- a/go.sum +++ b/go.sum @@ -185,8 +185,8 @@ github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4 github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/mattn/go-shellwords v1.0.12 h1:M2zGm7EW6UQJvDeQxo4T51eKPurbeFbe8WtebGE2xrk= github.com/mattn/go-shellwords v1.0.12/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y= -github.com/meroxa/meroxa-go v0.0.0-20230818143040-4b0824efc9e7 h1:0/3guJe/N7lQAiVMAIjzf/H4s9c3VcfCa3zqQThMf2Q= -github.com/meroxa/meroxa-go v0.0.0-20230818143040-4b0824efc9e7/go.mod h1:aGLMvOqFX9O+vgy5JkBFH1/OzKWjYXVCDg21hIE3WtE= +github.com/meroxa/meroxa-go v0.0.0-20230825083516-b71959984f10 h1:SqmiKJXuwU4eTPYYlKXMICliVSxKlciBK3Ljbz3m9j0= +github.com/meroxa/meroxa-go v0.0.0-20230825083516-b71959984f10/go.mod h1:aGLMvOqFX9O+vgy5JkBFH1/OzKWjYXVCDg21hIE3WtE= github.com/meroxa/turbine-core v0.0.0-20230815153536-e0c914b74ea1 h1:4tx5X9TVepTLVYP2ZOokKwkCSBldtGZh69kArXZaI9c= github.com/meroxa/turbine-core v0.0.0-20230815153536-e0c914b74ea1/go.mod h1:03beJfCWdChsKHzbhiDlOcYKyAKkrtoC3y8ualUFOrI= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= diff --git a/utils/display/apps.go b/utils/display/apps.go index c04a50208..222510e2f 100644 --- a/utils/display/apps.go +++ b/utils/display/apps.go @@ -3,7 +3,6 @@ package display import ( "fmt" "strings" - "time" "github.com/alexeyco/simpletable" "github.com/meroxa/meroxa-go/pkg/meroxa" @@ -176,14 +175,3 @@ func appFunctionsTable(functions []meroxa.EntityDetails) string { return subTable } - -func AppLogsTable(appLogs *meroxa.Logs) string { - var subTable string - - for i := len(appLogs.Data) - 1; i >= 0; i-- { - l := appLogs.Data[i] - subTable += fmt.Sprintf("[%s]\t%s\t%q\n", l.Timestamp.Format(time.RFC3339), l.Source, l.Log) - } - - return subTable -} diff --git a/utils/display/apps_test.go b/utils/display/apps_test.go index 64c77094b..778d574ef 100644 --- a/utils/display/apps_test.go +++ b/utils/display/apps_test.go @@ -1,51 +1,14 @@ package display import ( - "fmt" "strings" "testing" - "time" "github.com/meroxa/cli/utils" "github.com/meroxa/meroxa-go/pkg/meroxa" ) -func TestAppLogsTable(t *testing.T) { - res := "res" - fun := "fun" - log := "custom log" - now := time.Now().UTC() - logs := meroxa.Logs{ - Data: []meroxa.LogData{ - { - Timestamp: now, - Log: log, - Source: fun, - }, - { - Timestamp: now, - Log: log, - Source: res, - }, - }, - Metadata: meroxa.Metadata{ - End: now, - Start: now.Add(-12 * time.Hour), - Limit: 10, - }, - } - - out := AppLogsTable(&logs) - - if want := fmt.Sprintf("[%s]\t%s\t%q", now.Format(time.RFC3339), res, log); !strings.Contains(out, want) { - t.Errorf("expected %q to be shown with logs, %s", want, out) - } - if want := fmt.Sprintf("[%s]\t%s\t%q", now.Format(time.RFC3339), fun, log); !strings.Contains(out, want) { - t.Errorf("expected %q to be shown with logs, %s", want, out) - } -} - func TestAppDescribeTable(t *testing.T) { testCases := []struct { desc string diff --git a/utils/display/logs.go b/utils/display/logs.go new file mode 100644 index 000000000..885ea93ee --- /dev/null +++ b/utils/display/logs.go @@ -0,0 +1,19 @@ +package display + +import ( + "fmt" + "time" + + "github.com/meroxa/meroxa-go/pkg/meroxa" +) + +func LogsTable(ll *meroxa.Logs) string { + var subTable string + + for i := len(ll.Data) - 1; i >= 0; i-- { + l := ll.Data[i] + subTable += fmt.Sprintf("[%s]\t%s\t%q\n", l.Timestamp.Format(time.RFC3339), l.Source, l.Log) + } + + return subTable +} diff --git a/utils/display/logs_test.go b/utils/display/logs_test.go new file mode 100644 index 000000000..06f67aa98 --- /dev/null +++ b/utils/display/logs_test.go @@ -0,0 +1,45 @@ +package display + +import ( + "fmt" + "strings" + "testing" + "time" + + "github.com/meroxa/meroxa-go/pkg/meroxa" +) + +func TestLogsTable(t *testing.T) { + res := "res" + fun := "fun" + log := "custom log" + now := time.Now().UTC() + logs := meroxa.Logs{ + Data: []meroxa.LogData{ + { + Timestamp: now, + Log: log, + Source: fun, + }, + { + Timestamp: now, + Log: log, + Source: res, + }, + }, + Metadata: meroxa.Metadata{ + End: now, + Start: now.Add(-12 * time.Hour), + Limit: 10, + }, + } + + out := LogsTable(&logs) + + if want := fmt.Sprintf("[%s]\t%s\t%q", now.Format(time.RFC3339), res, log); !strings.Contains(out, want) { + t.Errorf("expected %q to be shown with logs, %s", want, out) + } + if want := fmt.Sprintf("[%s]\t%s\t%q", now.Format(time.RFC3339), fun, log); !strings.Contains(out, want) { + t.Errorf("expected %q to be shown with logs, %s", want, out) + } +} diff --git a/vendor/github.com/meroxa/meroxa-go/pkg/meroxa/flink_job.go b/vendor/github.com/meroxa/meroxa-go/pkg/meroxa/flink_job.go index 0000c8324..a89a2876d 100644 --- a/vendor/github.com/meroxa/meroxa-go/pkg/meroxa/flink_job.go +++ b/vendor/github.com/meroxa/meroxa-go/pkg/meroxa/flink_job.go @@ -8,7 +8,8 @@ import ( "time" ) -const flinkJobsBasePath = "/v1/flink-jobs" +const flinkJobsBasePathV1 = "/v1/flink-jobs" +const flinkJobsBasePathV2 = "/v2/flink-jobs" type FlinkJobDesiredState string type FlinkJobLifecycleState string @@ -70,7 +71,7 @@ type CreateFlinkJobInput struct { } func (c *client) GetFlinkJob(ctx context.Context, nameOrUUID string) (*FlinkJob, error) { - resp, err := c.MakeRequest(ctx, http.MethodGet, fmt.Sprintf("%s/%s", flinkJobsBasePath, nameOrUUID), nil, nil, nil) + resp, err := c.MakeRequest(ctx, http.MethodGet, fmt.Sprintf("%s/%s", flinkJobsBasePathV1, nameOrUUID), nil, nil, nil) if err != nil { return nil, err } @@ -88,7 +89,7 @@ func (c *client) GetFlinkJob(ctx context.Context, nameOrUUID string) (*FlinkJob, } func (c *client) ListFlinkJobs(ctx context.Context) ([]*FlinkJob, error) { - resp, err := c.MakeRequest(ctx, http.MethodGet, flinkJobsBasePath, nil, nil, nil) + resp, err := c.MakeRequest(ctx, http.MethodGet, flinkJobsBasePathV1, nil, nil, nil) if err != nil { return nil, err } @@ -106,7 +107,7 @@ func (c *client) ListFlinkJobs(ctx context.Context) ([]*FlinkJob, error) { } func (c *client) CreateFlinkJob(ctx context.Context, input *CreateFlinkJobInput) (*FlinkJob, error) { - resp, err := c.MakeRequest(ctx, http.MethodPost, flinkJobsBasePath, input, nil, nil) + resp, err := c.MakeRequest(ctx, http.MethodPost, flinkJobsBasePathV1, input, nil, nil) if err != nil { return nil, err } @@ -124,10 +125,31 @@ func (c *client) CreateFlinkJob(ctx context.Context, input *CreateFlinkJobInput) } func (c *client) DeleteFlinkJob(ctx context.Context, nameOrUUID string) error { - resp, err := c.MakeRequest(ctx, http.MethodDelete, fmt.Sprintf("%s/%s", flinkJobsBasePath, nameOrUUID), nil, nil, nil) + resp, err := c.MakeRequest(ctx, http.MethodDelete, fmt.Sprintf("%s/%s", flinkJobsBasePathV1, nameOrUUID), nil, nil, nil) if err != nil { return err } return handleAPIErrors(resp) } + +func (c *client) GetFlinkLogsV2(ctx context.Context, nameOrUUID string) (*Logs, error) { + path := fmt.Sprintf("%s/%s/logs", flinkJobsBasePathV2, nameOrUUID) + resp, err := c.MakeRequest(ctx, http.MethodGet, path, nil, nil, nil) + if err != nil { + return nil, err + } + + err = handleAPIErrors(resp) + if err != nil { + return nil, err + } + + var l *Logs + err = json.NewDecoder(resp.Body).Decode(&l) + if err != nil { + return nil, err + } + + return l, nil +} diff --git a/vendor/github.com/meroxa/meroxa-go/pkg/meroxa/meroxa.go b/vendor/github.com/meroxa/meroxa-go/pkg/meroxa/meroxa.go index 7456528d9..dde7c0863 100644 --- a/vendor/github.com/meroxa/meroxa-go/pkg/meroxa/meroxa.go +++ b/vendor/github.com/meroxa/meroxa-go/pkg/meroxa/meroxa.go @@ -87,6 +87,7 @@ type Client interface { DeleteFlinkJob(ctx context.Context, nameOrUUID string) error GetFlinkJob(ctx context.Context, nameOrUUID string) (*FlinkJob, error) ListFlinkJobs(ctx context.Context) ([]*FlinkJob, error) + GetFlinkLogsV2(ctx context.Context, nameOrUUID string) (*Logs, error) CreateFunction(ctx context.Context, input *CreateFunctionInput) (*Function, error) GetFunction(ctx context.Context, nameOrUUID string) (*Function, error) diff --git a/vendor/github.com/meroxa/meroxa-go/pkg/mock/mock_client.go b/vendor/github.com/meroxa/meroxa-go/pkg/mock/mock_client.go index 6012bebb2..6d7724972 100644 --- a/vendor/github.com/meroxa/meroxa-go/pkg/mock/mock_client.go +++ b/vendor/github.com/meroxa/meroxa-go/pkg/mock/mock_client.go @@ -552,6 +552,21 @@ func (mr *MockClientMockRecorder) GetFlinkJob(ctx, nameOrUUID interface{}) *gomo return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetFlinkJob", reflect.TypeOf((*MockClient)(nil).GetFlinkJob), ctx, nameOrUUID) } +// GetFlinkLogsV2 mocks base method. +func (m *MockClient) GetFlinkLogsV2(ctx context.Context, nameOrUUID string) (*meroxa.Logs, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetFlinkLogsV2", ctx, nameOrUUID) + ret0, _ := ret[0].(*meroxa.Logs) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetFlinkLogsV2 indicates an expected call of GetFlinkLogsV2. +func (mr *MockClientMockRecorder) GetFlinkLogsV2(ctx, nameOrUUID interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetFlinkLogsV2", reflect.TypeOf((*MockClient)(nil).GetFlinkLogsV2), ctx, nameOrUUID) +} + // GetFunction mocks base method. func (m *MockClient) GetFunction(ctx context.Context, nameOrUUID string) (*meroxa.Function, error) { m.ctrl.T.Helper() diff --git a/vendor/modules.txt b/vendor/modules.txt index 0fea1b679..23d66ee5a 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -107,7 +107,7 @@ github.com/mattn/go-runewidth # github.com/mattn/go-shellwords v1.0.12 ## explicit; go 1.13 github.com/mattn/go-shellwords -# github.com/meroxa/meroxa-go v0.0.0-20230818143040-4b0824efc9e7 +# github.com/meroxa/meroxa-go v0.0.0-20230825083516-b71959984f10 ## explicit; go 1.20 github.com/meroxa/meroxa-go/pkg/meroxa github.com/meroxa/meroxa-go/pkg/mock