Skip to content

Commit

Permalink
Implement phone home [CLC-205] (hazelcast#298)
Browse files Browse the repository at this point in the history
Add metric collection system
  • Loading branch information
mtyazici authored Sep 26, 2023
1 parent a1477c0 commit ff92790
Show file tree
Hide file tree
Showing 112 changed files with 1,359 additions and 232 deletions.
2 changes: 1 addition & 1 deletion base/commands/atomic_long/atomic_long_destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ import (
)

func init() {
c := commands.NewDestroyCommand("AtomicLong", getAtomicLong)
c := commands.NewDestroyCommand("AtomicLong", "atomiclong", getAtomicLong)
check.Must(plug.Registry.RegisterCommand("atomic-long:destroy", c))
}
1 change: 1 addition & 0 deletions base/commands/atomic_long/atomic_long_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func (GetCommand) Exec(ctx context.Context, ec plug.ExecContext) error {
if err != nil {
return nil, err
}
cmd.IncrementClusterMetric(ctx, ec, "total.atomiclong")
sp.SetText(fmt.Sprintf("Getting value of AtomicLong %s", ali.Name()))
val, err := ali.Get(ctx)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions base/commands/atomic_long/atomic_long_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func (mc *SetCommand) Exec(ctx context.Context, ec plug.ExecContext) error {
if err != nil {
return nil, err
}
cmd.IncrementClusterMetric(ctx, ec, "total.atomiclong")
sp.SetText(fmt.Sprintf("Setting value of AtomicLong %s", name))
v := ec.GetInt64Arg(base.ArgValue)
err = ali.Set(ctx, v)
Expand Down
1 change: 1 addition & 0 deletions base/commands/atomic_long/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func atomicLongChangeValue(ctx context.Context, ec plug.ExecContext, verb string
if err != nil {
return nil, err
}
cmd.IncrementClusterMetric(ctx, ec, "total.atomiclong")
sp.SetText(fmt.Sprintf("%sing the AtomicLong %s", verb, name))
val, err := ali.AddAndGet(ctx, change(by))
if err != nil {
Expand Down
16 changes: 13 additions & 3 deletions base/commands/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/hazelcast/hazelcast-commandline-client/base"
_ "github.com/hazelcast/hazelcast-commandline-client/base"
"github.com/hazelcast/hazelcast-commandline-client/clc"
"github.com/hazelcast/hazelcast-commandline-client/clc/cmd"
"github.com/hazelcast/hazelcast-commandline-client/errors"
"github.com/hazelcast/hazelcast-commandline-client/internal"
"github.com/hazelcast/hazelcast-commandline-client/internal/mk"
Expand All @@ -35,12 +36,14 @@ type getDestroyerFunc[T Destroyer] func(context.Context, plug.ExecContext, clc.S

type DestroyCommand[T Destroyer] struct {
typeName string
metricName string
getDestroyerFn getDestroyerFunc[T]
}

func NewDestroyCommand[T Destroyer](typeName string, getFn getDestroyerFunc[T]) *DestroyCommand[T] {
func NewDestroyCommand[T Destroyer](typeName string, metricName string, getFn getDestroyerFunc[T]) *DestroyCommand[T] {
return &DestroyCommand[T]{
typeName: typeName,
metricName: metricName,
getDestroyerFn: getFn,
}
}
Expand Down Expand Up @@ -75,6 +78,7 @@ func (cm DestroyCommand[T]) Exec(ctx context.Context, ec plug.ExecContext) error
if err != nil {
return nil, err
}
cmd.IncrementClusterMetric(ctx, ec, "total."+cm.metricName)
sp.SetText(fmt.Sprintf("Destroying %s '%s'", cm.typeName, name))
if err := m.Destroy(ctx); err != nil {
return nil, err
Expand All @@ -98,12 +102,14 @@ type getClearerFunc[T Clearer] func(context.Context, plug.ExecContext, clc.Spinn

type ClearCommand[T Clearer] struct {
typeName string
metricName string
getClearerFn getClearerFunc[T]
}

func NewClearCommand[T Clearer](typeName string, getFn getClearerFunc[T]) *ClearCommand[T] {
func NewClearCommand[T Clearer](typeName, metricName string, getFn getClearerFunc[T]) *ClearCommand[T] {
return &ClearCommand[T]{
typeName: typeName,
metricName: metricName,
getClearerFn: getFn,
}
}
Expand Down Expand Up @@ -135,6 +141,7 @@ func (cm ClearCommand[T]) Exec(ctx context.Context, ec plug.ExecContext) error {
if err != nil {
return nil, err
}
cmd.IncrementClusterMetric(ctx, ec, "total."+cm.metricName)
sp.SetText(fmt.Sprintf("Clearing %s '%s'", cm.typeName, name))
if err := m.Clear(ctx); err != nil {
return nil, err
Expand All @@ -158,12 +165,14 @@ type getSizerFunc[T Sizer] func(context.Context, plug.ExecContext, clc.Spinner)

type SizeCommand[T Sizer] struct {
typeName string
metricName string
getSizerFn getSizerFunc[T]
}

func NewSizeCommand[T Sizer](typeName string, getFn getSizerFunc[T]) *SizeCommand[T] {
func NewSizeCommand[T Sizer](typeName, metricName string, getFn getSizerFunc[T]) *SizeCommand[T] {
return &SizeCommand[T]{
typeName: typeName,
metricName: metricName,
getSizerFn: getFn,
}
}
Expand All @@ -182,6 +191,7 @@ func (cm SizeCommand[T]) Exec(ctx context.Context, ec plug.ExecContext) error {
if err != nil {
return nil, err
}
cmd.IncrementClusterMetric(ctx, ec, "total."+cm.metricName)
sp.SetText(fmt.Sprintf("Getting the size of %s '%s'", cm.typeName, name))
return m.Size(ctx)
})
Expand Down
10 changes: 6 additions & 4 deletions base/commands/demo/demo_generate_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func (GenerateDataCommand) Exec(ctx context.Context, ec plug.ExecContext) error
}

func generatePreviewResult(ctx context.Context, ec plug.ExecContext, generator dataStreamGenerator, keyVals map[string]string) error {
cmd.IncrementMetric(ctx, ec, "total.demo")
maxCount := ec.Props().GetInt(flagMaxValues)
if maxCount < 1 {
maxCount = 10
Expand Down Expand Up @@ -121,15 +122,16 @@ func generateResult(ctx context.Context, ec plug.ExecContext, generator dataStre
return fmt.Errorf("either %s key-value pair must be given or --preview must be used", pairMapName)
}
maxCount := ec.Props().GetInt(flagMaxValues)
query, err := generator.GenerateMappingQuery(mapName)
if err != nil {
return err
}
query, stop, err := cmd.ExecuteBlocking(ctx, ec, func(ctx context.Context, sp clc.Spinner) (string, error) {
sp.SetText("Creating the mapping")
query, err := generator.GenerateMappingQuery(mapName)
if err != nil {
return "", err
}
if _, err := sql.ExecSQL(ctx, ec, query); err != nil {
return "", err
}
cmd.IncrementClusterMetric(ctx, ec, "total.demo")
return query, nil
})
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions base/commands/demo/demo_map_set_many.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

"github.com/hazelcast/hazelcast-commandline-client/clc"
"github.com/hazelcast/hazelcast-commandline-client/clc/cmd"
. "github.com/hazelcast/hazelcast-commandline-client/internal/check"
"github.com/hazelcast/hazelcast-commandline-client/internal/check"
"github.com/hazelcast/hazelcast-commandline-client/internal/plug"
)

Expand Down Expand Up @@ -48,6 +48,7 @@ func (m MapSetManyCmd) Exec(ctx context.Context, ec plug.ExecContext) error {
if err != nil {
return nil, err
}
cmd.IncrementClusterMetric(ctx, ec, "total.demo")
sp.SetText(fmt.Sprintf("Creating entries in map %s with %d entries", mapName, count))
mm, err := ci.Client().GetMap(ctx, mapName)
if err != nil {
Expand Down Expand Up @@ -113,5 +114,5 @@ func getValueSize(sizeStr string) (int64, error) {
}

func init() {
Must(plug.Registry.RegisterCommand("demo:map-setmany", &MapSetManyCmd{}))
check.Must(plug.Registry.RegisterCommand("demo:map-setmany", &MapSetManyCmd{}))
}
2 changes: 2 additions & 0 deletions base/commands/job/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/hazelcast/hazelcast-go-client/types"

"github.com/hazelcast/hazelcast-commandline-client/clc/cmd"
"github.com/hazelcast/hazelcast-commandline-client/clc/ux/stage"
"github.com/hazelcast/hazelcast-commandline-client/internal/jet"
"github.com/hazelcast/hazelcast-commandline-client/internal/plug"
Expand Down Expand Up @@ -70,6 +71,7 @@ func terminateJob(ctx context.Context, ec plug.ExecContext, tm int32, cm Termina
if err != nil {
return 0, err
}
cmd.IncrementClusterMetric(ctx, ec, "total.job")
j := jet.New(ci, status, ec.Logger())
jis, err := j.GetJobList(ctx)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions base/commands/job/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"context"

"github.com/hazelcast/hazelcast-commandline-client/clc"
. "github.com/hazelcast/hazelcast-commandline-client/internal/check"
"github.com/hazelcast/hazelcast-commandline-client/internal/check"
"github.com/hazelcast/hazelcast-commandline-client/internal/plug"
)

Expand All @@ -27,5 +27,5 @@ func (Command) Exec(context.Context, plug.ExecContext) error {
}

func init() {
Must(plug.Registry.RegisterCommand("job", &Command{}))
check.Must(plug.Registry.RegisterCommand("job", &Command{}))
}
5 changes: 3 additions & 2 deletions base/commands/job/job_export_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/hazelcast/hazelcast-commandline-client/clc"
"github.com/hazelcast/hazelcast-commandline-client/clc/cmd"
. "github.com/hazelcast/hazelcast-commandline-client/internal/check"
"github.com/hazelcast/hazelcast-commandline-client/internal/check"
"github.com/hazelcast/hazelcast-commandline-client/internal/jet"
"github.com/hazelcast/hazelcast-commandline-client/internal/output"
"github.com/hazelcast/hazelcast-commandline-client/internal/plug"
Expand Down Expand Up @@ -42,6 +42,7 @@ func (ExportSnapshotCommand) Exec(ctx context.Context, ec plug.ExecContext) erro
if err != nil {
return nil, err
}
cmd.IncrementClusterMetric(ctx, ec, "total.job")
j := jet.New(ci, sp, ec.Logger())
jis, err := j.GetJobList(ctx)
if err != nil {
Expand Down Expand Up @@ -104,5 +105,5 @@ func autoGenerateSnapshotName(jobName string) string {
}

func init() {
Must(plug.Registry.RegisterCommand("job:export-snapshot", &ExportSnapshotCommand{}))
check.Must(plug.Registry.RegisterCommand("job:export-snapshot", &ExportSnapshotCommand{}))
}
5 changes: 3 additions & 2 deletions base/commands/job/job_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/hazelcast/hazelcast-commandline-client/clc"
"github.com/hazelcast/hazelcast-commandline-client/clc/cmd"
. "github.com/hazelcast/hazelcast-commandline-client/internal/check"
"github.com/hazelcast/hazelcast-commandline-client/internal/check"
"github.com/hazelcast/hazelcast-commandline-client/internal/jet"
"github.com/hazelcast/hazelcast-commandline-client/internal/output"
"github.com/hazelcast/hazelcast-commandline-client/internal/plug"
Expand All @@ -35,6 +35,7 @@ func (ListCommand) Exec(ctx context.Context, ec plug.ExecContext) error {
if err != nil {
return nil, err
}
cmd.IncrementClusterMetric(ctx, ec, "total.job")
sp.SetText("Getting the job list")
j := jet.New(ci, sp, ec.Logger())
jl, err := j.GetJobList(ctx)
Expand Down Expand Up @@ -139,5 +140,5 @@ func msToOffsetDateTimeColumn(ms int64, name string) output.Column {
}

func init() {
Must(plug.Registry.RegisterCommand("job:list", &ListCommand{}))
check.Must(plug.Registry.RegisterCommand("job:list", &ListCommand{}))
}
6 changes: 4 additions & 2 deletions base/commands/job/job_resume.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (
"fmt"
"time"

"github.com/hazelcast/hazelcast-commandline-client/clc/cmd"
"github.com/hazelcast/hazelcast-commandline-client/clc/ux/stage"
. "github.com/hazelcast/hazelcast-commandline-client/internal/check"
"github.com/hazelcast/hazelcast-commandline-client/internal/check"
"github.com/hazelcast/hazelcast-commandline-client/internal/jet"
"github.com/hazelcast/hazelcast-commandline-client/internal/plug"
)
Expand Down Expand Up @@ -37,6 +38,7 @@ func (ResumeCommand) Exec(ctx context.Context, ec plug.ExecContext) error {
if err != nil {
return 0, err
}
cmd.IncrementClusterMetric(ctx, ec, "total.job")
j := jet.New(ci, status, ec.Logger())
jis, err := j.GetJobList(ctx)
if err != nil {
Expand Down Expand Up @@ -73,5 +75,5 @@ func (ResumeCommand) Exec(ctx context.Context, ec plug.ExecContext) error {
}

func init() {
Must(plug.Registry.RegisterCommand("job:resume", &ResumeCommand{}))
check.Must(plug.Registry.RegisterCommand("job:resume", &ResumeCommand{}))
}
5 changes: 3 additions & 2 deletions base/commands/job/job_submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/hazelcast/hazelcast-commandline-client/clc/cmd"
"github.com/hazelcast/hazelcast-commandline-client/clc/paths"
"github.com/hazelcast/hazelcast-commandline-client/clc/ux/stage"
. "github.com/hazelcast/hazelcast-commandline-client/internal/check"
"github.com/hazelcast/hazelcast-commandline-client/internal/check"
"github.com/hazelcast/hazelcast-commandline-client/internal/jet"
"github.com/hazelcast/hazelcast-commandline-client/internal/log"
"github.com/hazelcast/hazelcast-commandline-client/internal/output"
Expand Down Expand Up @@ -104,6 +104,7 @@ func submitJar(ctx context.Context, ec plug.ExecContext, path string) (int64, er
if err != nil {
return 0, err
}
cmd.IncrementClusterMetric(ctx, ec, "total.job")
if sv, ok := cmd.CheckServerCompatible(ci, minServerVersion); !ok {
err := fmt.Errorf("server (%s) does not support this command, at least %s is expected", sv, minServerVersion)
return 0, err
Expand Down Expand Up @@ -207,5 +208,5 @@ func getJobIDs(ctx context.Context, j *jet.Jet, jobName string) (types.Set[int64
}

func init() {
Must(plug.Registry.RegisterCommand("job:submit", &SubmitCommand{}))
check.Must(plug.Registry.RegisterCommand("job:submit", &SubmitCommand{}))
}
8 changes: 4 additions & 4 deletions base/commands/job/job_terminate.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"context"
"fmt"

. "github.com/hazelcast/hazelcast-commandline-client/internal/check"
"github.com/hazelcast/hazelcast-commandline-client/internal/check"
"github.com/hazelcast/hazelcast-commandline-client/internal/jet"
"github.com/hazelcast/hazelcast-commandline-client/internal/plug"
)
Expand Down Expand Up @@ -44,7 +44,7 @@ func (cm TerminateCommand) Exec(ctx context.Context, ec plug.ExecContext) error
}

func init() {
Must(plug.Registry.RegisterCommand("job:cancel", &TerminateCommand{
check.Must(plug.Registry.RegisterCommand("job:cancel", &TerminateCommand{
name: "cancel",
longHelp: "Cancels the job with the given ID or name",
shortHelp: "Cancels the job with the given ID or name",
Expand All @@ -55,7 +55,7 @@ func init() {
successMsg: "Started cancellation of '%s'",
failureMsg: "Failed to start job cancellation",
}))
Must(plug.Registry.RegisterCommand("job:suspend", &TerminateCommand{
check.Must(plug.Registry.RegisterCommand("job:suspend", &TerminateCommand{
name: "suspend",
longHelp: "Suspends the job with the given ID or name",
shortHelp: "Suspends the job with the given ID or name",
Expand All @@ -66,7 +66,7 @@ func init() {
successMsg: "Started suspension of '%s'",
failureMsg: "Failed to start job suspension",
}))
Must(plug.Registry.RegisterCommand("job:restart", &TerminateCommand{
check.Must(plug.Registry.RegisterCommand("job:restart", &TerminateCommand{
name: "restart",
longHelp: "Restarts the job with the given ID or name",
shortHelp: "Restarts the job with the given ID or name",
Expand Down
1 change: 1 addition & 0 deletions base/commands/list/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func removeFromList(ctx context.Context, ec plug.ExecContext, name string, index
if err != nil {
return nil, err
}
cmd.IncrementClusterMetric(ctx, ec, "total.list")
pid, err := internal.StringToPartitionID(ci, name)
if err != nil {
return nil, err
Expand Down
7 changes: 4 additions & 3 deletions base/commands/list/list_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/hazelcast/hazelcast-commandline-client/clc"
"github.com/hazelcast/hazelcast-commandline-client/clc/cmd"
"github.com/hazelcast/hazelcast-commandline-client/internal"
. "github.com/hazelcast/hazelcast-commandline-client/internal/check"
"github.com/hazelcast/hazelcast-commandline-client/internal/check"
"github.com/hazelcast/hazelcast-commandline-client/internal/output"
"github.com/hazelcast/hazelcast-commandline-client/internal/plug"
"github.com/hazelcast/hazelcast-commandline-client/internal/proto/codec"
Expand All @@ -39,6 +39,7 @@ func (AddCommand) Exec(ctx context.Context, ec plug.ExecContext) error {
if err != nil {
return nil, err
}
cmd.IncrementClusterMetric(ctx, ec, "total.list")
// get the list just to ensure the corresponding proxy is created
_, err = getList(ctx, ec, sp)
if err != nil {
Expand Down Expand Up @@ -67,7 +68,7 @@ func (AddCommand) Exec(ctx context.Context, ec plug.ExecContext) error {
}
if index >= 0 {
return true, nil
}
}
return codec.DecodeListAddResponse(resp), nil
})
if err != nil {
Expand All @@ -87,5 +88,5 @@ func (AddCommand) Exec(ctx context.Context, ec plug.ExecContext) error {
}

func init() {
Must(plug.Registry.RegisterCommand("list:add", &AddCommand{}))
check.Must(plug.Registry.RegisterCommand("list:add", &AddCommand{}))
}
2 changes: 1 addition & 1 deletion base/commands/list/list_clear.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ import (
)

func init() {
cmd := commands.NewClearCommand("List", getList)
cmd := commands.NewClearCommand("List", "list", getList)
check.Must(plug.Registry.RegisterCommand("list:clear", cmd))
}
Loading

0 comments on commit ff92790

Please sign in to comment.