Skip to content

Commit

Permalink
[azquery] renaming (#19490)
Browse files Browse the repository at this point in the history
* change render/statistics to type []byte

* renames

* fix

* update docs
  • Loading branch information
gracewilcox authored Nov 4, 2022
1 parent 96096fe commit c5661e6
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 91 deletions.
4 changes: 4 additions & 0 deletions sdk/monitor/azquery/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

### Breaking Changes
* Added error return values to `NewLogsClient` and `NewMetricsClient`
* Rename `Batch` to `QueryBatch`
* Rename `NewListMetricDefinitionsPager` to `NewListDefinitionsPager`
* Rename `NewListMetricNamespacesPager` to `NewListNamespacesPager`
* Changed type of `Render` and `Statistics` from interface{} to []byte

### Bugs Fixed

Expand Down
28 changes: 18 additions & 10 deletions sdk/monitor/azquery/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ func main() {
//TODO: handle error
}

client := azquery.NewLogsClient(cred, nil)
client, error := azquery.NewLogsClient(cred, nil)
if err != nil {
//TODO: handle error
}
}
```

Expand All @@ -65,7 +68,10 @@ func main() {
//TODO: handle error
}

client := azquery.NewMetricsClient(cred, nil)
client, err := azquery.NewMetricsClient(cred, nil)
if err != nil {
//TODO: handle error
}
}
```

Expand Down Expand Up @@ -150,15 +156,16 @@ Results
|---Name *string
|---Type *LogsColumnType
|---Name *string
|---Rows [][]interface{}
|---Rows []Row
|---ColumnIndexLookup map[string]int
|---Error *ErrorInfo
|---Code *string // custom error type
|---Render interface{}
|---Statistics interface{}
|---Render []byte
|---Statistics []byte
```

### Batch query
`Batch` is an advanced method allowing users to execute multiple logs queries in a single request. It takes in a [BatchRequest](#batch-query-request-structure) and returns a [BatchResponse](#batch-query-result-structure). `Batch` can return results in any order (usually in order of completion/success). Please use the `ID` attribute to identify the correct response.
`QueryBatch` is an advanced method allowing users to execute multiple logs queries in a single request. It takes in a [BatchRequest](#batch-query-request-structure) and returns a [BatchResponse](#batch-query-result-structure). `QueryBatch` can return results in any order (usually in order of completion/success). Please use the `ID` attribute to identify the correct response.
```go
timespan := "2022-08-30/2022-08-31" // ISO8601 Standard Timespan
batchRequest := azquery.BatchRequest{[]*azquery.BatchQueryRequest{
Expand All @@ -167,7 +174,7 @@ batchRequest := azquery.BatchRequest{[]*azquery.BatchQueryRequest{
{Body: &azquery.Body{Query: to.Ptr(kustoQuery3), Timespan: to.Ptr(timespan)}, ID: to.Ptr("3"), Workspace: to.Ptr(workspaceID)},
}}

res, err := client.Batch(context.TODO(), batchRequest, nil)
res, err := client.QueryBatch(context.TODO(), batchRequest, nil)
if err != nil {
//TODO: handle error
}
Expand Down Expand Up @@ -198,14 +205,15 @@ BatchResponse
|---Body *BatchQueryResults
|---Error *ErrorInfo // custom error type
|---Code *string
|---Render interface{}
|---Statistics interface{}
|---Render []byte
|---Statistics []byte
|---Tables []*Table
|---Columns []*Column
|---Name *string
|---Type *LogsColumnType
|---Name *string
|---Rows [][]interface{}
|---Rows []Row
|---ColumnIndexLookup map[string]int
|---Headers map[string]*string
|---ID *string
|---Status *int32
Expand Down
27 changes: 23 additions & 4 deletions sdk/monitor/azquery/autorest.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ directive:
# rename log queries
- rename-operation:
from: Query_Execute
to: QueryWorkspace
to: Logs_QueryWorkspace
- rename-operation:
from: Query_Batch
to: Batch
to: Logs_QueryBatch

# rename metric list to QueryResource
- rename-operation:
Expand All @@ -63,10 +63,10 @@ directive:
# rename ListMetricDefinitions and ListMetricNamespaces to generate in metrics_client.go
- rename-operation:
from: MetricDefinitions_List
to: Metrics_ListMetricDefinitions
to: Metrics_ListDefinitions
- rename-operation:
from: MetricNamespaces_List
to: Metrics_ListMetricNamespaces
to: Metrics_ListNamespaces

# add default values for batch request path and method attributes
- from: swagger-document
Expand Down Expand Up @@ -138,3 +138,22 @@ directive:
- from: constants.go
where: $
transform: return $.replace(/const host = "(.*?)"/, "");

# change render and statistics type to []byte
- from: models.go
where: $
transform: return $.replace(/interface{}/g, "[]byte");
- from: models_serde.go
where: $
transform: return
$.replace(/err(.*)r\.Statistics\)/, "r.Statistics = val")
- from: models_serde.go
where: $
transform: return $.replace(/err(.*)r\.Render\)/, "r.Render = val");
- from: models_serde.go
where: $
transform: return
$.replace(/err(.*)b\.Statistics\)/, "b.Statistics = val")
- from: models_serde.go
where: $
transform: return $.replace(/err(.*)b\.Render\)/, "b.Render = val");
4 changes: 2 additions & 2 deletions sdk/monitor/azquery/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func ExampleLogsClient_QueryWorkspace_second() {
fmt.Println(QueryResults)
}

