From dbe7ff99566e3fe185a98a287124a327debf696f Mon Sep 17 00:00:00 2001 From: Bram Schuur Date: Thu, 11 Sep 2025 14:38:34 +0200 Subject: [PATCH] STAC-23353: Make topology sync metrics work --- cmd/health/health_status.go | 45 +--- cmd/topologysync/topologysync_describe.go | 12 + generated/stackstate_api/README.md | 1 - generated/stackstate_api/api/openapi.yaml | 79 ++----- .../api_topology_synchronization.go | 213 ------------------ .../TopologyStreamListItemWithErrorDetails.md | 26 +++ .../docs/TopologySynchronizationApi.md | 67 ------ ...ogy_stream_list_item_with_error_details.go | 36 +++ internal/printer/metrics.go | 32 +++ stackstate_openapi/openapi_version | 2 +- 10 files changed, 140 insertions(+), 373 deletions(-) create mode 100644 internal/printer/metrics.go diff --git a/cmd/health/health_status.go b/cmd/health/health_status.go index b6c0db30..055606a9 100644 --- a/cmd/health/health_status.go +++ b/cmd/health/health_status.go @@ -118,39 +118,14 @@ func RunStreamStatus(cli *di.Deps, api *stackstate_api.APIClient, args *StatusAr return nil } -func metricValueOrDash(bucket []stackstate_api.MetricBucketValue, index int) interface{} { - if index < len(bucket) && bucket[index].HasValue() { - return bucket[index].GetValue() - } - return "-" -} - -func metricBucketToJson(name string, bucket []stackstate_api.MetricBucketValue, size int32) map[string]interface{} { - return map[string]interface{}{ - "name": name, - fmt.Sprintf("now-%d", size): metricValueOrDash(bucket, 0), - fmt.Sprintf("%d-%d", size, 2*size): metricValueOrDash(bucket, 1), //nolint:mnd - fmt.Sprintf("%d-%d", 2*size, 3*size): metricValueOrDash(bucket, 2), //nolint:mnd - } -} - func streamMetricsToJson(metrics stackstate_api.HealthStreamMetrics) []map[string]interface{} { size := metrics.BucketSizeSeconds return []map[string]interface{}{ - metricBucketToJson("latency seconds", metrics.LatencySeconds, size), - metricBucketToJson("messages per seconds", metrics.MessagePerSecond, size), - metricBucketToJson("creates per seconds", metrics.CreatesPerSecond, size), - metricBucketToJson("updates per seconds", metrics.UpdatesPerSecond, size), - metricBucketToJson("deletes per seconds", metrics.DeletesPerSecond, size), - } -} - -func metricBucketToRow(name string, bucket []stackstate_api.MetricBucketValue) []interface{} { - return []interface{}{ - name, - metricValueOrDash(bucket, 0), - metricValueOrDash(bucket, 1), - metricValueOrDash(bucket, 2), //nolint:mnd + printer.MetricBucketToJson("latency seconds", metrics.LatencySeconds, size), + printer.MetricBucketToJson("messages per seconds", metrics.MessagePerSecond, size), + printer.MetricBucketToJson("creates per seconds", metrics.CreatesPerSecond, size), + printer.MetricBucketToJson("updates per seconds", metrics.UpdatesPerSecond, size), + printer.MetricBucketToJson("deletes per seconds", metrics.DeletesPerSecond, size), } } @@ -159,11 +134,11 @@ func streamMetricsToTable(metrics stackstate_api.HealthStreamMetrics) printer.Ta return printer.TableData{ Header: []string{"Metric", fmt.Sprintf("%ds ago", size), fmt.Sprintf("%d-%ds ago", size, 2*size), fmt.Sprintf("%d-%ds ago", 2*size, 3*size)}, //nolint:mnd Data: [][]interface{}{ - metricBucketToRow("latency seconds", metrics.LatencySeconds), - metricBucketToRow("messages per seconds", metrics.MessagePerSecond), - metricBucketToRow("creates per seconds", metrics.CreatesPerSecond), - metricBucketToRow("updates per seconds", metrics.UpdatesPerSecond), - metricBucketToRow("deletes per seconds", metrics.DeletesPerSecond), + printer.MetricBucketToRow("latency seconds", metrics.LatencySeconds), + printer.MetricBucketToRow("messages per seconds", metrics.MessagePerSecond), + printer.MetricBucketToRow("creates per seconds", metrics.CreatesPerSecond), + printer.MetricBucketToRow("updates per seconds", metrics.UpdatesPerSecond), + printer.MetricBucketToRow("deletes per seconds", metrics.DeletesPerSecond), }, MissingTableDataMsg: printer.NotFoundMsg{Types: "metrics"}, } diff --git a/cmd/topologysync/topologysync_describe.go b/cmd/topologysync/topologysync_describe.go index 5f1571d8..df8d5c85 100644 --- a/cmd/topologysync/topologysync_describe.go +++ b/cmd/topologysync/topologysync_describe.go @@ -72,6 +72,18 @@ func RunDescribeCommand(args *DescribeArgs) di.CmdWithApiFn { sync.Item, })) + if sync.Metrics != nil { + cli.Printer.PrintLn("\nTopology Synchronization Metrics:") + size := sync.Metrics.BucketSizeSeconds + cli.Printer.Table(printer.TableData{ + Header: []string{"Metric", fmt.Sprintf("%ds ago", size), fmt.Sprintf("%d-%ds ago", size, 2*size), fmt.Sprintf("%d-%ds ago", 2*size, 3*size)}, //nolint:mnd + Data: [][]interface{}{ + printer.MetricBucketToRow("latency seconds", sync.Metrics.LatencySeconds), + }, + MissingTableDataMsg: printer.NotFoundMsg{Types: "metrics"}, + }) + } + data := make([][]interface{}, len(sync.ErrorDetails)) for i, error := range sync.ErrorDetails { id := "-" diff --git a/generated/stackstate_api/README.md b/generated/stackstate_api/README.md index fe185961..2d7ca968 100644 --- a/generated/stackstate_api/README.md +++ b/generated/stackstate_api/README.md @@ -217,7 +217,6 @@ Class | Method | HTTP request | Description *TopicApi* | [**Describe**](docs/TopicApi.md#describe) | **Get** /topic/{topic} | Describe a topic *TopicApi* | [**List**](docs/TopicApi.md#list) | **Get** /topic | List topics *TopologySynchronizationApi* | [**GetTopologySynchronizationStreamById**](docs/TopologySynchronizationApi.md#gettopologysynchronizationstreambyid) | **Get** /synchronization/topology/streams/sync | Overview of a specific Topology Stream, queried by node id or sync identifier -*TopologySynchronizationApi* | [**GetTopologySynchronizationStreamStatusById**](docs/TopologySynchronizationApi.md#gettopologysynchronizationstreamstatusbyid) | **Get** /synchronization/topology/streams/status | Metrics of a specific Topology Stream, queried by node id *TopologySynchronizationApi* | [**GetTopologySynchronizationStreams**](docs/TopologySynchronizationApi.md#gettopologysynchronizationstreams) | **Get** /synchronization/topology/streams | Overview of the topology synchronization streams *TopologySynchronizationApi* | [**PostTopologySynchronizationStreamClearErrors**](docs/TopologySynchronizationApi.md#posttopologysynchronizationstreamclearerrors) | **Post** /synchronization/topology/streams/clearErrors | Clear all the errors related to a specific sync *TracesApi* | [**GetSpan**](docs/TracesApi.md#getspan) | **Get** /traces/{traceId}/spans/{spanId} | Get a span diff --git a/generated/stackstate_api/api/openapi.yaml b/generated/stackstate_api/api/openapi.yaml index fac6b272..02cdf818 100644 --- a/generated/stackstate_api/api/openapi.yaml +++ b/generated/stackstate_api/api/openapi.yaml @@ -3402,46 +3402,6 @@ paths: required: true schema: $ref: '#/components/schemas/IdentifierType' - /synchronization/topology/streams/status: - get: - description: "Metrics of a specific Topology Stream, queried by node id" - operationId: getTopologySynchronizationStreamStatusById - parameters: - - allowReserved: true - in: query - name: identifier - required: true - schema: - type: string - responses: - "200": - content: - application/json: - schema: - $ref: '#/components/schemas/TopologyStreamMetrics' - description: A specific topology stream metrics - "400": - content: - application/json: - schema: - $ref: '#/components/schemas/InvalidSyncIdentifier' - description: Bad request when specifying an invalid identifier - "404": - content: - application/json: - schema: - $ref: '#/components/schemas/TopologySyncError' - description: Sync with given identifier not found - summary: "Metrics of a specific Topology Stream, queried by node id" - tags: - - topologySynchronization - parameters: - - allowReserved: true - in: query - name: identifier - required: true - schema: - type: string /synchronization/topology/streams/clearErrors: parameters: - allowReserved: true @@ -10230,6 +10190,11 @@ components: errors: 2 createdComponents: 5 status: null + metrics: + latencySeconds: + - value: 5.637376656633329 + - value: 5.637376656633329 + bucketSizeSeconds: 0 errorDetails: - level: null externalId: externalId @@ -10244,6 +10209,8 @@ components: items: $ref: '#/components/schemas/TopologyStreamError' type: array + metrics: + $ref: '#/components/schemas/TopologyStreamMetrics' required: - errorDetails - item @@ -10268,6 +10235,22 @@ components: - level - message type: object + TopologyStreamMetrics: + example: + latencySeconds: + - value: 5.637376656633329 + - value: 5.637376656633329 + bucketSizeSeconds: 0 + properties: + bucketSizeSeconds: + type: integer + latencySeconds: + items: + $ref: '#/components/schemas/MetricBucketValue' + type: array + required: + - bucketSizeSeconds + type: object IdentifierType: enum: - NodeId @@ -10287,22 +10270,6 @@ components: required: - message type: object - TopologyStreamMetrics: - example: - latencySeconds: - - value: 5.637376656633329 - - value: 5.637376656633329 - bucketSizeSeconds: 0 - properties: - bucketSizeSeconds: - type: integer - latencySeconds: - items: - $ref: '#/components/schemas/MetricBucketValue' - type: array - required: - - bucketSizeSeconds - type: object ExecuteScriptResponse: example: result: "{}" diff --git a/generated/stackstate_api/api_topology_synchronization.go b/generated/stackstate_api/api_topology_synchronization.go index e16bfae1..90b8fad2 100644 --- a/generated/stackstate_api/api_topology_synchronization.go +++ b/generated/stackstate_api/api_topology_synchronization.go @@ -35,20 +35,6 @@ type TopologySynchronizationApi interface { // @return TopologyStreamListItemWithErrorDetails GetTopologySynchronizationStreamByIdExecute(r ApiGetTopologySynchronizationStreamByIdRequest) (*TopologyStreamListItemWithErrorDetails, *http.Response, error) - /* - GetTopologySynchronizationStreamStatusById Metrics of a specific Topology Stream, queried by node id - - Metrics of a specific Topology Stream, queried by node id - - @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). - @return ApiGetTopologySynchronizationStreamStatusByIdRequest - */ - GetTopologySynchronizationStreamStatusById(ctx context.Context) ApiGetTopologySynchronizationStreamStatusByIdRequest - - // GetTopologySynchronizationStreamStatusByIdExecute executes the request - // @return TopologyStreamMetrics - GetTopologySynchronizationStreamStatusByIdExecute(r ApiGetTopologySynchronizationStreamStatusByIdRequest) (*TopologyStreamMetrics, *http.Response, error) - /* GetTopologySynchronizationStreams Overview of the topology synchronization streams @@ -260,176 +246,6 @@ func (a *TopologySynchronizationApiService) GetTopologySynchronizationStreamById return localVarReturnValue, localVarHTTPResponse, nil } -type ApiGetTopologySynchronizationStreamStatusByIdRequest struct { - ctx context.Context - ApiService TopologySynchronizationApi - identifier *string -} - -func (r ApiGetTopologySynchronizationStreamStatusByIdRequest) Identifier(identifier string) ApiGetTopologySynchronizationStreamStatusByIdRequest { - r.identifier = &identifier - return r -} - -func (r ApiGetTopologySynchronizationStreamStatusByIdRequest) Execute() (*TopologyStreamMetrics, *http.Response, error) { - return r.ApiService.GetTopologySynchronizationStreamStatusByIdExecute(r) -} - -/* -GetTopologySynchronizationStreamStatusById Metrics of a specific Topology Stream, queried by node id - -Metrics of a specific Topology Stream, queried by node id - - @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). - @return ApiGetTopologySynchronizationStreamStatusByIdRequest -*/ -func (a *TopologySynchronizationApiService) GetTopologySynchronizationStreamStatusById(ctx context.Context) ApiGetTopologySynchronizationStreamStatusByIdRequest { - return ApiGetTopologySynchronizationStreamStatusByIdRequest{ - ApiService: a, - ctx: ctx, - } -} - -// Execute executes the request -// @return TopologyStreamMetrics -func (a *TopologySynchronizationApiService) GetTopologySynchronizationStreamStatusByIdExecute(r ApiGetTopologySynchronizationStreamStatusByIdRequest) (*TopologyStreamMetrics, *http.Response, error) { - var ( - localVarHTTPMethod = http.MethodGet - localVarPostBody interface{} - formFiles []formFile - localVarReturnValue *TopologyStreamMetrics - ) - - localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "TopologySynchronizationApiService.GetTopologySynchronizationStreamStatusById") - if err != nil { - return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} - } - - localVarPath := localBasePath + "/synchronization/topology/streams/status" - - localVarHeaderParams := make(map[string]string) - localVarQueryParams := url.Values{} - localVarFormParams := url.Values{} - if r.identifier == nil { - return localVarReturnValue, nil, reportError("identifier is required and must be specified") - } - - localVarQueryParams.Add("identifier", parameterToString(*r.identifier, "")) - // to determine the Content-Type header - localVarHTTPContentTypes := []string{} - - // set Content-Type header - localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) - if localVarHTTPContentType != "" { - localVarHeaderParams["Content-Type"] = localVarHTTPContentType - } - - // to determine the Accept header - localVarHTTPHeaderAccepts := []string{"application/json"} - - // set Accept header - localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) - if localVarHTTPHeaderAccept != "" { - localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept - } - if r.ctx != nil { - // API Key Authentication - if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { - if apiKey, ok := auth["ApiToken"]; ok { - var key string - if apiKey.Prefix != "" { - key = apiKey.Prefix + " " + apiKey.Key - } else { - key = apiKey.Key - } - localVarHeaderParams["X-API-Token"] = key - } - } - } - if r.ctx != nil { - // API Key Authentication - if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { - if apiKey, ok := auth["ServiceBearer"]; ok { - var key string - if apiKey.Prefix != "" { - key = apiKey.Prefix + " " + apiKey.Key - } else { - key = apiKey.Key - } - localVarHeaderParams["X-API-ServiceBearer"] = key - } - } - } - if r.ctx != nil { - // API Key Authentication - if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { - if apiKey, ok := auth["ServiceToken"]; ok { - var key string - if apiKey.Prefix != "" { - key = apiKey.Prefix + " " + apiKey.Key - } else { - key = apiKey.Key - } - localVarHeaderParams["X-API-Key"] = key - } - } - } - req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) - if err != nil { - return localVarReturnValue, nil, err - } - - localVarHTTPResponse, err := a.client.callAPI(req) - if err != nil || localVarHTTPResponse == nil { - return localVarReturnValue, localVarHTTPResponse, err - } - - localVarBody, err := ioutil.ReadAll(localVarHTTPResponse.Body) - localVarHTTPResponse.Body.Close() - localVarHTTPResponse.Body = ioutil.NopCloser(bytes.NewBuffer(localVarBody)) - if err != nil { - return localVarReturnValue, localVarHTTPResponse, err - } - - if localVarHTTPResponse.StatusCode >= 300 { - newErr := &GenericOpenAPIError{ - body: localVarBody, - error: localVarHTTPResponse.Status, - } - if localVarHTTPResponse.StatusCode == 400 { - var v InvalidSyncIdentifier - err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) - if err != nil { - newErr.error = err.Error() - return localVarReturnValue, localVarHTTPResponse, newErr - } - newErr.model = v - return localVarReturnValue, localVarHTTPResponse, newErr - } - if localVarHTTPResponse.StatusCode == 404 { - var v TopologySyncError - err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) - if err != nil { - newErr.error = err.Error() - return localVarReturnValue, localVarHTTPResponse, newErr - } - newErr.model = v - } - return localVarReturnValue, localVarHTTPResponse, newErr - } - - err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) - if err != nil { - newErr := &GenericOpenAPIError{ - body: localVarBody, - error: err.Error(), - } - return localVarReturnValue, localVarHTTPResponse, newErr - } - - return localVarReturnValue, localVarHTTPResponse, nil -} - type ApiGetTopologySynchronizationStreamsRequest struct { ctx context.Context ApiService TopologySynchronizationApi @@ -747,8 +563,6 @@ func (a *TopologySynchronizationApiService) PostTopologySynchronizationStreamCle type TopologySynchronizationApiMock struct { GetTopologySynchronizationStreamByIdCalls *[]GetTopologySynchronizationStreamByIdCall GetTopologySynchronizationStreamByIdResponse GetTopologySynchronizationStreamByIdMockResponse - GetTopologySynchronizationStreamStatusByIdCalls *[]GetTopologySynchronizationStreamStatusByIdCall - GetTopologySynchronizationStreamStatusByIdResponse GetTopologySynchronizationStreamStatusByIdMockResponse GetTopologySynchronizationStreamsCalls *[]GetTopologySynchronizationStreamsCall GetTopologySynchronizationStreamsResponse GetTopologySynchronizationStreamsMockResponse PostTopologySynchronizationStreamClearErrorsCalls *[]PostTopologySynchronizationStreamClearErrorsCall @@ -757,12 +571,10 @@ type TopologySynchronizationApiMock struct { func NewTopologySynchronizationApiMock() TopologySynchronizationApiMock { xGetTopologySynchronizationStreamByIdCalls := make([]GetTopologySynchronizationStreamByIdCall, 0) - xGetTopologySynchronizationStreamStatusByIdCalls := make([]GetTopologySynchronizationStreamStatusByIdCall, 0) xGetTopologySynchronizationStreamsCalls := make([]GetTopologySynchronizationStreamsCall, 0) xPostTopologySynchronizationStreamClearErrorsCalls := make([]PostTopologySynchronizationStreamClearErrorsCall, 0) return TopologySynchronizationApiMock{ GetTopologySynchronizationStreamByIdCalls: &xGetTopologySynchronizationStreamByIdCalls, - GetTopologySynchronizationStreamStatusByIdCalls: &xGetTopologySynchronizationStreamStatusByIdCalls, GetTopologySynchronizationStreamsCalls: &xGetTopologySynchronizationStreamsCalls, PostTopologySynchronizationStreamClearErrorsCalls: &xPostTopologySynchronizationStreamClearErrorsCalls, } @@ -795,31 +607,6 @@ func (mock TopologySynchronizationApiMock) GetTopologySynchronizationStreamByIdE return &mock.GetTopologySynchronizationStreamByIdResponse.Result, mock.GetTopologySynchronizationStreamByIdResponse.Response, mock.GetTopologySynchronizationStreamByIdResponse.Error } -type GetTopologySynchronizationStreamStatusByIdMockResponse struct { - Result TopologyStreamMetrics - Response *http.Response - Error error -} - -type GetTopologySynchronizationStreamStatusByIdCall struct { - Pidentifier *string -} - -func (mock TopologySynchronizationApiMock) GetTopologySynchronizationStreamStatusById(ctx context.Context) ApiGetTopologySynchronizationStreamStatusByIdRequest { - return ApiGetTopologySynchronizationStreamStatusByIdRequest{ - ApiService: mock, - ctx: ctx, - } -} - -func (mock TopologySynchronizationApiMock) GetTopologySynchronizationStreamStatusByIdExecute(r ApiGetTopologySynchronizationStreamStatusByIdRequest) (*TopologyStreamMetrics, *http.Response, error) { - p := GetTopologySynchronizationStreamStatusByIdCall{ - Pidentifier: r.identifier, - } - *mock.GetTopologySynchronizationStreamStatusByIdCalls = append(*mock.GetTopologySynchronizationStreamStatusByIdCalls, p) - return &mock.GetTopologySynchronizationStreamStatusByIdResponse.Result, mock.GetTopologySynchronizationStreamStatusByIdResponse.Response, mock.GetTopologySynchronizationStreamStatusByIdResponse.Error -} - type GetTopologySynchronizationStreamsMockResponse struct { Result TopologyStreamList Response *http.Response diff --git a/generated/stackstate_api/docs/TopologyStreamListItemWithErrorDetails.md b/generated/stackstate_api/docs/TopologyStreamListItemWithErrorDetails.md index 09ffd2cb..a1a5720f 100644 --- a/generated/stackstate_api/docs/TopologyStreamListItemWithErrorDetails.md +++ b/generated/stackstate_api/docs/TopologyStreamListItemWithErrorDetails.md @@ -6,6 +6,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **Item** | [**TopologyStreamListItem**](TopologyStreamListItem.md) | | **ErrorDetails** | [**[]TopologyStreamError**](TopologyStreamError.md) | | +**Metrics** | Pointer to [**TopologyStreamMetrics**](TopologyStreamMetrics.md) | | [optional] ## Methods @@ -66,6 +67,31 @@ and a boolean to check if the value has been set. SetErrorDetails sets ErrorDetails field to given value. +### GetMetrics + +`func (o *TopologyStreamListItemWithErrorDetails) GetMetrics() TopologyStreamMetrics` + +GetMetrics returns the Metrics field if non-nil, zero value otherwise. + +### GetMetricsOk + +`func (o *TopologyStreamListItemWithErrorDetails) GetMetricsOk() (*TopologyStreamMetrics, bool)` + +GetMetricsOk returns a tuple with the Metrics field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetMetrics + +`func (o *TopologyStreamListItemWithErrorDetails) SetMetrics(v TopologyStreamMetrics)` + +SetMetrics sets Metrics field to given value. + +### HasMetrics + +`func (o *TopologyStreamListItemWithErrorDetails) HasMetrics() bool` + +HasMetrics returns a boolean if a field has been set. + [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/generated/stackstate_api/docs/TopologySynchronizationApi.md b/generated/stackstate_api/docs/TopologySynchronizationApi.md index 469035ed..bf5a0f1a 100644 --- a/generated/stackstate_api/docs/TopologySynchronizationApi.md +++ b/generated/stackstate_api/docs/TopologySynchronizationApi.md @@ -5,7 +5,6 @@ All URIs are relative to *http://localhost* Method | HTTP request | Description ------------- | ------------- | ------------- [**GetTopologySynchronizationStreamById**](TopologySynchronizationApi.md#GetTopologySynchronizationStreamById) | **Get** /synchronization/topology/streams/sync | Overview of a specific Topology Stream, queried by node id or sync identifier -[**GetTopologySynchronizationStreamStatusById**](TopologySynchronizationApi.md#GetTopologySynchronizationStreamStatusById) | **Get** /synchronization/topology/streams/status | Metrics of a specific Topology Stream, queried by node id [**GetTopologySynchronizationStreams**](TopologySynchronizationApi.md#GetTopologySynchronizationStreams) | **Get** /synchronization/topology/streams | Overview of the topology synchronization streams [**PostTopologySynchronizationStreamClearErrors**](TopologySynchronizationApi.md#PostTopologySynchronizationStreamClearErrors) | **Post** /synchronization/topology/streams/clearErrors | Clear all the errors related to a specific sync @@ -79,72 +78,6 @@ Name | Type | Description | Notes [[Back to README]](../README.md) -## GetTopologySynchronizationStreamStatusById - -> TopologyStreamMetrics GetTopologySynchronizationStreamStatusById(ctx).Identifier(identifier).Execute() - -Metrics of a specific Topology Stream, queried by node id - - - -### Example - -```go -package main - -import ( - "context" - "fmt" - "os" - openapiclient "./openapi" -) - -func main() { - identifier := "identifier_example" // string | - - configuration := openapiclient.NewConfiguration() - apiClient := openapiclient.NewAPIClient(configuration) - resp, r, err := apiClient.TopologySynchronizationApi.GetTopologySynchronizationStreamStatusById(context.Background()).Identifier(identifier).Execute() - if err != nil { - fmt.Fprintf(os.Stderr, "Error when calling `TopologySynchronizationApi.GetTopologySynchronizationStreamStatusById``: %v\n", err) - fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) - } - // response from `GetTopologySynchronizationStreamStatusById`: TopologyStreamMetrics - fmt.Fprintf(os.Stdout, "Response from `TopologySynchronizationApi.GetTopologySynchronizationStreamStatusById`: %v\n", resp) -} -``` - -### Path Parameters - - - -### Other Parameters - -Other parameters are passed through a pointer to a apiGetTopologySynchronizationStreamStatusByIdRequest struct via the builder pattern - - -Name | Type | Description | Notes -------------- | ------------- | ------------- | ------------- - **identifier** | **string** | | - -### Return type - -[**TopologyStreamMetrics**](TopologyStreamMetrics.md) - -### Authorization - -[ApiToken](../README.md#ApiToken), [ServiceBearer](../README.md#ServiceBearer), [ServiceToken](../README.md#ServiceToken) - -### HTTP request headers - -- **Content-Type**: Not defined -- **Accept**: application/json - -[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) -[[Back to Model list]](../README.md#documentation-for-models) -[[Back to README]](../README.md) - - ## GetTopologySynchronizationStreams > TopologyStreamList GetTopologySynchronizationStreams(ctx).Execute() diff --git a/generated/stackstate_api/model_topology_stream_list_item_with_error_details.go b/generated/stackstate_api/model_topology_stream_list_item_with_error_details.go index a4a4221a..7b44251e 100644 --- a/generated/stackstate_api/model_topology_stream_list_item_with_error_details.go +++ b/generated/stackstate_api/model_topology_stream_list_item_with_error_details.go @@ -19,6 +19,7 @@ import ( type TopologyStreamListItemWithErrorDetails struct { Item TopologyStreamListItem `json:"item"` ErrorDetails []TopologyStreamError `json:"errorDetails"` + Metrics *TopologyStreamMetrics `json:"metrics,omitempty"` } // NewTopologyStreamListItemWithErrorDetails instantiates a new TopologyStreamListItemWithErrorDetails object @@ -88,6 +89,38 @@ func (o *TopologyStreamListItemWithErrorDetails) SetErrorDetails(v []TopologyStr o.ErrorDetails = v } +// GetMetrics returns the Metrics field value if set, zero value otherwise. +func (o *TopologyStreamListItemWithErrorDetails) GetMetrics() TopologyStreamMetrics { + if o == nil || o.Metrics == nil { + var ret TopologyStreamMetrics + return ret + } + return *o.Metrics +} + +// GetMetricsOk returns a tuple with the Metrics field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *TopologyStreamListItemWithErrorDetails) GetMetricsOk() (*TopologyStreamMetrics, bool) { + if o == nil || o.Metrics == nil { + return nil, false + } + return o.Metrics, true +} + +// HasMetrics returns a boolean if a field has been set. +func (o *TopologyStreamListItemWithErrorDetails) HasMetrics() bool { + if o != nil && o.Metrics != nil { + return true + } + + return false +} + +// SetMetrics gets a reference to the given TopologyStreamMetrics and assigns it to the Metrics field. +func (o *TopologyStreamListItemWithErrorDetails) SetMetrics(v TopologyStreamMetrics) { + o.Metrics = &v +} + func (o TopologyStreamListItemWithErrorDetails) MarshalJSON() ([]byte, error) { toSerialize := map[string]interface{}{} if true { @@ -96,6 +129,9 @@ func (o TopologyStreamListItemWithErrorDetails) MarshalJSON() ([]byte, error) { if true { toSerialize["errorDetails"] = o.ErrorDetails } + if o.Metrics != nil { + toSerialize["metrics"] = o.Metrics + } return json.Marshal(toSerialize) } diff --git a/internal/printer/metrics.go b/internal/printer/metrics.go new file mode 100644 index 00000000..94ea9179 --- /dev/null +++ b/internal/printer/metrics.go @@ -0,0 +1,32 @@ +package printer + +import ( + "fmt" + + "github.com/stackvista/stackstate-cli/generated/stackstate_api" +) + +func metricValueOrDash(bucket []stackstate_api.MetricBucketValue, index int) interface{} { + if index < len(bucket) && bucket[index].HasValue() { + return bucket[index].GetValue() + } + return "-" +} + +func MetricBucketToJson(name string, bucket []stackstate_api.MetricBucketValue, size int32) map[string]interface{} { + return map[string]interface{}{ + "name": name, + fmt.Sprintf("now-%d", size): metricValueOrDash(bucket, 0), + fmt.Sprintf("%d-%d", size, 2*size): metricValueOrDash(bucket, 1), //nolint:mnd + fmt.Sprintf("%d-%d", 2*size, 3*size): metricValueOrDash(bucket, 2), //nolint:mnd + } +} + +func MetricBucketToRow(name string, bucket []stackstate_api.MetricBucketValue) []interface{} { + return []interface{}{ + name, + metricValueOrDash(bucket, 0), + metricValueOrDash(bucket, 1), + metricValueOrDash(bucket, 2), //nolint:mnd + } +} diff --git a/stackstate_openapi/openapi_version b/stackstate_openapi/openapi_version index 59c271cc..46e4653b 100644 --- a/stackstate_openapi/openapi_version +++ b/stackstate_openapi/openapi_version @@ -1 +1 @@ -674af5775997226a77151f9ef90cc9d6ef95c7eb +e53e53b60b43d118b823b297ec01807434d7eaad