Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Log Analytics Data feed valid credential testing #5

Merged
merged 3 commits into from
Jun 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public final class AnomalyAlertConfiguration {
private MetricAnomalyAlertConfigurationsOperator crossMetricsOperator;
private List<MetricAnomalyAlertConfiguration> metricAnomalyAlertConfigurations;
private List<String> hookIds;
private List<String> splitAlertByDimensions;

static {
AnomalyAlertConfigurationHelper.setAccessor((configuration, id) -> {
Expand Down Expand Up @@ -106,6 +107,15 @@ public List<String> getIdOfHooksToAlert() {
return Collections.unmodifiableList(this.hookIds);
}

/**
* Gets dimensions that receives alerts triggered by this configuration.
*
* @return The hook ids.
*/
public List<String> getDimensionsToAlert() {
return Collections.unmodifiableList(this.splitAlertByDimensions);
}

/**
* Sets the description for the configuration.
*
Expand Down Expand Up @@ -200,6 +210,22 @@ public AnomalyAlertConfiguration setIdOfHooksToAlert(List<String> hookIds) {
return this;
}

/**
* Sets the dimensionsToAlert to receives alerts triggered by this configuration.
*
* @param dimensionsToAlert The hook ids.
*
* @return The AnomalyAlertConfiguration object itself.
*/
public AnomalyAlertConfiguration setDimensionsToAlert(List<String> dimensionsToAlert) {
if (splitAlertByDimensions == null) {
this.splitAlertByDimensions = new ArrayList<>();
} else {
this.splitAlertByDimensions = dimensionsToAlert;
}
return this;
}

void setId(String id) {
this.id = id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public String getApiKey() {
* @param apiKey The new api key to associated with this credential.
* @return The updated {@code MetricsAdvisorKeyCredential} object.
*/
public MetricsAdvisorKeyCredential update(String subscriptionKey, String apiKey) {
public MetricsAdvisorKeyCredential updateKey(String subscriptionKey, String apiKey) {
synchronized (this.updateLock) {
this.subscriptionKey = subscriptionKey;
this.apiKey = apiKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ public void testKeyUpdate() {
Assertions.assertTrue(credential.getSubscriptionKey().equals("sub-id-1"));
Assertions.assertTrue(credential.getApiKey().equals("key-1"));

credential.update(null, null);
credential.updateKey(null, null);
Assertions.assertNull(credential.getSubscriptionKey());
Assertions.assertNull(credential.getApiKey());

credential.update("sub-id-2", "key-2");
credential.updateKey("sub-id-2", "key-2");
Assertions.assertTrue(credential.getSubscriptionKey().equals("sub-id-2"));
Assertions.assertTrue(credential.getApiKey().equals("key-2"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@
import com.azure.ai.metricsadvisor.models.AzureTableDataFeedSource;
import com.azure.ai.metricsadvisor.models.DataFeed;
import com.azure.ai.metricsadvisor.models.DataFeedAutoRollUpMethod;
import com.azure.ai.metricsadvisor.models.DataFeedDimension;
import com.azure.ai.metricsadvisor.models.DataFeedGranularity;
import com.azure.ai.metricsadvisor.models.DataFeedGranularityType;
import com.azure.ai.metricsadvisor.models.DataFeedIngestionSettings;
import com.azure.ai.metricsadvisor.models.DataFeedMetric;
import com.azure.ai.metricsadvisor.models.DataFeedMissingDataPointFillSettings;
import com.azure.ai.metricsadvisor.models.DataFeedMissingDataPointFillType;
import com.azure.ai.metricsadvisor.models.DataFeedOptions;
import com.azure.ai.metricsadvisor.models.DataFeedRollupSettings;
import com.azure.ai.metricsadvisor.models.DataFeedRollupType;
import com.azure.ai.metricsadvisor.models.DataFeedSchema;
import com.azure.ai.metricsadvisor.models.DataFeedSourceType;
import com.azure.ai.metricsadvisor.models.DataFeedMissingDataPointFillType;
import com.azure.ai.metricsadvisor.models.DataFeedDimension;
import com.azure.ai.metricsadvisor.models.InfluxDbDataFeedSource;
import com.azure.ai.metricsadvisor.models.MetricsAdvisorServiceVersion;
import com.azure.ai.metricsadvisor.models.MongoDbDataFeedSource;
Expand All @@ -45,7 +45,11 @@
import static com.azure.ai.metricsadvisor.TestUtils.APP_INSIGHTS_APPLICATION_ID;
import static com.azure.ai.metricsadvisor.TestUtils.APP_INSIGHTS_QUERY;
import static com.azure.ai.metricsadvisor.TestUtils.AZURE_DATALAKEGEN2_ACCOUNT_KEY;
import static com.azure.ai.metricsadvisor.TestUtils.AZURE_METRICS_ADVISOR_LOG_ANALYTICS_CLIENT_ID;
import static com.azure.ai.metricsadvisor.TestUtils.AZURE_METRICS_ADVISOR_LOG_ANALYTICS_CLIENT_SECRET;
import static com.azure.ai.metricsadvisor.TestUtils.AZURE_METRICS_ADVISOR_ENDPOINT;
import static com.azure.ai.metricsadvisor.TestUtils.AZURE_METRICS_ADVISOR_TENANT_ID;
import static com.azure.ai.metricsadvisor.TestUtils.AZURE_METRICS_ADVISOR_LOG_ANALYTICS_WORKSPACE_ID;
import static com.azure.ai.metricsadvisor.TestUtils.BLOB_CONNECTION_STRING;
import static com.azure.ai.metricsadvisor.TestUtils.BLOB_TEMPLATE;
import static com.azure.ai.metricsadvisor.TestUtils.COSMOS_DB_CONNECTION_STRING;
Expand All @@ -56,6 +60,7 @@
import static com.azure.ai.metricsadvisor.TestUtils.INFLUX_DB_CONNECTION_STRING;
import static com.azure.ai.metricsadvisor.TestUtils.INFLUX_DB_PASSWORD;
import static com.azure.ai.metricsadvisor.TestUtils.INGESTION_START_TIME;
import static com.azure.ai.metricsadvisor.TestUtils.LOG_ANALYTICS_QUERY;
import static com.azure.ai.metricsadvisor.TestUtils.MONGO_COMMAND;
import static com.azure.ai.metricsadvisor.TestUtils.MONGO_DB_CONNECTION_STRING;
import static com.azure.ai.metricsadvisor.TestUtils.MYSQL_DB_CONNECTION_STRING;
Expand Down Expand Up @@ -149,11 +154,11 @@ void creatDataFeedRunner(Consumer<DataFeed> testRunner, DataFeedSourceType dataF
TEST_DB_NAME, DIRECTORY_TEMPLATE, FILE_TEMPLATE));
} else if (dataFeedSourceType == DataFeedSourceType.AZURE_LOG_ANALYTICS) {
dataFeed = new DataFeed().setSource(AzureLogAnalyticsDataFeedSource.usingBasicCredential(
"tenant_id",
"client_id",
"client_secret",
"workspace_id",
TEMPLATE_QUERY));
AZURE_METRICS_ADVISOR_TENANT_ID,
AZURE_METRICS_ADVISOR_LOG_ANALYTICS_CLIENT_ID,
AZURE_METRICS_ADVISOR_LOG_ANALYTICS_CLIENT_SECRET,
AZURE_METRICS_ADVISOR_LOG_ANALYTICS_WORKSPACE_ID,
LOG_ANALYTICS_QUERY));
} else {
throw new IllegalStateException("Unexpected value: " + dataFeedSourceType);
}
Expand Down Expand Up @@ -292,6 +297,9 @@ private void validateDataFeedSource(DataFeed expectedDataFeed, DataFeed actualDa
assertNotNull(logAnalyticsDataFeedSource.getQuery());
assertEquals(expLogAnalyticsDataFeedSource.getClientId(),
logAnalyticsDataFeedSource.getClientId());
assertEquals(expLogAnalyticsDataFeedSource.getTenantId(),
logAnalyticsDataFeedSource.getTenantId());
assertEquals(expLogAnalyticsDataFeedSource.getQuery(), LOG_ANALYTICS_QUERY);
} else {
throw new IllegalStateException("Unexpected value: " + dataFeedSourceType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public final class TestUtils {
+ "let endtime=starttime + gran; requests | where timestamp >= starttime and timestamp < endtime "
+ "| summarize request_count = count(), duration_avg_ms = avg(duration), duration_95th_ms = percentile"
+ "(duration, 95), duration_max_ms = max(duration) by resultCode";
static final String LOG_ANALYTICS_QUERY = "where StartTime >=datetime(@StartTime) and EndTime <datetime(@EndTime)"
+ "| summarize count_per_type=count() by DataType";
static final String MONGO_COMMAND = "{\"find\": \"adsample\",\"filter\": { Timestamp: { $eq: @StartTime }}"
+ "\"batchSize\": 2000,}";
static final String TEST_DB_NAME = "adsample";
Expand Down Expand Up @@ -109,21 +111,25 @@ public final class TestUtils {
.getGlobalConfiguration()
.get("AZURE_METRICS_ADVISOR_INFLUX_DB_PASSWORD", "testPassword");

static final String HTTP_URL = Configuration
static final String AZURE_DATALAKEGEN2_ACCOUNT_KEY = Configuration
.getGlobalConfiguration()
.get("AZURE_METRICS_ADVISOR_HTTP_GET_URL", "httpUrl");
.get("AZURE_METRICS_ADVISOR_AZURE_DATALAKE_ACCOUNT_KEY", "azDataLakeAccountKey");

static final String ELASTIC_SEARCH_HOST = Configuration
static final String AZURE_METRICS_ADVISOR_TENANT_ID = Configuration
.getGlobalConfiguration()
.get("AZURE_METRICS_ADVISOR_ELASTIC_SEARCH_HOST", "elasticsearchHost");
.get("AZURE_CLIENT_ID", "azTenantId");

static final String ELASTIC_SEARCH_AUTH_HEADER = Configuration
static final String AZURE_METRICS_ADVISOR_LOG_ANALYTICS_CLIENT_ID = Configuration
.getGlobalConfiguration()
.get("AZURE_METRICS_ADVISOR_ELASTICSEARCH_AUTH_HEADER", "authHeader");
.get("AZURE_METRICS_ADVISOR_LOG_ANALYTICS_CLIENT_ID", "azClientId");

static final String AZURE_DATALAKEGEN2_ACCOUNT_KEY = Configuration
static final String AZURE_METRICS_ADVISOR_LOG_ANALYTICS_CLIENT_SECRET = Configuration
.getGlobalConfiguration()
.get("AZURE_METRICS_ADVISOR_AZURE_DATALAKE_ACCOUNT_KEY", "azDataLakeAccountKey");
.get("AZURE_METRICS_ADVISOR_LOG_ANALYTICS_CLIENT_SECRET", "azClientSecret");

static final String AZURE_METRICS_ADVISOR_LOG_ANALYTICS_WORKSPACE_ID = Configuration
.getGlobalConfiguration()
.get("AZURE_METRICS_ADVISOR_LOG_ANALYTICS_WORKSPACE_ID", "azWorkspaceId");

static final long DEFAULT_SUBSCRIBER_TIMEOUT_SECONDS = 60;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,60 +4,60 @@
"Uri" : "https://REDACTED.cognitiveservices.azure.com/metricsadvisor/v1.0/dataFeeds",
"Headers" : {
"User-Agent" : "azsdk-java-azure-ai-metricsadvisor/1.0.0-beta.4 (11.0.9; Windows 10; 10.0)",
"x-ms-client-request-id" : "dd647ef0-54f5-4065-9b30-130f7494114d",
"x-ms-client-request-id" : "1ec97baa-c7eb-4311-85dc-7fefe61bd7f9",
"Content-Type" : "application/json"
},
"Response" : {
"x-request-id" : "c0f44859-7181-4e3d-bc37-8c14782a3c8c",
"x-request-id" : "e051005f-4e86-4aec-a765-78add00cd2ed",
"content-length" : "0",
"x-envoy-upstream-service-time" : "5626",
"x-envoy-upstream-service-time" : "6007",
"Strict-Transport-Security" : "max-age=31536000; includeSubDomains; preload",
"x-content-type-options" : "nosniff",
"apim-request-id" : "c0f44859-7181-4e3d-bc37-8c14782a3c8c",
"apim-request-id" : "e051005f-4e86-4aec-a765-78add00cd2ed",
"retry-after" : "0",
"StatusCode" : "201",
"Date" : "Thu, 27 May 2021 12:51:50 GMT",
"Location" : "https://js-metrics-advisor.cognitiveservices.azure.com/metricsadvisor/v1.0/dataFeeds/66e0d9ae-551d-407b-ad9f-196fd5c6b43b"
"Date" : "Wed, 02 Jun 2021 18:31:00 GMT",
"Location" : "https://js-metrics-advisor.cognitiveservices.azure.com/metricsadvisor/v1.0/dataFeeds/df8256ef-5ac4-46c0-8de4-2b76d0373dfb"
},
"Exception" : null
}, {
"Method" : "GET",
"Uri" : "https://REDACTED.cognitiveservices.azure.com/metricsadvisor/v1.0/dataFeeds/66e0d9ae-551d-407b-ad9f-196fd5c6b43b",
"Uri" : "https://REDACTED.cognitiveservices.azure.com/metricsadvisor/v1.0/dataFeeds/df8256ef-5ac4-46c0-8de4-2b76d0373dfb",
"Headers" : {
"User-Agent" : "azsdk-java-azure-ai-metricsadvisor/1.0.0-beta.4 (11.0.9; Windows 10; 10.0)",
"x-ms-client-request-id" : "f299eda8-3e81-4555-8691-3ad11a56b621"
"x-ms-client-request-id" : "3eba4b09-4bb4-48b8-907c-3fe4aa0e7735"
},
"Response" : {
"x-request-id" : "70e44476-669f-4e35-9bb2-67fee326a4db",
"content-length" : "1342",
"x-envoy-upstream-service-time" : "83",
"x-request-id" : "f8024449-d837-4cc1-aeda-f9445d9c9731",
"content-length" : "1484",
"x-envoy-upstream-service-time" : "5161",
"Strict-Transport-Security" : "max-age=31536000; includeSubDomains; preload",
"x-content-type-options" : "nosniff",
"apim-request-id" : "70e44476-669f-4e35-9bb2-67fee326a4db",
"apim-request-id" : "f8024449-d837-4cc1-aeda-f9445d9c9731",
"retry-after" : "0",
"StatusCode" : "200",
"Body" : "{\"dataFeedId\":\"66e0d9ae-551d-407b-ad9f-196fd5c6b43b\",\"dataFeedName\":\"java_create_data_feed_test_sample6895aae9-1a19-427d-891f-5721bcbbdf97\",\"metrics\":[{\"metricId\":\"9880f665-bca2-4919-9127-9c0db132c4de\",\"metricName\":\"cost\",\"metricDisplayName\":\"cost\",\"metricDescription\":\"\"},{\"metricId\":\"fdea3d62-67be-491e-af05-9cef16687809\",\"metricName\":\"revenue\",\"metricDisplayName\":\"revenue\",\"metricDescription\":\"\"}],\"dimension\":[{\"dimensionName\":\"category\",\"dimensionDisplayName\":\"category\"},{\"dimensionName\":\"city\",\"dimensionDisplayName\":\"city\"}],\"dataStartFrom\":\"2019-10-01T00:00:00Z\",\"dataSourceType\":\"AzureLogAnalytics\",\"timestampColumn\":\"\",\"startOffsetInSeconds\":0,\"maxQueryPerMinute\":30.0,\"granularityName\":\"Daily\",\"needRollup\":\"NoRollup\",\"fillMissingPointType\":\"PreviousValue\",\"fillMissingPointValue\":0.0,\"rollUpMethod\":\"None\",\"dataFeedDescription\":\"\",\"stopRetryAfterInSeconds\":-1,\"minRetryIntervalInSeconds\":-1,\"maxConcurrency\":0,\"viewMode\":\"Private\",\"admins\":[\"f850650c-1fcf-4489-b46f-71af2e30d360\"],\"viewers\":[],\"creator\":\"f850650c-1fcf-4489-b46f-71af2e30d360\",\"status\":\"Active\",\"createdTime\":\"2021-05-27T12:51:50Z\",\"isAdmin\":true,\"actionLinkTemplate\":\"\",\"dataSourceParameter\":{\"clientId\":\"client_id\",\"query\":\"select * from adsample2 where Timestamp = @StartTime\",\"tenantId\":\"tenant_id\",\"workspaceId\":\"workspace_id\"},\"authenticationType\":\"Basic\"}",
"Date" : "Thu, 27 May 2021 12:51:52 GMT",
"Body" : "{\"dataFeedId\":\"df8256ef-5ac4-46c0-8de4-2b76d0373dfb\",\"dataFeedName\":\"java_create_data_feed_test_sample024382e1-a777-4115-ac2f-d7bb2e2ce2d4\",\"metrics\":[{\"metricId\":\"ae6455ae-30d9-46e9-8b65-ebe4443d9c32\",\"metricName\":\"cost\",\"metricDisplayName\":\"cost\",\"metricDescription\":\"\"},{\"metricId\":\"4fd8556b-cd65-4e2c-9d51-d18e11d554f4\",\"metricName\":\"revenue\",\"metricDisplayName\":\"revenue\",\"metricDescription\":\"\"}],\"dimension\":[{\"dimensionName\":\"category\",\"dimensionDisplayName\":\"category\"},{\"dimensionName\":\"city\",\"dimensionDisplayName\":\"city\"}],\"dataStartFrom\":\"2019-10-01T00:00:00Z\",\"dataSourceType\":\"AzureLogAnalytics\",\"timestampColumn\":\"\",\"startOffsetInSeconds\":0,\"maxQueryPerMinute\":30.0,\"granularityName\":\"Daily\",\"needRollup\":\"NoRollup\",\"fillMissingPointType\":\"PreviousValue\",\"fillMissingPointValue\":0.0,\"rollUpMethod\":\"None\",\"dataFeedDescription\":\"\",\"stopRetryAfterInSeconds\":-1,\"minRetryIntervalInSeconds\":-1,\"maxConcurrency\":0,\"viewMode\":\"Private\",\"admins\":[\"f850650c-1fcf-4489-b46f-71af2e30d360\"],\"viewers\":[],\"creator\":\"f850650c-1fcf-4489-b46f-71af2e30d360\",\"status\":\"Active\",\"createdTime\":\"2021-06-02T18:31:00Z\",\"isAdmin\":true,\"actionLinkTemplate\":\"\",\"dataSourceParameter\":{\"clientId\":\"0f169727-4b5b-40bd-87ce-c22561b057b4\",\"query\":\"where StartTime >=datetime(@StartTime) and EndTime <datetime(@EndTime)| summarize count_per_type=count() by DataType\",\"tenantId\":\"f850650c-1fcf-4489-b46f-71af2e30d360\",\"workspaceId\":\"de50d49d-dfae-4c37-9a02-6d6b69eee0c5\"},\"authenticationType\":\"Basic\"}",
"Date" : "Wed, 02 Jun 2021 18:31:07 GMT",
"Content-Type" : "application/json; charset=utf-8"
},
"Exception" : null
}, {
"Method" : "DELETE",
"Uri" : "https://REDACTED.cognitiveservices.azure.com/metricsadvisor/v1.0/dataFeeds/66e0d9ae-551d-407b-ad9f-196fd5c6b43b",
"Uri" : "https://REDACTED.cognitiveservices.azure.com/metricsadvisor/v1.0/dataFeeds/df8256ef-5ac4-46c0-8de4-2b76d0373dfb",
"Headers" : {
"User-Agent" : "azsdk-java-azure-ai-metricsadvisor/1.0.0-beta.4 (11.0.9; Windows 10; 10.0)",
"x-ms-client-request-id" : "1f513712-cbca-4576-8971-7749d28f2a41"
"x-ms-client-request-id" : "d5afb36c-ee96-4e8d-9d5a-6ff7e660503a"
},
"Response" : {
"x-request-id" : "0b2e731c-bf04-4c36-9715-b3270d74ab00",
"x-request-id" : "d69b8d06-d737-4c98-9c9c-35d19ef41b2a",
"content-length" : "0",
"x-envoy-upstream-service-time" : "5350",
"x-envoy-upstream-service-time" : "5450",
"Strict-Transport-Security" : "max-age=31536000; includeSubDomains; preload",
"x-content-type-options" : "nosniff",
"apim-request-id" : "0b2e731c-bf04-4c36-9715-b3270d74ab00",
"apim-request-id" : "d69b8d06-d737-4c98-9c9c-35d19ef41b2a",
"retry-after" : "0",
"StatusCode" : "204",
"Date" : "Thu, 27 May 2021 12:51:57 GMT"
"Date" : "Wed, 02 Jun 2021 18:31:12 GMT"
},
"Exception" : null
} ],
Expand Down
Loading