func ExampleLogsClient_Batch() {
func ExampleLogsClient_QueryBatch() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
//TODO: handle error
Expand All @@ -146,7 +146,7 @@ func ExampleLogsClient_Batch() {
{Body: &azquery.Body{Query: to.Ptr(kustoQuery3), Timespan: to.Ptr(timespan)}, ID: to.Ptr("3"), Workspace: to.Ptr(workspaceID)},
}}

res, err := client.Batch(context.TODO(), batchRequest, nil)
res, err := client.QueryBatch(context.TODO(), batchRequest, nil)
if err != nil {
//TODO: handle error
}
Expand Down
28 changes: 14 additions & 14 deletions sdk/monitor/azquery/logs_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions sdk/monitor/azquery/logs_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func TestBatch_QuerySuccess(t *testing.T) {
}}
testSerde(t, &batchRequest)

res, err := client.Batch(context.Background(), batchRequest, nil)
res, err := client.QueryBatch(context.Background(), batchRequest, nil)
if err != nil {
t.Fatalf("error with query, %s", err)
}
Expand Down Expand Up @@ -226,7 +226,7 @@ func TestBatch_PartialError(t *testing.T) {
{Body: &azquery.Body{Query: to.Ptr(query)}, ID: to.Ptr("2"), Workspace: to.Ptr(workspaceID)},
}}

res, err := client.Batch(context.Background(), batchRequest, nil)
res, err := client.QueryBatch(context.Background(), batchRequest, nil)
if err != nil {
t.Fatalf("error with query, %s", err)
}
Expand Down
70 changes: 34 additions & 36 deletions sdk/monitor/azquery/metrics_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions sdk/monitor/azquery/metrics_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestQueryResource_BasicQuerySuccess(t *testing.T) {
func TestNewListMetricDefinitionsPager_Success(t *testing.T) {
client := startMetricsTest(t)

pager := client.NewListMetricDefinitionsPager(resourceURI, nil)
pager := client.NewListDefinitionsPager(resourceURI, nil)

// test if first page is valid
if pager.More() {
Expand All @@ -66,7 +66,7 @@ func TestNewListMetricDefinitionsPager_Success(t *testing.T) {
func TestNewListMetricNamespacesPager_Success(t *testing.T) {
client := startMetricsTest(t)

pager := client.NewListMetricNamespacesPager(resourceURI, nil)
pager := client.NewListNamespacesPager(resourceURI, nil)

// test if first page is valid
if pager.More() {
Expand Down
Loading

0 comments on commit c5661e6

Please sign in to comment.