Skip to content

Commit

Permalink
[azlogs] remove logs prefix (#22737)
Browse files Browse the repository at this point in the history
* remove logs prefix

* cleanup

* changelog

* fix test
  • Loading branch information
gracewilcox authored Apr 11, 2024
1 parent f9c81db commit ad0e2db
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 62 deletions.
5 changes: 4 additions & 1 deletion sdk/monitor/query/azlogs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# Release History

## 1.0.0 (2024-04-10)
## 1.0.0 (2024-04-15)

### Breaking Changes
* Removed pointers from slices
* Renamed `LogsColumnType` to `ColumnType`
* Renamed `LogsQueryOptions` to `QueryOptions`
* Renamed `ServiceNameLogs` to `ServiceName`

## 0.1.0 (2024-03-07)

Expand Down
10 changes: 5 additions & 5 deletions sdk/monitor/query/azlogs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,17 @@ When multiple workspaces are included in the query, the logs in the result table

#### Increase wait time, include statistics, include visualization

The `LogsQueryOptions` type is used for advanced logs options.
The `QueryOptions` type is used for advanced logs options.

* By default, your query will run for up to three minutes. To increase the default timeout, set `LogsQueryOptions.Wait` to the desired number of seconds. The maximum wait time is 10 minutes (600 seconds).
* By default, your query will run for up to three minutes. To increase the default timeout, set `QueryOptions.Wait` to the desired number of seconds. The maximum wait time is 10 minutes (600 seconds).

* To get logs query execution statistics, such as CPU and memory consumption, set `LogsQueryOptions.Statistics` to `true`.
* To get logs query execution statistics, such as CPU and memory consumption, set `QueryOptions.Statistics` to `true`.

* To get visualization data for logs queries, set `LogsQueryOptions.Visualization` to `true`.
* To get visualization data for logs queries, set `QueryOptions.Visualization` to `true`.

```go
azlogs.QueryWorkspaceOptions{
Options: &azlogs.LogsQueryOptions{
Options: &azlogs.QueryOptions{
Statistics: to.Ptr(true),
Visualization: to.Ptr(true),
Wait: to.Ptr(600),
Expand Down
13 changes: 7 additions & 6 deletions sdk/monitor/query/azlogs/autorest.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use: "@autorest/go@4.0.0-preview.61"
inject-spans: true
version: "^3.0.0"
slice-elements-byval: true
rawjson-as-bytes: true

directive:
# delete extra endpoints
Expand Down Expand Up @@ -70,23 +71,23 @@ directive:
- from: swagger-document
where: $.definitions.queryResults.properties.render
transform: $["x-ms-client-name"] = "Visualization"

# rename LogsColumnType to ColumnType
- from: swagger-document
where: $.definitions.logsColumnType.x-ms-enum
transform: $["name"] = "ColumnType"

# rename Prefer to Options
- from: swagger-document
where: $.parameters.PreferHeaderParameter
transform: $["x-ms-client-name"] = "Options"
- from: options.go
where: $
transform: return $.replace(/Options \*string/g, "Options *LogsQueryOptions");
transform: return $.replace(/Options \*string/g, "Options *QueryOptions");
- from: client.go
where: $
transform: return $.replace(/\*options\.Options/g, "options.Options.preferHeader()");

# add descriptions for models and constants that don't have them
- from: constants.go
where: $
transform: return $.replace(/type ResultType string/, "//ResultType - Reduces the set of data collected. The syntax allowed depends on the operation. See the operation's description for details.\ntype ResultType string");

# delete unused error models
- from: models.go
where: $
Expand Down
2 changes: 1 addition & 1 deletion sdk/monitor/query/azlogs/build.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//go:build go1.18
// +build go1.18

//go:generate autorest ./autorest.md --rawjson-as-bytes
//go:generate autorest ./autorest.md
//go:generate gofmt -w .

// Copyright (c) Microsoft Corporation. All rights reserved.
Expand Down
6 changes: 3 additions & 3 deletions sdk/monitor/query/azlogs/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestClient(t *testing.T) {
c := cloud.Configuration{
ActiveDirectoryAuthorityHost: "https://...",
Services: map[cloud.ServiceName]cloud.ServiceConfiguration{
cloud.ResourceManager: {
azlogs.ServiceName: {
Audience: "",
Endpoint: "",
},
Expand Down Expand Up @@ -124,7 +124,7 @@ func TestQueryWorkspace_AdvancedQuerySuccess(t *testing.T) {
client := startTest(t)

res, err := client.QueryWorkspace(context.Background(), workspaceID, azlogs.QueryBody{Query: &query},
&azlogs.QueryWorkspaceOptions{Options: &azlogs.LogsQueryOptions{Statistics: to.Ptr(true), Visualization: to.Ptr(true), Wait: to.Ptr(600)}})
&azlogs.QueryWorkspaceOptions{Options: &azlogs.QueryOptions{Statistics: to.Ptr(true), Visualization: to.Ptr(true), Wait: to.Ptr(600)}})
require.NoError(t, err)
require.Nil(t, res.Error)
require.NotNil(t, res.Tables)
Expand Down Expand Up @@ -196,7 +196,7 @@ func TestQueryResource_Advanced(t *testing.T) {
client := startTest(t)

res, err := client.QueryResource(context.Background(), resourceURI, azlogs.QueryBody{Query: &query},
&azlogs.QueryResourceOptions{Options: &azlogs.LogsQueryOptions{Statistics: to.Ptr(true), Visualization: to.Ptr(true), Wait: to.Ptr(600)}})
&azlogs.QueryResourceOptions{Options: &azlogs.QueryOptions{Statistics: to.Ptr(true), Visualization: to.Ptr(true), Wait: to.Ptr(600)}})
require.NoError(t, err)
require.Nil(t, res.Error)
require.NotNil(t, res.Tables)
Expand Down
8 changes: 4 additions & 4 deletions sdk/monitor/query/azlogs/cloud_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ package azlogs
import "github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud"

// Cloud Service Names for Monitor Query Logs, used to identify the respective cloud.ServiceConfiguration
const ServiceNameLogs cloud.ServiceName = "query/azlogs"
const ServiceName cloud.ServiceName = "query/azlogs"

func init() {
cloud.AzureChina.Services[ServiceNameLogs] = cloud.ServiceConfiguration{
cloud.AzureChina.Services[ServiceName] = cloud.ServiceConfiguration{
Audience: "https://api.loganalytics.azure.cn",
Endpoint: "https://api.loganalytics.azure.cn/v1",
}
cloud.AzureGovernment.Services[ServiceNameLogs] = cloud.ServiceConfiguration{
cloud.AzureGovernment.Services[ServiceName] = cloud.ServiceConfiguration{
Audience: "https://api.loganalytics.us",
Endpoint: "https://api.loganalytics.us/v1",
}
cloud.AzurePublic.Services[ServiceNameLogs] = cloud.ServiceConfiguration{
cloud.AzurePublic.Services[ServiceName] = cloud.ServiceConfiguration{
Audience: "https://api.loganalytics.io",
Endpoint: "https://api.loganalytics.io/v1",
}
Expand Down
50 changes: 25 additions & 25 deletions sdk/monitor/query/azlogs/constants.go

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

12 changes: 6 additions & 6 deletions sdk/monitor/query/azlogs/custom_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func NewClient(credential azcore.TokenCredential, options *ClientOptions) (*Clie
if reflect.ValueOf(options.Cloud).IsZero() {
options.Cloud = cloud.AzurePublic
}
c, ok := options.Cloud.Services[ServiceNameLogs]
c, ok := options.Cloud.Services[ServiceName]
if !ok || c.Audience == "" || c.Endpoint == "" {
return nil, errors.New("provided Cloud field is missing Azure Monitor Logs configuration")
}
Expand Down Expand Up @@ -74,7 +74,7 @@ func (e *ErrorInfo) Error() string {
return string(e.data)
}

// Row of data in a table, types of data used by service specified in LogsColumnType
// Row of data in a table, types of data used by service specified in ColumnType
type Row []any

// TimeInterval specifies the time range over which to query.
Expand Down Expand Up @@ -109,8 +109,8 @@ func (i TimeInterval) Values() (time.Time, time.Time, error) {
return start, end, nil
}

// LogsQueryOptions sets server timeout, query statistics and visualization information
type LogsQueryOptions struct {
// QueryOptions sets server timeout, query statistics and visualization information
type QueryOptions struct {
// Set Statistics to true to get logs query execution statistics,
// such as CPU and memory consumption. Defaults to false.
Statistics *bool
Expand All @@ -126,9 +126,9 @@ type LogsQueryOptions struct {
Wait *int
}

// preferHeader converts LogsQueryOptions from struct to properly formatted sting
// preferHeader converts QueryOptions from struct to properly formatted sting
// to be used in the request Prefer Header
func (l LogsQueryOptions) preferHeader() string {
func (l QueryOptions) preferHeader() string {
var options []string
if l.Statistics != nil && *l.Statistics {
options = append(options, "include-statistics=true")
Expand Down
4 changes: 2 additions & 2 deletions sdk/monitor/query/azlogs/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func ExampleClient_QueryWorkspace() {

func ExampleClient_QueryWorkspace_second() {
// `QueryWorkspace` also has more advanced options, including querying multiple workspaces
// and LogsQueryOptions (including statistics and visualization information and increasing default timeout).
// and QueryOptions (including statistics and visualization information and increasing default timeout).

// When multiple workspaces are included in the query, the logs in the result table are not grouped
// according to the workspace from which it was retrieved.
Expand All @@ -82,7 +82,7 @@ func ExampleClient_QueryWorkspace_second() {
// Setting Statistics to true returns stats information in Results.Statistics
// Setting Visualization to true returns visualization information in Results.Visualization
options := &azlogs.QueryWorkspaceOptions{
Options: &azlogs.LogsQueryOptions{
Options: &azlogs.QueryOptions{
Statistics: to.Ptr(true),
Visualization: to.Ptr(true),
Wait: to.Ptr(600),
Expand Down
2 changes: 1 addition & 1 deletion sdk/monitor/query/azlogs/models.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/query/azlogs/options.go

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

10 changes: 4 additions & 6 deletions sdk/monitor/query/azlogs/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,11 @@ func run(m *testing.M) int {
if recording.GetRecordMode() == recording.PlaybackMode {
credential = &FakeCredential{}
} else {
// tenantID := getEnvVar("AZLOGS_TENANT_ID", "")
// clientID := getEnvVar("AZLOGS_CLIENT_ID", "")
// secret := getEnvVar("AZLOGS_CLIENT_SECRET", "")
// var err error
// credential, err = azidentity.NewClientSecretCredential(tenantID, clientID, secret, nil)
tenantID := getEnvVar("AZLOGS_TENANT_ID", "")
clientID := getEnvVar("AZLOGS_CLIENT_ID", "")
secret := getEnvVar("AZLOGS_CLIENT_SECRET", "")
var err error
credential, err = azidentity.NewDefaultAzureCredential(nil)
credential, err = azidentity.NewClientSecretCredential(tenantID, clientID, secret, nil)
if err != nil {
panic(err)
}
Expand Down

0 comments on commit ad0e2db

Please sign in to comment.