Skip to content

Commit ed1ba38

Browse files
committed
STAC-24149: process feedback
Remove 'View' from schema names and drop viewId from request/response
1 parent 32fab4f commit ed1ba38

File tree

12 files changed

+141
-314
lines changed

12 files changed

+141
-314
lines changed

cmd/topology/topology_inspect.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ func RunInspectCommand(
8686
true,
8787
)
8888

89-
request := stackstate_api.NewViewSnapshotRequest(
90-
"ViewSnapshotRequest",
89+
request := stackstate_api.NewSnapshotRequest(
90+
"SnapshotRequest",
9191
query,
9292
"0.0.1",
9393
*metadata,
9494
)
9595

9696
result, resp, err := api.SnapshotApi.QuerySnapshot(cli.Context).
97-
ViewSnapshotRequest(*request).
97+
SnapshotRequest(*request).
9898
Execute()
9999
if err != nil {
100100
return common.NewResponseError(err, resp)
@@ -104,7 +104,7 @@ func RunInspectCommand(
104104
components, parseErr := parseSnapshotResponse(result, cli.CurrentContext.URL)
105105
if parseErr != nil {
106106
// Check if the error is a typed error from the response by examining the _type discriminator
107-
if typedErr := handleViewSnapshotError(result.ViewSnapshotResponse, resp); typedErr != nil {
107+
if typedErr := handleSnapshotError(result.SnapshotResponse, resp); typedErr != nil {
108108
return typedErr
109109
}
110110
return common.NewExecutionError(parseErr)
@@ -166,8 +166,8 @@ type ComponentMetadata struct {
166166
Environments map[int64]string
167167
}
168168

169-
// handleViewSnapshotError checks if the response is a typed error by examining the _type discriminator
170-
func handleViewSnapshotError(respMap map[string]interface{}, resp *http.Response) common.CLIError {
169+
// handleSnapshotError checks if the response is a typed error by examining the _type discriminator
170+
func handleSnapshotError(respMap map[string]interface{}, resp *http.Response) common.CLIError {
171171
if respMap == nil {
172172
return nil
173173
}
@@ -177,6 +177,7 @@ func handleViewSnapshotError(respMap map[string]interface{}, resp *http.Response
177177
return nil
178178
}
179179

180+
// Note: the `View` prefix on the error types comes from the existing (Scala) DTO types
180181
switch responseType {
181182
case "ViewSnapshotFetchTimeout":
182183
if usedTimeoutSeconds, ok := respMap["usedTimeoutSeconds"].(float64); ok {
@@ -217,18 +218,19 @@ func parseSnapshotResponse(
217218
result *stackstate_api.QuerySnapshotResult,
218219
baseURL string,
219220
) ([]Component, error) {
220-
// ViewSnapshotResponse is already typed as map[string]interface{} from the generated API
221-
respMap := result.ViewSnapshotResponse
221+
// SnapshotResponse is already typed as map[string]interface{} from the generated API
222+
respMap := result.SnapshotResponse
222223
if respMap == nil {
223224
return nil, fmt.Errorf("response data is nil")
224225
}
225226

226-
// Check if this is a ViewSnapshot (success) or an error type
227+
// Check if this is a Snapshot (success) or an error type
227228
respType, ok := respMap["_type"].(string)
228229
if !ok {
229230
return nil, fmt.Errorf("response has no _type discriminator")
230231
}
231232

233+
// Note: the `View` prefix on response type comes from the existing (Scala) DTO types
232234
// If it's not a ViewSnapshot, it's an error type - return empty components and let error handler deal with it
233235
if respType != "ViewSnapshot" {
234236
return nil, fmt.Errorf("response is an error type: %s", respType)
@@ -263,7 +265,7 @@ var metadataFieldMapping = []struct {
263265
}
264266

265267
// parseMetadata extracts component type, layer, domain, and environment metadata
266-
// from the opaque ViewSnapshot response using a table-driven approach.
268+
// from the opaque Snapshot response using a table-driven approach.
267269
func parseMetadata(respMap map[string]interface{}) ComponentMetadata {
268270
metadata := ComponentMetadata{
269271
ComponentTypes: make(map[int64]string),

cmd/topology/topology_inspect_test.go

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func setInspectCmd(t *testing.T) (*di.MockDeps, *cobra.Command) {
2121
func mockSnapshotResponse() sts.QuerySnapshotResult {
2222
return sts.QuerySnapshotResult{
2323
Type: "QuerySnapshotResult",
24-
ViewSnapshotResponse: map[string]interface{}{
24+
SnapshotResponse: map[string]interface{}{
2525
"_type": "ViewSnapshot",
2626
"components": []interface{}{
2727
map[string]interface{}{
@@ -121,7 +121,7 @@ func TestTopologyInspectWithTags(t *testing.T) {
121121

122122
// Verify query contains both tags ANDed
123123
call := calls[0]
124-
request := call.PviewSnapshotRequest
124+
request := call.PsnapshotRequest
125125
expectedQuery := `type = "test type" AND label = "service.namespace:test" AND label = "service.name:myservice"`
126126
assert.Equal(t, expectedQuery, request.Query)
127127
}
@@ -141,7 +141,7 @@ func TestTopologyInspectWithIdentifiers(t *testing.T) {
141141

142142
// Verify query contains identifiers in IN clause
143143
call := calls[0]
144-
request := call.PviewSnapshotRequest
144+
request := call.PsnapshotRequest
145145
expectedQuery := `type = "test type" AND identifier IN ("urn:test:1", "urn:test:2")`
146146
assert.Equal(t, expectedQuery, request.Query)
147147
}
@@ -150,7 +150,7 @@ func TestTopologyInspectNoResults(t *testing.T) {
150150
cli, cmd := setInspectCmd(t)
151151
cli.MockClient.ApiMocks.SnapshotApi.QuerySnapshotResponse.Result = sts.QuerySnapshotResult{
152152
Type: "QuerySnapshotResult",
153-
ViewSnapshotResponse: map[string]interface{}{
153+
SnapshotResponse: map[string]interface{}{
154154
"_type": "ViewSnapshot",
155155
"components": []interface{}{},
156156
"metadata": map[string]interface{}{
@@ -178,7 +178,7 @@ func TestTopologyInspectMultipleIdentifiers(t *testing.T) {
178178
cli, cmd := setInspectCmd(t)
179179
responseData := mockSnapshotResponse()
180180
// Modify to include multiple identifiers
181-
components := responseData.ViewSnapshotResponse["components"].([]interface{})
181+
components := responseData.SnapshotResponse["components"].([]interface{})
182182
comp := components[0].(map[string]interface{})
183183
comp["identifiers"] = []interface{}{"urn:test:1", "urn:test:2", "urn:test:3"}
184184
cli.MockClient.ApiMocks.SnapshotApi.QuerySnapshotResponse.Result = responseData
@@ -199,7 +199,7 @@ func TestTopologyInspectURLEncoding(t *testing.T) {
199199
cli, cmd := setInspectCmd(t)
200200
responseData := mockSnapshotResponse()
201201
// Set identifier with special characters
202-
components := responseData.ViewSnapshotResponse["components"].([]interface{})
202+
components := responseData.SnapshotResponse["components"].([]interface{})
203203
comp := components[0].(map[string]interface{})
204204
comp["identifiers"] = []interface{}{"urn:opentelemetry:namespace/service:component/name"}
205205
cli.MockClient.ApiMocks.SnapshotApi.QuerySnapshotResponse.Result = responseData
@@ -219,11 +219,11 @@ func TestTopologyInspectWithEnvironment(t *testing.T) {
219219
cli, cmd := setInspectCmd(t)
220220
responseData := mockSnapshotResponse()
221221
// Add environment to component
222-
components := responseData.ViewSnapshotResponse["components"].([]interface{})
222+
components := responseData.SnapshotResponse["components"].([]interface{})
223223
comp := components[0].(map[string]interface{})
224224
comp["environment"] = float64(123)
225225
// Add environment to metadata
226-
metadata := responseData.ViewSnapshotResponse["metadata"].(map[string]interface{})
226+
metadata := responseData.SnapshotResponse["metadata"].(map[string]interface{})
227227
metadata["environments"] = []interface{}{
228228
map[string]interface{}{
229229
"id": float64(123),
@@ -273,23 +273,26 @@ func TestTopologyInspectWithBaseURL(t *testing.T) {
273273
cli.MockClient.ApiMocks.SnapshotApi.QuerySnapshotResponse.Result = mockSnapshotResponse()
274274
cli.CurrentContext.URL = "https://stackstate.example.com:8080"
275275

276-
di.ExecuteCommandWithContextUnsafe(&cli.Deps, cmd, "--type", "test type")
276+
di.ExecuteCommandWithContextUnsafe(&cli.Deps, cmd, "--type", "test type", "-o", "json")
277277

278278
// Verify base URL is included in the link
279-
tableCalls := *cli.MockPrinter.TableCalls
280-
assert.Len(t, tableCalls, 1)
279+
jsonCalls := *cli.MockPrinter.PrintJsonCalls
280+
assert.Len(t, jsonCalls, 1)
281+
282+
jsonData := jsonCalls[0]
283+
// Components are serialized from []Component struct
284+
components := jsonData["components"].([]Component)
285+
assert.NotNil(t, components)
281286

282-
table := tableCalls[0]
283-
row := table.Data[0]
284287
expectedLink := "https://stackstate.example.com:8080/#/components/urn:test:component:1"
285-
assert.Equal(t, expectedLink, row[3])
288+
assert.Equal(t, expectedLink, components[0].Link)
286289
}
287290

288291
func TestTopologyInspectFetchTimeout(t *testing.T) {
289292
cli, cmd := setInspectCmd(t)
290293
cli.MockClient.ApiMocks.SnapshotApi.QuerySnapshotResponse.Result = sts.QuerySnapshotResult{
291294
Type: "QuerySnapshotResult",
292-
ViewSnapshotResponse: map[string]interface{}{
295+
SnapshotResponse: map[string]interface{}{
293296
"_type": "ViewSnapshotFetchTimeout",
294297
"usedTimeoutSeconds": float64(30),
295298
},
@@ -307,7 +310,7 @@ func TestTopologyInspectTooManyActiveQueries(t *testing.T) {
307310
cli, cmd := setInspectCmd(t)
308311
cli.MockClient.ApiMocks.SnapshotApi.QuerySnapshotResponse.Result = sts.QuerySnapshotResult{
309312
Type: "QuerySnapshotResult",
310-
ViewSnapshotResponse: map[string]interface{}{
313+
SnapshotResponse: map[string]interface{}{
311314
"_type": "ViewSnapshotTooManyActiveQueries",
312315
},
313316
}
@@ -324,7 +327,7 @@ func TestTopologyInspectTopologySizeOverflow(t *testing.T) {
324327
cli, cmd := setInspectCmd(t)
325328
cli.MockClient.ApiMocks.SnapshotApi.QuerySnapshotResponse.Result = sts.QuerySnapshotResult{
326329
Type: "QuerySnapshotResult",
327-
ViewSnapshotResponse: map[string]interface{}{
330+
SnapshotResponse: map[string]interface{}{
328331
"_type": "ViewSnapshotTopologySizeOverflow",
329332
"maxSize": float64(10000),
330333
},
@@ -342,7 +345,7 @@ func TestTopologyInspectDataUnavailable(t *testing.T) {
342345
cli, cmd := setInspectCmd(t)
343346
cli.MockClient.ApiMocks.SnapshotApi.QuerySnapshotResponse.Result = sts.QuerySnapshotResult{
344347
Type: "QuerySnapshotResult",
345-
ViewSnapshotResponse: map[string]interface{}{
348+
SnapshotResponse: map[string]interface{}{
346349
"_type": "ViewSnapshotDataUnavailable",
347350
"unavailableAtEpochMs": float64(1000000),
348351
"availableSinceEpochMs": float64(1609459200000),

generated/stackstate_api/.openapi-generator/FILES

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ docs/SlackChannelsChunk.md
402402
docs/SlackNotificationChannel.md
403403
docs/SlackNotificationChannelAllOf.md
404404
docs/SnapshotApi.md
405+
docs/SnapshotRequest.md
405406
docs/SourceLink.md
406407
docs/Span.md
407408
docs/SpanComponent.md
@@ -497,7 +498,6 @@ docs/UserProfileApi.md
497498
docs/UserProfileSaveError.md
498499
docs/UserSessionApi.md
499500
docs/ViewCheckState.md
500-
docs/ViewSnapshotRequest.md
501501
docs/WebhookChannelRefId.md
502502
docs/WebhookChannelWriteSchema.md
503503
docs/WebhookNotificationChannel.md
@@ -837,6 +837,7 @@ model_slack_channel_ref_id.go
837837
model_slack_channels_chunk.go
838838
model_slack_notification_channel.go
839839
model_slack_notification_channel_all_of.go
840+
model_snapshot_request.go
840841
model_source_link.go
841842
model_span.go
842843
model_span_component.go
@@ -921,7 +922,6 @@ model_user_not_logged_in_error.go
921922
model_user_profile.go
922923
model_user_profile_save_error.go
923924
model_view_check_state.go
924-
model_view_snapshot_request.go
925925
model_webhook_channel_ref_id.go
926926
model_webhook_channel_write_schema.go
927927
model_webhook_notification_channel.go

generated/stackstate_api/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,7 @@ Class | Method | HTTP request | Description
587587
- [SlackChannelsChunk](docs/SlackChannelsChunk.md)
588588
- [SlackNotificationChannel](docs/SlackNotificationChannel.md)
589589
- [SlackNotificationChannelAllOf](docs/SlackNotificationChannelAllOf.md)
590+
- [SnapshotRequest](docs/SnapshotRequest.md)
590591
- [SourceLink](docs/SourceLink.md)
591592
- [Span](docs/Span.md)
592593
- [SpanComponent](docs/SpanComponent.md)
@@ -671,7 +672,6 @@ Class | Method | HTTP request | Description
671672
- [UserProfile](docs/UserProfile.md)
672673
- [UserProfileSaveError](docs/UserProfileSaveError.md)
673674
- [ViewCheckState](docs/ViewCheckState.md)
674-
- [ViewSnapshotRequest](docs/ViewSnapshotRequest.md)
675675
- [WebhookChannelRefId](docs/WebhookChannelRefId.md)
676676
- [WebhookChannelWriteSchema](docs/WebhookChannelWriteSchema.md)
677677
- [WebhookNotificationChannel](docs/WebhookNotificationChannel.md)

generated/stackstate_api/api/openapi.yaml

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6408,7 +6408,7 @@ paths:
64086408
format: int64
64096409
type: integer
64106410
requestBody:
6411-
$ref: '#/components/requestBodies/viewSnapshotRequest'
6411+
$ref: '#/components/requestBodies/SnapshotRequest'
64126412
responses:
64136413
"200":
64146414
content:
@@ -6608,11 +6608,11 @@ components:
66086608
$ref: '#/components/schemas/upsertOtelRelationMappings_request'
66096609
description: Otel Relation Mapping to create/update
66106610
required: true
6611-
viewSnapshotRequest:
6611+
SnapshotRequest:
66126612
content:
66136613
application/json:
66146614
schema:
6615-
$ref: '#/components/schemas/ViewSnapshotRequest'
6615+
$ref: '#/components/schemas/SnapshotRequest'
66166616
description: Request body for querying a topology snapshot
66176617
required: true
66186618
responses:
@@ -15348,7 +15348,7 @@ components:
1534815348
type: string
1534915349
required:
1535015350
- viewIdentifier
15351-
ViewSnapshotRequest:
15351+
SnapshotRequest:
1535215352
example:
1535315353
metadata:
1535415354
minGroupSize: 0
@@ -15362,14 +15362,13 @@ components:
1536215362
connectedComponents: true
1536315363
groupingEnabled: true
1536415364
groupedByDomain: true
15365-
viewId: 1
1536615365
query: query
15367-
_type: ViewSnapshotRequest
15366+
_type: SnapshotRequest
1536815367
queryVersion: 0.0.1
1536915368
properties:
1537015369
_type:
1537115370
enum:
15372-
- ViewSnapshotRequest
15371+
- SnapshotRequest
1537315372
type: string
1537415373
query:
1537515374
description: STQL query string
@@ -15380,10 +15379,6 @@ components:
1538015379
type: string
1538115380
metadata:
1538215381
$ref: '#/components/schemas/QueryMetadata'
15383-
viewId:
15384-
format: int64
15385-
nullable: true
15386-
type: integer
1538715382
required:
1538815383
- _type
1538915384
- metadata
@@ -15446,35 +15441,29 @@ components:
1544615441
QuerySnapshotResult:
1544715442
description: |
1544815443
Query succeeded (or encountered a runtime error that's part of the result).
15449-
The viewSnapshotResponse uses existing DTO types for nested structures.
15444+
The SnapshotResponse uses existing DTO types for nested structures.
1545015445
example:
15451-
viewId: 0
15452-
viewSnapshotResponse: "{}"
1545315446
_type: QuerySnapshotResult
15447+
snapshotResponse: "{}"
1545415448
properties:
1545515449
_type:
1545615450
description: Discriminator field
1545715451
enum:
1545815452
- QuerySnapshotResult
1545915453
type: string
15460-
viewSnapshotResponse:
15454+
snapshotResponse:
1546115455
description: |
15462-
The query result or error response. This is opaque at the API level but contains one of:
15456+
The query result or error response. This is opaque at the API level but contains one of the following DTO types:
1546315457
- ViewSnapshot (success)
1546415458
- ViewSnapshotFetchTimeout (error)
1546515459
- ViewSnapshotTooManyActiveQueries (error)
1546615460
- ViewSnapshotTopologySizeOverflow (error)
1546715461
- ViewSnapshotDataUnavailable (error)
1546815462
Use the _type field to discriminate between types.
1546915463
type: object
15470-
viewId:
15471-
description: Optional view ID associated with this result
15472-
format: int64
15473-
nullable: true
15474-
type: integer
1547515464
required:
1547615465
- _type
15477-
- viewSnapshotResponse
15466+
- snapshotResponse
1547815467
type: object
1547915468
QueryParsingFailure:
1548015469
description: |

0 commit comments

Comments
 (0)