From 9887899173e379e7355e26dd6eb1baaf307eefd8 Mon Sep 17 00:00:00 2001 From: Lev Shvarts Date: Fri, 7 Aug 2020 12:05:05 -0500 Subject: [PATCH] Support for client metrics in mcctl (#942) --- mc/mcctl/cliwrapper/metrics.go | 7 +++ mc/mcctl/ormctl/metrics.go | 79 +++++++++++++++++++++++++++++++--- mc/ormclient/clientapi.go | 1 + mc/ormclient/rest_client.go | 6 +++ 4 files changed, 88 insertions(+), 5 deletions(-) diff --git a/mc/mcctl/cliwrapper/metrics.go b/mc/mcctl/cliwrapper/metrics.go index f9f7215cd..1fc820c27 100644 --- a/mc/mcctl/cliwrapper/metrics.go +++ b/mc/mcctl/cliwrapper/metrics.go @@ -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 +} diff --git a/mc/mcctl/ormctl/metrics.go b/mc/mcctl/ormctl/metrics.go index ac1b9afef..16d74e855 100644 --- a/mc/mcctl/ormctl/metrics.go +++ b/mc/mcctl/ormctl/metrics.go @@ -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" @@ -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"), @@ -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"), @@ -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) } @@ -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", @@ -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", @@ -105,7 +123,46 @@ 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", @@ -113,8 +170,20 @@ var MetricComments = map[string]string{ "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 +} diff --git a/mc/ormclient/clientapi.go b/mc/ormclient/clientapi.go index 4be9f9e89..fabcf5d01 100644 --- a/mc/ormclient/clientapi.go +++ b/mc/ormclient/clientapi.go @@ -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) diff --git a/mc/ormclient/rest_client.go b/mc/ormclient/rest_client.go index 34ad74edf..8a607543d 100644 --- a/mc/ormclient/rest_client.go +++ b/mc/ormclient/rest_client.go @@ -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)