Audit message were being persisted with the type ‘audit_activity’ (elastic/elasticsearch#554)

Original commit: elastic/x-pack-elasticsearch@7c00495c98
This commit is contained in:
David Kyle 2016-12-15 15:31:11 +00:00 committed by GitHub
parent 8841a97659
commit 8e14aee978
2 changed files with 10 additions and 4 deletions

View File

@ -55,7 +55,7 @@ public class Auditor {
}
private void indexDoc(String type, ToXContent toXContent) {
client.prepareIndex(index, AuditActivity.TYPE.getPreferredName())
client.prepareIndex(index, type)
.setSource(toXContentBuilder(toXContent))
.execute(new ActionListener<IndexResponse>() {
@Override

View File

@ -5,7 +5,6 @@
*/
package org.elasticsearch.xpack.prelert.job.audit;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.when;
import java.io.IOException;
@ -27,6 +26,7 @@ public class AuditorTests extends ESTestCase {
private Client client;
private ListenableActionFuture<IndexResponse> indexResponse;
private ArgumentCaptor<String> indexCaptor;
private ArgumentCaptor<String> typeCaptor;
private ArgumentCaptor<XContentBuilder> jsonCaptor;
@SuppressWarnings("unchecked")
@ -35,6 +35,7 @@ public class AuditorTests extends ESTestCase {
client = Mockito.mock(Client.class);
indexResponse = Mockito.mock(ListenableActionFuture.class);
indexCaptor = ArgumentCaptor.forClass(String.class);
typeCaptor = ArgumentCaptor.forClass(String.class);
jsonCaptor = ArgumentCaptor.forClass(XContentBuilder.class);
}
@ -43,6 +44,7 @@ public class AuditorTests extends ESTestCase {
Auditor auditor = new Auditor(client, "prelert-int", "foo");
auditor.info("Here is my info");
assertEquals("prelert-int", indexCaptor.getValue());
assertEquals("audit_message", typeCaptor.getValue());
AuditMessage auditMessage = parseAuditMessage();
assertEquals("foo", auditMessage.getJobId());
assertEquals("Here is my info", auditMessage.getMessage());
@ -54,6 +56,7 @@ public class AuditorTests extends ESTestCase {
Auditor auditor = new Auditor(client, "someIndex", "bar");
auditor.warning("Here is my warning");
assertEquals("someIndex", indexCaptor.getValue());
assertEquals("audit_message", typeCaptor.getValue());
AuditMessage auditMessage = parseAuditMessage();
assertEquals("bar", auditMessage.getJobId());
assertEquals("Here is my warning", auditMessage.getMessage());
@ -65,6 +68,7 @@ public class AuditorTests extends ESTestCase {
Auditor auditor = new Auditor(client, "someIndex", "foobar");
auditor.error("Here is my error");
assertEquals("someIndex", indexCaptor.getValue());
assertEquals("audit_message", typeCaptor.getValue());
AuditMessage auditMessage = parseAuditMessage();
assertEquals("foobar", auditMessage.getJobId());
assertEquals("Here is my error", auditMessage.getMessage());
@ -76,6 +80,7 @@ public class AuditorTests extends ESTestCase {
Auditor auditor = new Auditor(client, "someIndex", "");
auditor.activity("Here is my activity");
assertEquals("someIndex", indexCaptor.getValue());
assertEquals("audit_message", typeCaptor.getValue());
AuditMessage auditMessage = parseAuditMessage();
assertEquals("", auditMessage.getJobId());
assertEquals("Here is my activity", auditMessage.getMessage());
@ -87,6 +92,7 @@ public class AuditorTests extends ESTestCase {
Auditor auditor = new Auditor(client, "someIndex", "");
auditor.activity(10, 100, 5, 50);
assertEquals("someIndex", indexCaptor.getValue());
assertEquals("audit_activity", typeCaptor.getValue());
AuditActivity auditActivity = parseAuditActivity();
assertEquals(10, auditActivity.getTotalJobs());
assertEquals(100, auditActivity.getTotalDetectors());
@ -98,9 +104,9 @@ public class AuditorTests extends ESTestCase {
IndexRequestBuilder indexRequestBuilder = Mockito.mock(IndexRequestBuilder.class);
when(indexRequestBuilder.setSource(jsonCaptor.capture())).thenReturn(indexRequestBuilder);
when(indexRequestBuilder.execute()).thenReturn(indexResponse);
when(client.prepareIndex(indexCaptor.capture(), eq("audit_message")))
when(client.prepareIndex(indexCaptor.capture(), typeCaptor.capture()))
.thenReturn(indexRequestBuilder);
when(client.prepareIndex(indexCaptor.capture(), eq("audit_activity")))
when(client.prepareIndex(indexCaptor.capture(), typeCaptor.capture()))
.thenReturn(indexRequestBuilder);
}