Repository: Azure/azure-sdk-for-go (go)

Issue:
Allow api version override in azmetrics client
### Feature Request

Please enable override of the API version in azmetrics. It seems that outside of testing and validation (which I know may be significant), all that is required is to set pipeline options with the following: 
```
APIVersion: runtime.APIVersionOptions{
	Location: runtime.APIVersionLocationQueryParam,
	Name:     "api-version",
}
```

Pull request:
[azmetrics] add api version support
Closes #23819

Adds API version support. Instead of only being able to use the default version, users can now set the API version themselves.

Patch:
diff --git a/sdk/azcore/CHANGELOG.md b/sdk/azcore/CHANGELOG.md
index 7b9973b12e..f7713e06ce 100644
--- a/sdk/azcore/CHANGELOG.md
+++ b/sdk/azcore/CHANGELOG.md
@@ -5,6 +5,7 @@
 ### Features Added
 
 * Added field `OperationLocationResultPath` to `runtime.NewPollerOptions[T]` for LROs that use the `Operation-Location` pattern.
+* Support `encoding.TextMarshaler` and `encoding.TextUnmarshaler` interfaces in `arm.ResourceID`.
 
 ### Breaking Changes
 
diff --git a/sdk/azcore/arm/internal/resource/resource_identifier.go b/sdk/azcore/arm/internal/resource/resource_identifier.go
index 00f2d5a0ab..d9a4e36dcc 100644
--- a/sdk/azcore/arm/internal/resource/resource_identifier.go
+++ b/sdk/azcore/arm/internal/resource/resource_identifier.go
@@ -110,6 +110,21 @@ func (id *ResourceID) String() string {
 	return id.stringValue
 }
 
