Drop unreleased features (record & replay) (#1406)
1. The records are stored in redis which is not migratable to another cluster for the testing purposes. 2. Some of the requests fields are not recorded. 3. People should consider using https://github.com/buger/goreplay which is an existing mature and well-tested solution for testing purposes.
This commit is contained in:
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
Copyright 2019 The Fission Authors.
|
||||
|
||||
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 recorder
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
wrapper "github.com/fission/fission/pkg/fission-cli/cliwrapper/driver/cobra"
|
||||
"github.com/fission/fission/pkg/fission-cli/flag"
|
||||
)
|
||||
|
||||
func Commands() *cobra.Command {
|
||||
createCmd := &cobra.Command{
|
||||
Use: "create",
|
||||
Short: "Create a recorder",
|
||||
RunE: wrapper.Wrapper(Create),
|
||||
}
|
||||
wrapper.SetFlags(createCmd, flag.FlagSet{
|
||||
Optional: []flag.Flag{flag.RecorderName, flag.RecorderFn, flag.RecorderTriggers, flag.SpecSave},
|
||||
})
|
||||
|
||||
getCmd := &cobra.Command{
|
||||
Use: "get",
|
||||
Short: "Get recorder details",
|
||||
RunE: wrapper.Wrapper(Get),
|
||||
}
|
||||
wrapper.SetFlags(getCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.RecorderName},
|
||||
})
|
||||
|
||||
updateCmd := &cobra.Command{
|
||||
Use: "update",
|
||||
Short: "Update a recorder",
|
||||
RunE: wrapper.Wrapper(Update),
|
||||
}
|
||||
wrapper.SetFlags(getCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.RecorderName},
|
||||
Optional: []flag.Flag{flag.RecorderFn, flag.RecorderTriggers, flag.RecorderEnabled, flag.RecorderDisabled},
|
||||
})
|
||||
|
||||
deleteCmd := &cobra.Command{
|
||||
Use: "delete",
|
||||
Short: "Delete a recorder",
|
||||
RunE: wrapper.Wrapper(Delete),
|
||||
}
|
||||
wrapper.SetFlags(deleteCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.RecorderName},
|
||||
Optional: []flag.Flag{flag.NamespaceRecorder},
|
||||
})
|
||||
|
||||
listCmd := &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "List all recorders in a namespace if specified, else, list recorders across all namespaces",
|
||||
RunE: wrapper.Wrapper(List),
|
||||
}
|
||||
wrapper.SetFlags(deleteCmd, flag.FlagSet{
|
||||
Optional: []flag.Flag{flag.NamespaceRecorder},
|
||||
})
|
||||
|
||||
command := &cobra.Command{
|
||||
Use: "recorder",
|
||||
Short: "Create, update and manage recorders",
|
||||
Hidden: true,
|
||||
}
|
||||
|
||||
command.AddCommand(createCmd, getCmd, updateCmd, deleteCmd, listCmd)
|
||||
|
||||
return command
|
||||
}
|
||||
@@ -1,124 +0,0 @@
|
||||
/*
|
||||
Copyright 2019 The Fission Authors.
|
||||
|
||||
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 recorder
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/satori/go.uuid"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||
"github.com/fission/fission/pkg/controller/client"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
"github.com/fission/fission/pkg/fission-cli/cmd/spec"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
|
||||
type CreateSubCommand struct {
|
||||
client *client.Client
|
||||
recorder *fv1.Recorder
|
||||
}
|
||||
|
||||
func Create(input cli.Input) error {
|
||||
c, err := util.GetServer(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := CreateSubCommand{
|
||||
client: c,
|
||||
}
|
||||
return opts.do(input)
|
||||
}
|
||||
|
||||
func (opts *CreateSubCommand) do(input cli.Input) error {
|
||||
err := opts.complete(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return opts.run(input)
|
||||
}
|
||||
|
||||
func (opts *CreateSubCommand) complete(input cli.Input) error {
|
||||
recName := input.String("name")
|
||||
if len(recName) == 0 {
|
||||
recName = uuid.NewV4().String()
|
||||
}
|
||||
fnName := input.String("function")
|
||||
triggersOriginal := input.StringSlice("trigger")
|
||||
|
||||
// Function XOR triggers can be given
|
||||
if len(fnName) == 0 && len(triggersOriginal) == 0 {
|
||||
return errors.New("Need to specify at least one function or one trigger, use --function, --trigger")
|
||||
}
|
||||
if len(fnName) != 0 && len(triggersOriginal) != 0 {
|
||||
return errors.New("Can specify either one function or one or more triggers, but not both")
|
||||
}
|
||||
|
||||
// TODO: Validate here or elsewhere that all triggers belong to the same namespace
|
||||
|
||||
var triggers []string
|
||||
if len(triggersOriginal) != 0 {
|
||||
ts := strings.Split(triggersOriginal[0], ",")
|
||||
for _, name := range ts {
|
||||
if len(name) > 0 {
|
||||
triggers = append(triggers, name)
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO: Define appropriate set of policies and defaults
|
||||
//retPolicy := flags.String("retention")
|
||||
//evictPolicy := flags.String("eviction")
|
||||
|
||||
opts.recorder = &fv1.Recorder{
|
||||
Metadata: metav1.ObjectMeta{
|
||||
Name: recName,
|
||||
Namespace: "default",
|
||||
},
|
||||
Spec: fv1.RecorderSpec{
|
||||
Name: recName,
|
||||
Function: fnName,
|
||||
Triggers: triggers,
|
||||
RetentionPolicy: "Permanent", // TODO: Implement customizable policies for expiration of records
|
||||
EvictionPolicy: "None",
|
||||
Enabled: true,
|
||||
},
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (opts *CreateSubCommand) run(input cli.Input) error {
|
||||
// If we're writing a spec, don't call the API
|
||||
if input.Bool("spec") {
|
||||
specFile := fmt.Sprintf("recorder-%v.yaml", opts.recorder.Metadata.Name)
|
||||
err := spec.SpecSave(*opts.recorder, specFile)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error creating recorder spec")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
_, err := opts.client.RecorderCreate(opts.recorder)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error creating recorder")
|
||||
}
|
||||
|
||||
fmt.Printf("recorder '%s' created\n", opts.recorder.Metadata.Name)
|
||||
return nil
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
Copyright 2019 The Fission Authors.
|
||||
|
||||
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 recorder
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
"github.com/fission/fission/pkg/controller/client"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
|
||||
type DeleteSubCommand struct {
|
||||
client *client.Client
|
||||
metadata *metav1.ObjectMeta
|
||||
}
|
||||
|
||||
func Delete(input cli.Input) error {
|
||||
c, err := util.GetServer(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := DeleteSubCommand{
|
||||
client: c,
|
||||
}
|
||||
return opts.do(input)
|
||||
}
|
||||
|
||||
func (opts *DeleteSubCommand) do(input cli.Input) error {
|
||||
err := opts.complete(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return opts.run(input)
|
||||
}
|
||||
|
||||
func (opts *DeleteSubCommand) complete(input cli.Input) error {
|
||||
opts.metadata = &metav1.ObjectMeta{
|
||||
Name: input.String("name"),
|
||||
Namespace: input.String("recorderns"),
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (opts *DeleteSubCommand) run(input cli.Input) error {
|
||||
err := opts.client.RecorderDelete(opts.metadata)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error deleting recorder")
|
||||
}
|
||||
fmt.Printf("recorder '%v' deleted\n", opts.metadata.Name)
|
||||
return nil
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
/*
|
||||
Copyright 2019 The Fission Authors.
|
||||
|
||||
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 recorder
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
"github.com/fission/fission/pkg/controller/client"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
|
||||
type GetSubCommand struct {
|
||||
client *client.Client
|
||||
name string
|
||||
}
|
||||
|
||||
func Get(input cli.Input) error {
|
||||
c, err := util.GetServer(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := GetSubCommand{
|
||||
client: c,
|
||||
}
|
||||
return opts.do(input)
|
||||
}
|
||||
|
||||
func (opts *GetSubCommand) do(input cli.Input) error {
|
||||
err := opts.complete(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return opts.run(input)
|
||||
}
|
||||
|
||||
func (opts *GetSubCommand) complete(input cli.Input) error {
|
||||
opts.name = input.String("name")
|
||||
|
||||
if len(opts.name) <= 0 {
|
||||
return errors.New("need a recorder name, use --name")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (opts *GetSubCommand) run(input cli.Input) error {
|
||||
recorder, err := opts.client.RecorderGet(&metav1.ObjectMeta{
|
||||
Name: opts.name,
|
||||
Namespace: "default",
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error getting recorder")
|
||||
}
|
||||
|
||||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', 0)
|
||||
|
||||
fmt.Fprintf(w, "%v\t%v\t%v\t%v\t%v\t%v\n",
|
||||
"NAME", "ENABLED", "FUNCTION", "TRIGGERS", "RETENTION_POLICY", "EVICTION_POLICY")
|
||||
fmt.Fprintf(w, "%v\t%v\t%v\t%v\t%v\t%v\n",
|
||||
recorder.Metadata.Name, recorder.Spec.Enabled, recorder.Spec.Function, recorder.Spec.Triggers, recorder.Spec.RetentionPolicy, recorder.Spec.EvictionPolicy)
|
||||
w.Flush()
|
||||
return nil
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
Copyright 2019 The Fission Authors.
|
||||
|
||||
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 recorder
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/fission/fission/pkg/controller/client"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
|
||||
type ListSubCommand struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
func List(input cli.Input) error {
|
||||
c, err := util.GetServer(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := ListSubCommand{
|
||||
client: c,
|
||||
}
|
||||
return opts.do(input)
|
||||
}
|
||||
|
||||
func (opts *ListSubCommand) do(input cli.Input) error {
|
||||
return opts.run(input)
|
||||
}
|
||||
|
||||
func (opts *ListSubCommand) run(input cli.Input) error {
|
||||
recorders, err := opts.client.RecorderList("default")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error listing recorders")
|
||||
}
|
||||
|
||||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', 0)
|
||||
|
||||
fmt.Fprintf(w, "%v\t%v\t%v\t%v\t%v\t%v\n",
|
||||
"NAME", "ENABLED", "FUNCTIONS", "TRIGGERS", "RETENTION_POLICY", "EVICTION_POLICY")
|
||||
for _, r := range recorders {
|
||||
fmt.Fprintf(w, "%v\t%v\t%v\t%v\t%v\t%v\n",
|
||||
r.Metadata.Name, r.Spec.Enabled, r.Spec.Function, r.Spec.Triggers, r.Spec.RetentionPolicy, r.Spec.EvictionPolicy)
|
||||
}
|
||||
w.Flush()
|
||||
return nil
|
||||
}
|
||||
@@ -1,145 +0,0 @@
|
||||
/*
|
||||
Copyright 2019 The Fission Authors.
|
||||
|
||||
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 recorder
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||
"github.com/fission/fission/pkg/controller/client"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
|
||||
type UpdateSubCommand struct {
|
||||
client *client.Client
|
||||
recorder *fv1.Recorder
|
||||
}
|
||||
|
||||
func Update(input cli.Input) error {
|
||||
c, err := util.GetServer(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := UpdateSubCommand{
|
||||
client: c,
|
||||
}
|
||||
return opts.do(input)
|
||||
}
|
||||
|
||||
func (opts *UpdateSubCommand) do(input cli.Input) error {
|
||||
err := opts.complete(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return opts.run(input)
|
||||
}
|
||||
|
||||
func (opts *UpdateSubCommand) complete(input cli.Input) error {
|
||||
recName := input.String("name")
|
||||
enable := input.Bool("enable")
|
||||
disable := input.Bool("disable")
|
||||
//retPolicy := flags.String("retention")
|
||||
//evictPolicy := flags.String("eviction")
|
||||
triggers := input.StringSlice("trigger")
|
||||
function := input.String("function")
|
||||
|
||||
if enable && disable {
|
||||
return errors.New("Cannot enable and disable a recorder simultaneously.")
|
||||
}
|
||||
|
||||
// Prevent enable or disable while trying to update other fields. These flags must be standalone.
|
||||
if enable || disable {
|
||||
if len(triggers) > 0 || len(function) > 0 {
|
||||
return errors.New("Enabling or disabling a recorder with other (non-name) flags set is not supported.")
|
||||
}
|
||||
} else if len(triggers) == 0 && len(function) == 0 {
|
||||
return errors.New("Need to specify either a function or trigger(s) for this recorder")
|
||||
}
|
||||
|
||||
if len(recName) == 0 {
|
||||
return errors.New("Need name of recorder, use --name")
|
||||
}
|
||||
|
||||
recorder, err := opts.client.RecorderGet(&metav1.ObjectMeta{
|
||||
Name: recName,
|
||||
Namespace: "default",
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error getting recorder")
|
||||
}
|
||||
|
||||
updated := false
|
||||
|
||||
// TODO: Additional validation on type of supported retention policy, eviction policy
|
||||
|
||||
//if len(retPolicy) > 0 {
|
||||
// recorder.Spec.RetentionPolicy = retPolicy
|
||||
// updated = true
|
||||
//}
|
||||
//if len(evictPolicy) > 0 {
|
||||
// recorder.Spec.EvictionPolicy = evictPolicy
|
||||
// updated = true
|
||||
//}
|
||||
if enable {
|
||||
recorder.Spec.Enabled = true
|
||||
updated = true
|
||||
}
|
||||
|
||||
if disable {
|
||||
recorder.Spec.Enabled = false
|
||||
updated = true
|
||||
}
|
||||
|
||||
if len(triggers) > 0 {
|
||||
var newTriggers []string
|
||||
triggs := strings.Split(triggers[0], ",")
|
||||
for _, name := range triggs {
|
||||
if len(name) > 0 {
|
||||
newTriggers = append(newTriggers, name)
|
||||
}
|
||||
}
|
||||
recorder.Spec.Triggers = newTriggers
|
||||
updated = true
|
||||
}
|
||||
|
||||
if len(function) > 0 {
|
||||
recorder.Spec.Function = function
|
||||
updated = true
|
||||
}
|
||||
|
||||
if !updated {
|
||||
return errors.New("Nothing to update. Use --function, --triggers, --enable or --disable")
|
||||
}
|
||||
|
||||
opts.recorder = recorder
|
||||
return nil
|
||||
}
|
||||
|
||||
func (opts *UpdateSubCommand) run(input cli.Input) error {
|
||||
_, err := opts.client.RecorderUpdate(opts.recorder)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error updating recorder")
|
||||
}
|
||||
|
||||
fmt.Printf("recorder '%v' updated\n", opts.recorder.Metadata.Name)
|
||||
return nil
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
Copyright 2019 The Fission Authors.
|
||||
|
||||
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 records
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
wrapper "github.com/fission/fission/pkg/fission-cli/cliwrapper/driver/cobra"
|
||||
"github.com/fission/fission/pkg/fission-cli/flag"
|
||||
)
|
||||
|
||||
func Commands() *cobra.Command {
|
||||
viewCmd := &cobra.Command{
|
||||
Use: "view",
|
||||
Short: "View existing records",
|
||||
RunE: wrapper.Wrapper(View),
|
||||
}
|
||||
wrapper.SetFlags(viewCmd, flag.FlagSet{
|
||||
Optional: []flag.Flag{flag.RecordsFilterTimeTo, flag.RecordsFilterTimeFrom,
|
||||
flag.RecordsFilterFunction, flag.RecordsFilterTrigger, flag.RecordsVerbosity,
|
||||
flag.RecordsVv},
|
||||
})
|
||||
|
||||
command := &cobra.Command{
|
||||
Use: "records",
|
||||
Short: "View records with optional filters",
|
||||
Hidden: true,
|
||||
}
|
||||
|
||||
command.AddCommand(viewCmd)
|
||||
|
||||
return command
|
||||
}
|
||||
@@ -1,159 +0,0 @@
|
||||
/*
|
||||
Copyright 2019 The Fission Authors.
|
||||
|
||||
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 records
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/fission/fission/pkg/controller/client"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
redisCache "github.com/fission/fission/pkg/redis/build/gen"
|
||||
)
|
||||
|
||||
type ViewSubCommand struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
func View(flaginput cli.Input) error {
|
||||
c, err := util.GetServer(flaginput)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := ViewSubCommand{
|
||||
client: c,
|
||||
}
|
||||
return opts.do(flaginput)
|
||||
}
|
||||
|
||||
func (opts *ViewSubCommand) do(input cli.Input) error {
|
||||
return opts.run(input)
|
||||
}
|
||||
|
||||
func (opts *ViewSubCommand) run(input cli.Input) error {
|
||||
var verbosity int
|
||||
if input.Bool("v") && input.Bool("vv") {
|
||||
return errors.New("conflicting verbosity levels, use either --v or --vv")
|
||||
}
|
||||
if input.Bool("v") {
|
||||
verbosity = 1
|
||||
}
|
||||
if input.Bool("vv") {
|
||||
verbosity = 2
|
||||
}
|
||||
|
||||
function := input.String("function")
|
||||
trigger := input.String("trigger")
|
||||
from := input.String("from")
|
||||
to := input.String("to")
|
||||
|
||||
//Refuse multiple filters for now
|
||||
if multipleFiltersSpecified(function, trigger, from+to) {
|
||||
return errors.New("maximum of one filter is currently supported, either --function, --trigger, or --from,--to")
|
||||
}
|
||||
|
||||
if len(function) != 0 {
|
||||
return recordsByFunction(opts.client, function, verbosity)
|
||||
}
|
||||
if len(trigger) != 0 {
|
||||
return recordsByTrigger(opts.client, trigger, verbosity)
|
||||
}
|
||||
if len(from) != 0 && len(to) != 0 {
|
||||
return recordsByTime(opts.client, from, to, verbosity)
|
||||
}
|
||||
err := recordsAll(opts.client, verbosity)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error viewing records")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func recordsAll(client *client.Client, verbosity int) error {
|
||||
records, err := client.RecordsAll()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error viewing records")
|
||||
}
|
||||
showRecords(records, verbosity)
|
||||
return nil
|
||||
}
|
||||
|
||||
func recordsByTrigger(client *client.Client, trigger string, verbosity int) error {
|
||||
records, err := client.RecordsByTrigger(trigger)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error viewing records")
|
||||
}
|
||||
showRecords(records, verbosity)
|
||||
return nil
|
||||
}
|
||||
|
||||
// TODO: More accurate function name (function filter)
|
||||
func recordsByFunction(client *client.Client, function string, verbosity int) error {
|
||||
records, err := client.RecordsByFunction(function)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error viewing records")
|
||||
}
|
||||
showRecords(records, verbosity)
|
||||
return nil
|
||||
}
|
||||
|
||||
func recordsByTime(client *client.Client, from string, to string, verbosity int) error {
|
||||
records, err := client.RecordsByTime(from, to)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error viewing records")
|
||||
}
|
||||
showRecords(records, verbosity)
|
||||
return nil
|
||||
}
|
||||
|
||||
func showRecords(records []*redisCache.RecordedEntry, verbosity int) {
|
||||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', 0)
|
||||
|
||||
if verbosity == 1 {
|
||||
fmt.Fprintf(w, "%v\t%v\t%v\t%v\t%v\n",
|
||||
"REQUID", "REQUEST METHOD", "FUNCTION", "RESPONSE STATUS", "TRIGGER")
|
||||
for _, record := range records {
|
||||
fmt.Fprintf(w, "%v\t%v\t%v\t%v\t%v\n",
|
||||
record.ReqUID, record.Req.Method, record.Req.Header["X-Fission-Function-Name"], record.Resp.Status, record.Trigger)
|
||||
}
|
||||
} else if verbosity == 2 {
|
||||
for _, record := range records {
|
||||
fmt.Println(record)
|
||||
}
|
||||
} else {
|
||||
fmt.Fprintf(w, "%v\n",
|
||||
"REQUID")
|
||||
for _, record := range records {
|
||||
fmt.Fprintf(w, "%v\n",
|
||||
record.ReqUID)
|
||||
}
|
||||
}
|
||||
w.Flush()
|
||||
}
|
||||
|
||||
func multipleFiltersSpecified(entries ...string) bool {
|
||||
var specified int
|
||||
for _, entry := range entries {
|
||||
if len(entry) > 0 {
|
||||
specified += 1
|
||||
}
|
||||
}
|
||||
return specified > 1
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
Copyright 2019 The Fission Authors.
|
||||
|
||||
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 replay
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
wrapper "github.com/fission/fission/pkg/fission-cli/cliwrapper/driver/cobra"
|
||||
"github.com/fission/fission/pkg/fission-cli/flag"
|
||||
)
|
||||
|
||||
func Commands() *cobra.Command {
|
||||
replayCmd := &cobra.Command{
|
||||
Use: "create",
|
||||
Short: "Create a recorder",
|
||||
RunE: wrapper.Wrapper(Replay),
|
||||
}
|
||||
wrapper.SetFlags(replayCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.RecordsReqID},
|
||||
})
|
||||
|
||||
command := &cobra.Command{
|
||||
Use: "replay",
|
||||
Short: "Replay records",
|
||||
Hidden: true,
|
||||
}
|
||||
|
||||
command.AddCommand(replayCmd)
|
||||
|
||||
return command
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
Copyright 2019 The Fission Authors.
|
||||
|
||||
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 replay
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/fission/fission/pkg/controller/client"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
|
||||
type ReplaySubCommand struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
func Replay(input cli.Input) error {
|
||||
c, err := util.GetServer(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := ReplaySubCommand{
|
||||
client: c,
|
||||
}
|
||||
return opts.do(input)
|
||||
}
|
||||
|
||||
func (opts *ReplaySubCommand) do(input cli.Input) error {
|
||||
return opts.run(input)
|
||||
}
|
||||
|
||||
func (opts *ReplaySubCommand) run(input cli.Input) error {
|
||||
reqUID := input.String("reqUID")
|
||||
if len(reqUID) == 0 {
|
||||
return errors.New("Need a reqUID, use --reqUID flag to specify")
|
||||
}
|
||||
|
||||
responses, err := opts.client.ReplayByReqUID(reqUID)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error replaying records")
|
||||
}
|
||||
|
||||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', 0)
|
||||
|
||||
for _, resp := range responses {
|
||||
fmt.Fprintf(w, "%v",
|
||||
resp,
|
||||
)
|
||||
}
|
||||
|
||||
w.Flush()
|
||||
return nil
|
||||
}
|
||||
@@ -209,10 +209,6 @@ func SpecSave(resource interface{}, specFile string) error {
|
||||
typedres.TypeMeta.APIVersion = fv1.CRD_VERSION
|
||||
typedres.TypeMeta.Kind = "TimeTrigger"
|
||||
data, err = yaml.Marshal(typedres)
|
||||
case fv1.Recorder:
|
||||
typedres.TypeMeta.APIVersion = fv1.CRD_VERSION
|
||||
typedres.TypeMeta.Kind = "Recorder"
|
||||
data, err = yaml.Marshal(typedres)
|
||||
default:
|
||||
return fmt.Errorf("can't save resource %#v", resource)
|
||||
}
|
||||
|
||||
@@ -90,15 +90,15 @@ func (opts *DumpSubCommand) do(input cli.Input) error {
|
||||
|
||||
// fission component logs & spec
|
||||
"fission-components-svc-spec": resources.NewKubernetesObjectDumper(k8sClient, resources.KubernetesService,
|
||||
"svc in (buildermgr, controller, executor, influxdb, kubewatcher, logger, mqtrigger, nats-streaming, redis, router, storagesvc, timer)"),
|
||||
"svc in (buildermgr, controller, executor, influxdb, kubewatcher, logger, mqtrigger, nats-streaming, router, storagesvc, timer)"),
|
||||
"fission-components-deployment-spec": resources.NewKubernetesObjectDumper(k8sClient, resources.KubernetesDeployment,
|
||||
"svc in (buildermgr, controller, executor, influxdb, kubewatcher, logger, mqtrigger, nats-streaming, redis, router, storagesvc, timer)"),
|
||||
"svc in (buildermgr, controller, executor, influxdb, kubewatcher, logger, mqtrigger, nats-streaming, router, storagesvc, timer)"),
|
||||
"fission-components-daemonset-spec": resources.NewKubernetesObjectDumper(k8sClient, resources.KubernetesDaemonSet,
|
||||
"svc in (buildermgr, controller, executor, influxdb, kubewatcher, logger, mqtrigger, nats-streaming, redis, router, storagesvc, timer)"),
|
||||
"svc in (buildermgr, controller, executor, influxdb, kubewatcher, logger, mqtrigger, nats-streaming, router, storagesvc, timer)"),
|
||||
"fission-components-pod-spec": resources.NewKubernetesObjectDumper(k8sClient, resources.KubernetesPod,
|
||||
"svc in (buildermgr, controller, executor, influxdb, kubewatcher, logger, mqtrigger, nats-streaming, redis, router, storagesvc, timer)"),
|
||||
"svc in (buildermgr, controller, executor, influxdb, kubewatcher, logger, mqtrigger, nats-streaming, router, storagesvc, timer)"),
|
||||
"fission-components-pod-log": resources.NewKubernetesPodLogDumper(k8sClient,
|
||||
"svc in (buildermgr, controller, executor, influxdb, kubewatcher, logger, mqtrigger, nats-streaming, redis, router, storagesvc, timer)"),
|
||||
"svc in (buildermgr, controller, executor, influxdb, kubewatcher, logger, mqtrigger, nats-streaming, router, storagesvc, timer)"),
|
||||
|
||||
// fission builder logs & spec
|
||||
"fission-builder-svc-spec": resources.NewKubernetesObjectDumper(k8sClient, resources.KubernetesService, "owner=buildermgr"),
|
||||
|
||||
Reference in New Issue
Block a user