From 21fdaf8e3ca4a1e9dbc0c2f20a8a7f609e5c614d Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Tue, 9 May 2023 11:36:53 -0400 Subject: [PATCH] duration parameter (#319) --- .../metrics/get_account_metrics_parameters.go | 33 +++++++++++++++++ .../get_environment_metrics_parameters.go | 32 ++++++++++++++++ .../metrics/get_share_metrics_parameters.go | 32 ++++++++++++++++ rest_server_zrok/embedded_spec.go | 34 +++++++++++++++++ .../metrics/get_account_metrics_parameters.go | 37 +++++++++++++++++++ .../metrics/get_account_metrics_urlbuilder.go | 18 +++++++++ .../get_environment_metrics_parameters.go | 36 ++++++++++++++++++ .../get_environment_metrics_urlbuilder.go | 16 ++++++++ .../metrics/get_share_metrics_parameters.go | 36 ++++++++++++++++++ .../metrics/get_share_metrics_urlbuilder.go | 16 ++++++++ specs/zrok.yml | 10 +++++ ui/src/api/metrics.js | 29 +++++++++++++-- .../console/detail/environment/SharesTab.js | 2 +- ui/src/console/detail/share/ShareDetail.js | 2 +- ui/src/console/visualizer/Network.js | 4 +- ui/src/console/visualizer/graph.js | 4 +- 16 files changed, 331 insertions(+), 10 deletions(-) diff --git a/rest_client_zrok/metrics/get_account_metrics_parameters.go b/rest_client_zrok/metrics/get_account_metrics_parameters.go index 5af21fb7..b06d0b6d 100644 --- a/rest_client_zrok/metrics/get_account_metrics_parameters.go +++ b/rest_client_zrok/metrics/get_account_metrics_parameters.go @@ -14,6 +14,7 @@ import ( "github.com/go-openapi/runtime" cr "github.com/go-openapi/runtime/client" "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" ) // NewGetAccountMetricsParams creates a new GetAccountMetricsParams object, @@ -60,6 +61,10 @@ GetAccountMetricsParams contains all the parameters to send to the API endpoint Typically these are written to a http.Request. */ type GetAccountMetricsParams struct { + + // Duration. + Duration *float64 + timeout time.Duration Context context.Context HTTPClient *http.Client @@ -113,6 +118,17 @@ func (o *GetAccountMetricsParams) SetHTTPClient(client *http.Client) { o.HTTPClient = client } +// WithDuration adds the duration to the get account metrics params +func (o *GetAccountMetricsParams) WithDuration(duration *float64) *GetAccountMetricsParams { + o.SetDuration(duration) + return o +} + +// SetDuration adds the duration to the get account metrics params +func (o *GetAccountMetricsParams) SetDuration(duration *float64) { + o.Duration = duration +} + // WriteToRequest writes these params to a swagger request func (o *GetAccountMetricsParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { @@ -121,6 +137,23 @@ func (o *GetAccountMetricsParams) WriteToRequest(r runtime.ClientRequest, reg st } var res []error + if o.Duration != nil { + + // query param duration + var qrDuration float64 + + if o.Duration != nil { + qrDuration = *o.Duration + } + qDuration := swag.FormatFloat64(qrDuration) + if qDuration != "" { + + if err := r.SetQueryParam("duration", qDuration); err != nil { + return err + } + } + } + if len(res) > 0 { return errors.CompositeValidationError(res...) } diff --git a/rest_client_zrok/metrics/get_environment_metrics_parameters.go b/rest_client_zrok/metrics/get_environment_metrics_parameters.go index 538d0074..796adaae 100644 --- a/rest_client_zrok/metrics/get_environment_metrics_parameters.go +++ b/rest_client_zrok/metrics/get_environment_metrics_parameters.go @@ -14,6 +14,7 @@ import ( "github.com/go-openapi/runtime" cr "github.com/go-openapi/runtime/client" "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" ) // NewGetEnvironmentMetricsParams creates a new GetEnvironmentMetricsParams object, @@ -61,6 +62,9 @@ GetEnvironmentMetricsParams contains all the parameters to send to the API endpo */ type GetEnvironmentMetricsParams struct { + // Duration. + Duration *float64 + // EnvID. EnvID string @@ -117,6 +121,17 @@ func (o *GetEnvironmentMetricsParams) SetHTTPClient(client *http.Client) { o.HTTPClient = client } +// WithDuration adds the duration to the get environment metrics params +func (o *GetEnvironmentMetricsParams) WithDuration(duration *float64) *GetEnvironmentMetricsParams { + o.SetDuration(duration) + return o +} + +// SetDuration adds the duration to the get environment metrics params +func (o *GetEnvironmentMetricsParams) SetDuration(duration *float64) { + o.Duration = duration +} + // WithEnvID adds the envID to the get environment metrics params func (o *GetEnvironmentMetricsParams) WithEnvID(envID string) *GetEnvironmentMetricsParams { o.SetEnvID(envID) @@ -136,6 +151,23 @@ func (o *GetEnvironmentMetricsParams) WriteToRequest(r runtime.ClientRequest, re } var res []error + if o.Duration != nil { + + // query param duration + var qrDuration float64 + + if o.Duration != nil { + qrDuration = *o.Duration + } + qDuration := swag.FormatFloat64(qrDuration) + if qDuration != "" { + + if err := r.SetQueryParam("duration", qDuration); err != nil { + return err + } + } + } + // path param envId if err := r.SetPathParam("envId", o.EnvID); err != nil { return err diff --git a/rest_client_zrok/metrics/get_share_metrics_parameters.go b/rest_client_zrok/metrics/get_share_metrics_parameters.go index 690b280f..359c3c47 100644 --- a/rest_client_zrok/metrics/get_share_metrics_parameters.go +++ b/rest_client_zrok/metrics/get_share_metrics_parameters.go @@ -14,6 +14,7 @@ import ( "github.com/go-openapi/runtime" cr "github.com/go-openapi/runtime/client" "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" ) // NewGetShareMetricsParams creates a new GetShareMetricsParams object, @@ -61,6 +62,9 @@ GetShareMetricsParams contains all the parameters to send to the API endpoint */ type GetShareMetricsParams struct { + // Duration. + Duration *float64 + // ShrToken. ShrToken string @@ -117,6 +121,17 @@ func (o *GetShareMetricsParams) SetHTTPClient(client *http.Client) { o.HTTPClient = client } +// WithDuration adds the duration to the get share metrics params +func (o *GetShareMetricsParams) WithDuration(duration *float64) *GetShareMetricsParams { + o.SetDuration(duration) + return o +} + +// SetDuration adds the duration to the get share metrics params +func (o *GetShareMetricsParams) SetDuration(duration *float64) { + o.Duration = duration +} + // WithShrToken adds the shrToken to the get share metrics params func (o *GetShareMetricsParams) WithShrToken(shrToken string) *GetShareMetricsParams { o.SetShrToken(shrToken) @@ -136,6 +151,23 @@ func (o *GetShareMetricsParams) WriteToRequest(r runtime.ClientRequest, reg strf } var res []error + if o.Duration != nil { + + // query param duration + var qrDuration float64 + + if o.Duration != nil { + qrDuration = *o.Duration + } + qDuration := swag.FormatFloat64(qrDuration) + if qDuration != "" { + + if err := r.SetQueryParam("duration", qDuration); err != nil { + return err + } + } + } + // path param shrToken if err := r.SetPathParam("shrToken", o.ShrToken); err != nil { return err diff --git a/rest_server_zrok/embedded_spec.go b/rest_server_zrok/embedded_spec.go index 59341826..46e97057 100644 --- a/rest_server_zrok/embedded_spec.go +++ b/rest_server_zrok/embedded_spec.go @@ -531,6 +531,13 @@ func init() { "metrics" ], "operationId": "getAccountMetrics", + "parameters": [ + { + "type": "number", + "name": "duration", + "in": "query" + } + ], "responses": { "200": { "description": "account metrics", @@ -558,6 +565,11 @@ func init() { "name": "envId", "in": "path", "required": true + }, + { + "type": "number", + "name": "duration", + "in": "query" } ], "responses": { @@ -590,6 +602,11 @@ func init() { "name": "shrToken", "in": "path", "required": true + }, + { + "type": "number", + "name": "duration", + "in": "query" } ], "responses": { @@ -1924,6 +1941,13 @@ func init() { "metrics" ], "operationId": "getAccountMetrics", + "parameters": [ + { + "type": "number", + "name": "duration", + "in": "query" + } + ], "responses": { "200": { "description": "account metrics", @@ -1951,6 +1975,11 @@ func init() { "name": "envId", "in": "path", "required": true + }, + { + "type": "number", + "name": "duration", + "in": "query" } ], "responses": { @@ -1983,6 +2012,11 @@ func init() { "name": "shrToken", "in": "path", "required": true + }, + { + "type": "number", + "name": "duration", + "in": "query" } ], "responses": { diff --git a/rest_server_zrok/operations/metrics/get_account_metrics_parameters.go b/rest_server_zrok/operations/metrics/get_account_metrics_parameters.go index 98bb9b8c..afe23af1 100644 --- a/rest_server_zrok/operations/metrics/get_account_metrics_parameters.go +++ b/rest_server_zrok/operations/metrics/get_account_metrics_parameters.go @@ -9,7 +9,10 @@ import ( "net/http" "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" ) // NewGetAccountMetricsParams creates a new GetAccountMetricsParams object @@ -28,6 +31,11 @@ type GetAccountMetricsParams struct { // HTTP Request Object HTTPRequest *http.Request `json:"-"` + + /* + In: query + */ + Duration *float64 } // BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface @@ -39,8 +47,37 @@ func (o *GetAccountMetricsParams) BindRequest(r *http.Request, route *middleware o.HTTPRequest = r + qs := runtime.Values(r.URL.Query()) + + qDuration, qhkDuration, _ := qs.GetOK("duration") + if err := o.bindDuration(qDuration, qhkDuration, route.Formats); err != nil { + res = append(res, err) + } if len(res) > 0 { return errors.CompositeValidationError(res...) } return nil } + +// bindDuration binds and validates parameter Duration from query. +func (o *GetAccountMetricsParams) bindDuration(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + + if raw == "" { // empty values pass all other validations + return nil + } + + value, err := swag.ConvertFloat64(raw) + if err != nil { + return errors.InvalidType("duration", "query", "float64", raw) + } + o.Duration = &value + + return nil +} diff --git a/rest_server_zrok/operations/metrics/get_account_metrics_urlbuilder.go b/rest_server_zrok/operations/metrics/get_account_metrics_urlbuilder.go index 16b79838..79001f68 100644 --- a/rest_server_zrok/operations/metrics/get_account_metrics_urlbuilder.go +++ b/rest_server_zrok/operations/metrics/get_account_metrics_urlbuilder.go @@ -9,11 +9,17 @@ import ( "errors" "net/url" golangswaggerpaths "path" + + "github.com/go-openapi/swag" ) // GetAccountMetricsURL generates an URL for the get account metrics operation type GetAccountMetricsURL struct { + Duration *float64 + _basePath string + // avoid unkeyed usage + _ struct{} } // WithBasePath sets the base path for this url builder, only required when it's different from the @@ -43,6 +49,18 @@ func (o *GetAccountMetricsURL) Build() (*url.URL, error) { } _result.Path = golangswaggerpaths.Join(_basePath, _path) + qs := make(url.Values) + + var durationQ string + if o.Duration != nil { + durationQ = swag.FormatFloat64(*o.Duration) + } + if durationQ != "" { + qs.Set("duration", durationQ) + } + + _result.RawQuery = qs.Encode() + return &_result, nil } diff --git a/rest_server_zrok/operations/metrics/get_environment_metrics_parameters.go b/rest_server_zrok/operations/metrics/get_environment_metrics_parameters.go index 1f10409f..69bfb627 100644 --- a/rest_server_zrok/operations/metrics/get_environment_metrics_parameters.go +++ b/rest_server_zrok/operations/metrics/get_environment_metrics_parameters.go @@ -9,8 +9,10 @@ import ( "net/http" "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" "github.com/go-openapi/runtime/middleware" "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" ) // NewGetEnvironmentMetricsParams creates a new GetEnvironmentMetricsParams object @@ -30,6 +32,10 @@ type GetEnvironmentMetricsParams struct { // HTTP Request Object HTTPRequest *http.Request `json:"-"` + /* + In: query + */ + Duration *float64 /* Required: true In: path @@ -46,6 +52,13 @@ func (o *GetEnvironmentMetricsParams) BindRequest(r *http.Request, route *middle o.HTTPRequest = r + qs := runtime.Values(r.URL.Query()) + + qDuration, qhkDuration, _ := qs.GetOK("duration") + if err := o.bindDuration(qDuration, qhkDuration, route.Formats); err != nil { + res = append(res, err) + } + rEnvID, rhkEnvID, _ := route.Params.GetOK("envId") if err := o.bindEnvID(rEnvID, rhkEnvID, route.Formats); err != nil { res = append(res, err) @@ -56,6 +69,29 @@ func (o *GetEnvironmentMetricsParams) BindRequest(r *http.Request, route *middle return nil } +// bindDuration binds and validates parameter Duration from query. +func (o *GetEnvironmentMetricsParams) bindDuration(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + + if raw == "" { // empty values pass all other validations + return nil + } + + value, err := swag.ConvertFloat64(raw) + if err != nil { + return errors.InvalidType("duration", "query", "float64", raw) + } + o.Duration = &value + + return nil +} + // bindEnvID binds and validates parameter EnvID from path. func (o *GetEnvironmentMetricsParams) bindEnvID(rawData []string, hasKey bool, formats strfmt.Registry) error { var raw string diff --git a/rest_server_zrok/operations/metrics/get_environment_metrics_urlbuilder.go b/rest_server_zrok/operations/metrics/get_environment_metrics_urlbuilder.go index a31dfd88..9693cf12 100644 --- a/rest_server_zrok/operations/metrics/get_environment_metrics_urlbuilder.go +++ b/rest_server_zrok/operations/metrics/get_environment_metrics_urlbuilder.go @@ -10,12 +10,16 @@ import ( "net/url" golangswaggerpaths "path" "strings" + + "github.com/go-openapi/swag" ) // GetEnvironmentMetricsURL generates an URL for the get environment metrics operation type GetEnvironmentMetricsURL struct { EnvID string + Duration *float64 + _basePath string // avoid unkeyed usage _ struct{} @@ -55,6 +59,18 @@ func (o *GetEnvironmentMetricsURL) Build() (*url.URL, error) { } _result.Path = golangswaggerpaths.Join(_basePath, _path) + qs := make(url.Values) + + var durationQ string + if o.Duration != nil { + durationQ = swag.FormatFloat64(*o.Duration) + } + if durationQ != "" { + qs.Set("duration", durationQ) + } + + _result.RawQuery = qs.Encode() + return &_result, nil } diff --git a/rest_server_zrok/operations/metrics/get_share_metrics_parameters.go b/rest_server_zrok/operations/metrics/get_share_metrics_parameters.go index 1013bb7a..efc3d81d 100644 --- a/rest_server_zrok/operations/metrics/get_share_metrics_parameters.go +++ b/rest_server_zrok/operations/metrics/get_share_metrics_parameters.go @@ -9,8 +9,10 @@ import ( "net/http" "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" "github.com/go-openapi/runtime/middleware" "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" ) // NewGetShareMetricsParams creates a new GetShareMetricsParams object @@ -30,6 +32,10 @@ type GetShareMetricsParams struct { // HTTP Request Object HTTPRequest *http.Request `json:"-"` + /* + In: query + */ + Duration *float64 /* Required: true In: path @@ -46,6 +52,13 @@ func (o *GetShareMetricsParams) BindRequest(r *http.Request, route *middleware.M o.HTTPRequest = r + qs := runtime.Values(r.URL.Query()) + + qDuration, qhkDuration, _ := qs.GetOK("duration") + if err := o.bindDuration(qDuration, qhkDuration, route.Formats); err != nil { + res = append(res, err) + } + rShrToken, rhkShrToken, _ := route.Params.GetOK("shrToken") if err := o.bindShrToken(rShrToken, rhkShrToken, route.Formats); err != nil { res = append(res, err) @@ -56,6 +69,29 @@ func (o *GetShareMetricsParams) BindRequest(r *http.Request, route *middleware.M return nil } +// bindDuration binds and validates parameter Duration from query. +func (o *GetShareMetricsParams) bindDuration(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + + if raw == "" { // empty values pass all other validations + return nil + } + + value, err := swag.ConvertFloat64(raw) + if err != nil { + return errors.InvalidType("duration", "query", "float64", raw) + } + o.Duration = &value + + return nil +} + // bindShrToken binds and validates parameter ShrToken from path. func (o *GetShareMetricsParams) bindShrToken(rawData []string, hasKey bool, formats strfmt.Registry) error { var raw string diff --git a/rest_server_zrok/operations/metrics/get_share_metrics_urlbuilder.go b/rest_server_zrok/operations/metrics/get_share_metrics_urlbuilder.go index deeb05e3..3477a21a 100644 --- a/rest_server_zrok/operations/metrics/get_share_metrics_urlbuilder.go +++ b/rest_server_zrok/operations/metrics/get_share_metrics_urlbuilder.go @@ -10,12 +10,16 @@ import ( "net/url" golangswaggerpaths "path" "strings" + + "github.com/go-openapi/swag" ) // GetShareMetricsURL generates an URL for the get share metrics operation type GetShareMetricsURL struct { ShrToken string + Duration *float64 + _basePath string // avoid unkeyed usage _ struct{} @@ -55,6 +59,18 @@ func (o *GetShareMetricsURL) Build() (*url.URL, error) { } _result.Path = golangswaggerpaths.Join(_basePath, _path) + qs := make(url.Values) + + var durationQ string + if o.Duration != nil { + durationQ = swag.FormatFloat64(*o.Duration) + } + if durationQ != "" { + qs.Set("duration", durationQ) + } + + _result.RawQuery = qs.Encode() + return &_result, nil } diff --git a/specs/zrok.yml b/specs/zrok.yml index ffe081b8..7c9f97fc 100644 --- a/specs/zrok.yml +++ b/specs/zrok.yml @@ -415,6 +415,10 @@ paths: security: - key: [] operationId: getAccountMetrics + parameters: + - name: duration + in: query + type: number responses: 200: description: account metrics @@ -433,6 +437,9 @@ paths: in: path type: string required: true + - name: duration + in: query + type: number responses: 200: description: environment metrics @@ -453,6 +460,9 @@ paths: in: path type: string required: true + - name: duration + in: query + type: number responses: 200: description: share metrics diff --git a/ui/src/api/metrics.js b/ui/src/api/metrics.js index 5c1111dd..cc0063de 100644 --- a/ui/src/api/metrics.js +++ b/ui/src/api/metrics.js @@ -3,19 +3,34 @@ import * as gateway from './gateway' /** + * @param {object} options Optional options + * @param {number} [options.duration] + * @return {Promise} account metrics */ -export function getAccountMetrics() { - return gateway.request(getAccountMetricsOperation) +export function getAccountMetrics(options) { + if (!options) options = {} + const parameters = { + query: { + duration: options.duration + } + } + return gateway.request(getAccountMetricsOperation, parameters) } /** * @param {string} envId + * @param {object} options Optional options + * @param {number} [options.duration] * @return {Promise} environment metrics */ -export function getEnvironmentMetrics(envId) { +export function getEnvironmentMetrics(envId, options) { + if (!options) options = {} const parameters = { path: { envId + }, + query: { + duration: options.duration } } return gateway.request(getEnvironmentMetricsOperation, parameters) @@ -23,12 +38,18 @@ export function getEnvironmentMetrics(envId) { /** * @param {string} shrToken + * @param {object} options Optional options + * @param {number} [options.duration] * @return {Promise} share metrics */ -export function getShareMetrics(shrToken) { +export function getShareMetrics(shrToken, options) { + if (!options) options = {} const parameters = { path: { shrToken + }, + query: { + duration: options.duration } } return gateway.request(getShareMetricsOperation, parameters) diff --git a/ui/src/console/detail/environment/SharesTab.js b/ui/src/console/detail/environment/SharesTab.js index e902529c..6fb01439 100644 --- a/ui/src/console/detail/environment/SharesTab.js +++ b/ui/src/console/detail/environment/SharesTab.js @@ -46,7 +46,7 @@ const SharesTab = (props) => { cell: row => { return - v} stroke={"#231069"} fillOpacity={1} fill={"#655796"} isAnimationActive={false} dot={false} /> + v} stroke={"#777"} fillOpacity={0.5} fill={"#04adef"} isAnimationActive={false} dot={false} /> } diff --git a/ui/src/console/detail/share/ShareDetail.js b/ui/src/console/detail/share/ShareDetail.js index 78371e1f..31501afc 100644 --- a/ui/src/console/detail/share/ShareDetail.js +++ b/ui/src/console/detail/share/ShareDetail.js @@ -42,7 +42,7 @@ const ShareDetail = (props) => { metrics: row => ( - v} stroke={"#231069"} fillOpacity={1} fill={"#655796"} isAnimationActive={false} dot={false} /> + v} stroke={"#777"} fillOpacity={0.5} fill={"#04adef"} isAnimationActive={false} dot={false} /> ), diff --git a/ui/src/console/visualizer/Network.js b/ui/src/console/visualizer/Network.js index 3de59eb9..c75421c4 100644 --- a/ui/src/console/visualizer/Network.js +++ b/ui/src/console/visualizer/Network.js @@ -21,8 +21,8 @@ const Network = (props) => { }, []); const paintNode = (node, ctx) => { - let nodeColor = node.selected ? "#04adef" : "#9BF316"; - let textColor = node.selected ? "white" : "black"; + let nodeColor = node.selected ? "#9BF316" : "#04adef"; + let textColor = node.selected ? "black" : "white"; ctx.textBaseline = "middle"; ctx.textAlign = "center"; diff --git a/ui/src/console/visualizer/graph.js b/ui/src/console/visualizer/graph.js index 4e068555..7a445081 100644 --- a/ui/src/console/visualizer/graph.js +++ b/ui/src/console/visualizer/graph.js @@ -40,7 +40,7 @@ export const mergeGraph = (oldGraph, user, newOverview) => { newGraph.links.push({ target: accountNode.id, source: envNode.id, - color: "#9BF316" + color: "#04adef" }); if(env.shares) { env.shares.forEach(shr => { @@ -60,7 +60,7 @@ export const mergeGraph = (oldGraph, user, newOverview) => { newGraph.links.push({ target: envNode.id, source: shrNode.id, - color: "#9BF316" + color: "#04adef" }); }); }