NIFI-6977 - Change the reporting behavior of Azure Reporting task to report report the time when metrics are generated

Signed-off-by: Pierre Villard <pierre.villard.fr@gmail.com>

This closes #4211.
This commit is contained in:
sjyang18 2020-01-09 19:39:36 +00:00 committed by Pierre Villard
parent a61a4c2b58
commit 9df53e7204
No known key found for this signature in database
GPG Key ID: BEE1599F0726E9CD
2 changed files with 13 additions and 5 deletions

View File

@ -133,11 +133,15 @@ public abstract class AbstractAzureLogAnalyticsReportingTask extends AbstractRep
protected void sendToLogAnalytics(final HttpPost request, final String workspaceId, final String linuxPrimaryKey, protected void sendToLogAnalytics(final HttpPost request, final String workspaceId, final String linuxPrimaryKey,
final String rawJson) throws IllegalArgumentException, RuntimeException, IOException { final String rawJson) throws IllegalArgumentException, RuntimeException, IOException {
final int bodyLength = rawJson.getBytes(UTF8).length; final int bodyLength = rawJson.getBytes(UTF8).length;
final String nowRfc1123 = RFC_1123_DATE_TIME.format(ZonedDateTime.now(ZoneOffset.UTC)); final ZonedDateTime zNow = ZonedDateTime.now(ZoneOffset.UTC);
final String nowRfc1123 = zNow.format(DateTimeFormatter.RFC_1123_DATE_TIME);
final String nowISO8601 = zNow.format(DateTimeFormatter.ISO_DATE_TIME);
final String createAuthorization = createAuthorization(workspaceId, linuxPrimaryKey, bodyLength, nowRfc1123); final String createAuthorization = createAuthorization(workspaceId, linuxPrimaryKey, bodyLength, nowRfc1123);
request.addHeader("Authorization", createAuthorization); request.addHeader("Authorization", createAuthorization);
request.addHeader("x-ms-date", nowRfc1123); request.addHeader("x-ms-date", nowRfc1123);
request.addHeader("time-generated-field", nowISO8601);
request.setEntity(new StringEntity(rawJson)); request.setEntity(new StringEntity(rawJson));
try (CloseableHttpClient httpClient = HttpClients.createDefault()) { try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
postRequest(httpClient, request); postRequest(httpClient, request);

View File

@ -213,9 +213,13 @@ public class TestAzureLogAnalyticsReportingTask {
testedReportingTask.onTrigger(reportingContextStub); testedReportingTask.onTrigger(reportingContextStub);
HttpPost postRequest = testedReportingTask.getPostRequest(); HttpPost postRequest = testedReportingTask.getPostRequest();
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class); ArgumentCaptor<String> captorAuthorization = ArgumentCaptor.forClass(String.class);
verify(postRequest, atLeast(1)).addHeader( eq("Authorization"), captor.capture()); ArgumentCaptor<String> captorXMsDate = ArgumentCaptor.forClass(String.class);
assertTrue(captor.getValue().contains("SharedKey")); ArgumentCaptor<String> captorTimeGeneratedField = ArgumentCaptor.forClass(String.class);
verify(postRequest, atLeast(1)).addHeader( eq("Authorization"), captorAuthorization.capture());
verify(postRequest, atLeast(1)).addHeader( eq("x-ms-date"), captorXMsDate.capture());
verify(postRequest, atLeast(1)).addHeader( eq("time-generated-field"), captorTimeGeneratedField.capture());
assertTrue(captorAuthorization.getValue().contains("SharedKey"));
} }