Skip to content

Commit

Permalink
[monitor-query] Add version string to options endpoint (#23383)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpodwysocki authored Oct 5, 2022
1 parent 4f44c25 commit 15bfcd8
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 11 deletions.
8 changes: 2 additions & 6 deletions sdk/monitor/monitor-query/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
# Release History

## 1.0.3 (Unreleased)

### Features Added

### Breaking Changes
## 1.0.3 (2022-10-05)

### Bugs Fixed

### Other Changes
- #23349 Fixed endpoint resolution to allow endpoints from sovereign clouds

## 1.0.2 (2022-06-07)

Expand Down
15 changes: 15 additions & 0 deletions sdk/monitor/monitor-query/src/internal/logQueryOptionUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { LogsQueryClientOptions } from "../logsQueryClient";

export function getLogQueryEndpoint(options: LogsQueryClientOptions): string {
if (!options.endpoint) {
throw new Error("options.endpoint is required");
}

const url = new URL(options.endpoint);
url.pathname = "/v1";

return url.toString();
}
9 changes: 6 additions & 3 deletions sdk/monitor/monitor-query/src/logsQueryClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { QueryTimeInterval } from "./models/timeInterval";
import { convertTimespanToInterval } from "./timespanConversion";
import { SDK_VERSION } from "./constants";
import { tracingClient } from "./tracing";
import { getLogQueryEndpoint } from "./internal/logQueryOptionUtils";

const defaultMonitorScope = "https://api.loganalytics.io/.default";

Expand Down Expand Up @@ -56,8 +57,10 @@ export class LogsQueryClient {
// This client defaults to using 'https://api.loganalytics.io/' as the
// host.
let scope;
let endpoint = options?.endpoint;
if (options?.endpoint) {
scope = `${options?.endpoint}/.default`;
scope = `${options.endpoint}/.default`;
endpoint = getLogQueryEndpoint(options);
}
const credentialOptions = {
credentialScopes: scope,
Expand All @@ -69,8 +72,8 @@ export class LogsQueryClient {
: `${packageDetails}`;
this._logAnalytics = new AzureLogAnalytics({
...options,
$host: options?.endpoint,
endpoint: options?.endpoint,
$host: endpoint,
endpoint: endpoint,
credentialScopes: credentialOptions?.credentialScopes ?? defaultMonitorScope,
credential: tokenCredential,
userAgentOptions: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { assert } from "@azure/test-utils";
import { getLogQueryEndpoint } from "../../../src/internal/logQueryOptionUtils";

describe("logQueryOptionsUtils", () => {
describe("getLogQueryEndpoint", () => {
it("should return the endpoint with the version", () => {
const expected = "http://microsoft.com/v1";

const endpoint1 = "http://microsoft.com/";
const endpoint2 = "http://microsoft.com";

const result1 = getLogQueryEndpoint({ endpoint: endpoint1 });
const result2 = getLogQueryEndpoint({ endpoint: endpoint2 });

assert.equal(result1, expected);
assert.equal(result2, expected);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ describe("LogsQueryClient unit tests", () => {
endpoint: "https://customEndpoint1",
});

assert.equal(client["_logAnalytics"].$host, "https://customEndpoint1");
assert.equal(client["_logAnalytics"]["_endpoint"], "https://customEndpoint1");
assert.equal(client["_logAnalytics"].$host, "https://customendpoint1/v1");
assert.equal(client["_logAnalytics"]["_endpoint"], "https://customendpoint1/v1");

try {
await client.queryWorkspace("workspaceId", "query", { duration: Durations.fiveMinutes });
Expand Down

0 comments on commit 15bfcd8

Please sign in to comment.