+// MarshalText returns a textual representation of the ResourceID
+func (id *ResourceID) MarshalText() ([]byte, error) {
+	return []byte(id.String()), nil
+}
+
+// UnmarshalText decodes the textual representation of a ResourceID
+func (id *ResourceID) UnmarshalText(text []byte) error {
+	newId, err := ParseResourceID(string(text))
+	if err != nil {
+		return err
+	}
+	*id = *newId
+	return nil
+}
+
 func newResourceID(parent *ResourceID, resourceTypeName string, resourceName string) *ResourceID {
 	id := &ResourceID{}
 	id.init(parent, chooseResourceType(resourceTypeName, parent), resourceName, true)
diff --git a/sdk/monitor/query/azmetrics/CHANGELOG.md b/sdk/monitor/query/azmetrics/CHANGELOG.md
index d72be8f985..2f0c1964c7 100644
--- a/sdk/monitor/query/azmetrics/CHANGELOG.md
+++ b/sdk/monitor/query/azmetrics/CHANGELOG.md
@@ -1,8 +1,9 @@
 # Release History
 
-## 1.1.1 (Unreleased)
+## 1.2.0 (Unreleased)
 
 ### Features Added
+* Added API Version support. Users can now change the default API Version by setting ClientOptions.APIVersion
 
 ### Breaking Changes
 
diff --git a/sdk/monitor/query/azmetrics/custom_client.go b/sdk/monitor/query/azmetrics/custom_client.go
index 80503cab81..c90287728c 100644
--- a/sdk/monitor/query/azmetrics/custom_client.go
+++ b/sdk/monitor/query/azmetrics/custom_client.go
@@ -42,7 +42,13 @@ func NewClient(endpoint string, credential azcore.TokenCredential, options *Clie
 	}
 
 	authPolicy := runtime.NewBearerTokenPolicy(credential, []string{c.Audience + "/.default"}, nil)
-	azcoreClient, err := azcore.NewClient(moduleName, version, runtime.PipelineOptions{PerRetry: []policy.Policy{authPolicy}}, &options.ClientOptions)
+	azcoreClient, err := azcore.NewClient(moduleName, version, runtime.PipelineOptions{
+		APIVersion: runtime.APIVersionOptions{
+			Location: runtime.APIVersionLocationQueryParam,
+			Name:     "api-version",
+		},
+		PerRetry: []policy.Policy{authPolicy},
+	}, &options.ClientOptions)
 	if err != nil {
 		return nil, err
 	}
diff --git a/sdk/monitor/query/azmetrics/version.go b/sdk/monitor/query/azmetrics/version.go
index 7a2b2c2d31..52ef17baa2 100644
--- a/sdk/monitor/query/azmetrics/version.go
+++ b/sdk/monitor/query/azmetrics/version.go
@@ -8,5 +8,5 @@ package azmetrics
 
 const (
 	moduleName = "github.com/Azure/azure-sdk-for-go/sdk/monitor/query/azmetrics"
-	version    = "v1.1.1"
+	version    = "v1.2.0"
 )


Test patch:
diff --git a/sdk/azcore/arm/internal/resource/resource_identifier_test.go b/sdk/azcore/arm/internal/resource/resource_identifier_test.go
index aab7c66f3a..162bf533d7 100644
--- a/sdk/azcore/arm/internal/resource/resource_identifier_test.go
+++ b/sdk/azcore/arm/internal/resource/resource_identifier_test.go
@@ -6,7 +6,10 @@
 
 package resource
 
-import "testing"
+import (
+	"encoding"
+	"testing"
+)
 
 func TestParseResourceIdentifier(t *testing.T) {
 	testData := map[string]*ResourceID{
@@ -220,6 +223,26 @@ func TestParseResourceIdentifier(t *testing.T) {
 	}
 }
 
+// Ensure ResourceID implements these interfaces
+var _ encoding.TextMarshaler = (*ResourceID)(nil)
+var _ encoding.TextUnmarshaler = (*ResourceID)(nil)
+
+func TestMarshalResourceIdentifier(t *testing.T) {
+	resourceID := &ResourceID{}
+	input := []byte("/subscriptions/17fecd63-33d8-4e43-ac6f-0aafa111b38d/resourceGroups/myRg/providers/Microsoft.ApiManagement/service/myServiceName/subscriptions/mySubs")
+	err := resourceID.UnmarshalText(input)
+	if err != nil {
+		t.Fatalf("unexpected error: %+v", err)
+	}
+	output, err := resourceID.MarshalText()
+	if err != nil {
+		t.Fatalf("unexpected error: %+v", err)
+	}
+	if string(output) != string(input) {
+		t.Fatalf("resource id changed, got %v, expected %v", string(output), string(input))
+	}
+}
+
 func equals(left, right *ResourceID) bool {
 	if left != nil && right != nil {
 		if left.String() != right.String() {
diff --git a/sdk/monitor/query/azmetrics/client_test.go b/sdk/monitor/query/azmetrics/client_test.go
index 79c45130a8..e6db2b163d 100644
--- a/sdk/monitor/query/azmetrics/client_test.go
+++ b/sdk/monitor/query/azmetrics/client_test.go
@@ -8,10 +8,13 @@ package azmetrics_test
 
 import (
 	"context"
+	"net/http"
 	"testing"
 
 	"github.com/Azure/azure-sdk-for-go/sdk/azcore"
 	"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
+	"github.com/Azure/azure-sdk-for-go/sdk/internal/mock"
+	azcred "github.com/Azure/azure-sdk-for-go/sdk/internal/test/credential"
 	"github.com/Azure/azure-sdk-for-go/sdk/monitor/query/azmetrics"
 	"github.com/stretchr/testify/require"
 )
@@ -68,3 +71,31 @@ func TestQueryResources_Fail(t *testing.T) {
 
 	testSerde(t, &res)
 }
+
+func TestAPIVersion(t *testing.T) {
+	apiVersion := "2023-10-01"
+	var requireVersion = func(t *testing.T) func(req *http.Request) bool {
+		return func(r *http.Request) bool {
+			version := r.URL.Query().Get("api-version")
+			require.Equal(t, version, apiVersion)
+			return true
+		}
+	}
+	srv, close := mock.NewServer(mock.WithTransformAllRequestsToTestServerUrl())
+	defer close()
+	srv.AppendResponse(
+		mock.WithStatusCode(200),
+		mock.WithPredicate(requireVersion(t)),
+	)
+	srv.AppendResponse(mock.WithStatusCode(http.StatusInternalServerError))
+	opts := &azmetrics.ClientOptions{
+		ClientOptions: azcore.ClientOptions{
+			Transport:  srv,
+			APIVersion: apiVersion,
+		},
+	}
+	client, err := azmetrics.NewClient(endpoint, &azcred.Fake{}, opts)
+	require.NoError(t, err)
+	_, err = client.QueryResources(context.Background(), subscriptionID, "testing", []string{"test"}, azmetrics.ResourceIDList{}, nil)
+	require.NoError(t, err)
+}