Skip to content

Commit

Permalink
Support for client metrics in mcctl (#942)
Browse files Browse the repository at this point in the history
  • Loading branch information
levshvarts authored Aug 7, 2020
1 parent 9f1ad75 commit 9887899
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 5 deletions.
7 changes: 7 additions & 0 deletions mc/mcctl/cliwrapper/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,10 @@ func (s *Client) ShowCloudletMetrics(uri, token string, query *ormapi.RegionClou
st, err := s.runObjs(uri, token, args, query, &metrics)
return &metrics, st, err
}

func (s *Client) ShowClientMetrics(uri, token string, query *ormapi.RegionClientMetrics) (*ormapi.AllMetrics, int, error) {
args := []string{"metrics", "client"}
metrics := ormapi.AllMetrics{}
st, err := s.runObjs(uri, token, args, query, &metrics)
return &metrics, st, err
}
79 changes: 74 additions & 5 deletions mc/mcctl/ormctl/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ormctl
import (
"strings"

"github.com/mobiledgex/edge-cloud-infra/mc/orm"
"github.com/mobiledgex/edge-cloud-infra/mc/ormapi"
"github.com/mobiledgex/edge-cloud/cli"
"github.com/spf13/cobra"
Expand All @@ -14,7 +15,7 @@ func GetMetricsCommand() *cobra.Command {
RequiredArgs: strings.Join(append([]string{"region"}, AppMetricRequiredArgs...), " "),
OptionalArgs: strings.Join(AppMetricOptionalArgs, " "),
AliasArgs: strings.Join(AppMetricAliasArgs, " "),
Comments: addRegionComment(MetricComments),
Comments: mergeMetricComments(addRegionComment(MetricCommentsCommon), AppMetricComments),
ReqData: &ormapi.RegionAppInstMetrics{},
ReplyData: &ormapi.AllMetrics{},
Run: runRest("/auth/metrics/app"),
Expand All @@ -23,7 +24,7 @@ func GetMetricsCommand() *cobra.Command {
RequiredArgs: strings.Join(append([]string{"region"}, ClusterMetricRequiredArgs...), " "),
OptionalArgs: strings.Join(ClusterMetricOptionalArgs, " "),
AliasArgs: strings.Join(ClusterMetricAliasArgs, " "),
Comments: addRegionComment(MetricComments),
Comments: mergeMetricComments(addRegionComment(MetricCommentsCommon), ClusterMetricComments),
ReqData: &ormapi.RegionClusterInstMetrics{},
ReplyData: &ormapi.AllMetrics{},
Run: runRest("/auth/metrics/cluster"),
Expand All @@ -32,10 +33,19 @@ func GetMetricsCommand() *cobra.Command {
RequiredArgs: strings.Join(append([]string{"region"}, CloudletMetricRequiredArgs...), " "),
OptionalArgs: strings.Join(CloudletMetricOptionalArgs, " "),
AliasArgs: strings.Join(CloudletMetricAliasArgs, " "),
Comments: addRegionComment(MetricComments),
Comments: mergeMetricComments(addRegionComment(MetricCommentsCommon), CloudletMetricComments),
ReqData: &ormapi.RegionCloudletMetrics{},
ReplyData: &ormapi.AllMetrics{},
Run: runRest("/auth/metrics/cloudlet"),
}, &cli.Command{
Use: "client",
RequiredArgs: strings.Join(append([]string{"region"}, ClientMetricRequiredArgs...), " "),
OptionalArgs: strings.Join(ClientMetricOptionalArgs, " "),
AliasArgs: strings.Join(ClientMetricAliasArgs, " "),
Comments: mergeMetricComments(addRegionComment(MetricCommentsCommon), ClientMetricComments),
ReqData: &ormapi.RegionClientMetrics{},
ReplyData: &ormapi.AllMetrics{},
Run: runRest("/auth/metrics/client"),
}}
return cli.GenGroup("metrics", "view metrics ", cmds)
}
Expand Down Expand Up @@ -67,6 +77,10 @@ var AppMetricAliasArgs = []string{
"cloudlet=appinst.clusterinstkey.cloudletkey.name",
}

var AppMetricComments = map[string]string{
"selector": "Comma separated list of metrics to view. Available metrics: \"" + strings.Join(orm.AppSelectors, "\", \"") + "\"",
}

var ClusterMetricRequiredArgs = []string{
"cluster-org",
"selector",
Expand All @@ -88,6 +102,10 @@ var ClusterMetricAliasArgs = []string{
"cloudlet=clusterinst.cloudletkey.name",
}

var ClusterMetricComments = map[string]string{
"selector": "Comma separated list of metrics to view. Available metrics: \"" + strings.Join(orm.ClusterSelectors, "\", \"") + "\"",
}

var CloudletMetricRequiredArgs = []string{
"cloudlet-org",
"selector",
Expand All @@ -105,16 +123,67 @@ var CloudletMetricAliasArgs = []string{
"cloudlet=cloudlet.name",
}

var MetricComments = map[string]string{
var CloudletMetricComments = map[string]string{
"selector": "Comma separated list of metrics to view. Available metrics: \"" + strings.Join(orm.CloudletSelectors, "\", \"") + "\"",
}

var ClientMetricRequiredArgs = []string{
"app-org",
"selector",
}

var ClientMetricOptionalArgs = []string{
"appname",
"appvers",
"cluster",
"cluster-org",
"cloudlet",
"cloudlet-org",
"method",
"cellid",
"last",
"starttime",
"endtime",
}

var ClientMetricAliasArgs = []string{
"app-org=appinst.appkey.organization",
"appname=appinst.appkey.name",
"appvers=appinst.appkey.version",
"cluster=appinst.clusterinstkey.clusterkey.name",
"cluster-org=appinst.clusterinstkey.organization",
"cloudlet-org=appinst.clusterinstkey.cloudletkey.organization",
"cloudlet=appinst.clusterinstkey.cloudletkey.name",
}

var ClientMetricComments = map[string]string{
"method": "Api call method, one of: FindCloudlet, PlatformFindCloudlet, RegisterClient, VerifyLocation",
"cellid": "Cell tower Id(experimental)",
"selector": "Comma separated list of metrics to view. Currently only \"api\" is supported.",
}

var MetricCommentsCommon = map[string]string{
"app-org": "Organization or Company name of the App",
"appname": "App name",
"appvers": "App version",
"cluster": "Cluster name",
"cloudlet-org": "Company or Organization name of the cloudlet",
"cloudlet": "Name of the cloudlet",
"cluster-org": "Organization or Company Name that a Cluster is used by",
"selector": "Comma separated list of metrics to view",
"last": "Display the last X metrics",
"starttime": "Time to start displaying stats from in RFC3339 format (ex. 2002-12-31T15:00:00Z)",
"endtime": "Time up to which to display stats in RFC3339 format (ex. 2002-12-31T10:00:00-05:00)",
}

// merge two maps - entries in b will overwrite values in a
// resulting map is a newly allocated map
func mergeMetricComments(a, b map[string]string) map[string]string {
res := map[string]string{}
for k, v := range a {
res[k] = v
}
for k, v := range b {
res[k] = v
}
return res
}
1 change: 1 addition & 0 deletions mc/ormclient/clientapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type Api interface {
ShowAppMetrics(uri, token string, query *ormapi.RegionAppInstMetrics) (*ormapi.AllMetrics, int, error)
ShowClusterMetrics(uri, token string, query *ormapi.RegionClusterInstMetrics) (*ormapi.AllMetrics, int, error)
ShowCloudletMetrics(uri, token string, query *ormapi.RegionCloudletMetrics) (*ormapi.AllMetrics, int, error)
ShowClientMetrics(uri, token string, query *ormapi.RegionClientMetrics) (*ormapi.AllMetrics, int, error)

ShowAppEvents(uri, token string, query *ormapi.RegionAppInstEvents) (*ormapi.AllMetrics, int, error)
ShowClusterEvents(uri, token string, query *ormapi.RegionClusterInstEvents) (*ormapi.AllMetrics, int, error)
Expand Down
6 changes: 6 additions & 0 deletions mc/ormclient/rest_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ func (s *Client) ShowCloudletMetrics(uri, token string, query *ormapi.RegionClou
return &metrics, status, err
}

func (s *Client) ShowClientMetrics(uri, token string, query *ormapi.RegionClientMetrics) (*ormapi.AllMetrics, int, error) {
metrics := ormapi.AllMetrics{}
status, err := s.PostJson(uri+"/auth/metrics/client", token, query, &metrics)
return &metrics, status, err
}

func (s *Client) ShowAppEvents(uri, token string, query *ormapi.RegionAppInstEvents) (*ormapi.AllMetrics, int, error) {
metrics := ormapi.AllMetrics{}
status, err := s.PostJson(uri+"/auth/events/app", token, query, &metrics)
Expand Down

0 comments on commit 9887899

Please sign in to comment.