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:
parent
8841a97659
commit
8e14aee978
|
@ -55,7 +55,7 @@ public class Auditor {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void indexDoc(String type, ToXContent toXContent) {
|
private void indexDoc(String type, ToXContent toXContent) {
|
||||||
client.prepareIndex(index, AuditActivity.TYPE.getPreferredName())
|
client.prepareIndex(index, type)
|
||||||
.setSource(toXContentBuilder(toXContent))
|
.setSource(toXContentBuilder(toXContent))
|
||||||
.execute(new ActionListener<IndexResponse>() {
|
.execute(new ActionListener<IndexResponse>() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
*/
|
*/
|
||||||
package org.elasticsearch.xpack.prelert.job.audit;
|
package org.elasticsearch.xpack.prelert.job.audit;
|
||||||
|
|
||||||
import static org.mockito.Matchers.eq;
|
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -27,6 +26,7 @@ public class AuditorTests extends ESTestCase {
|
||||||
private Client client;
|
private Client client;
|
||||||
private ListenableActionFuture<IndexResponse> indexResponse;
|
private ListenableActionFuture<IndexResponse> indexResponse;
|
||||||
private ArgumentCaptor<String> indexCaptor;
|
private ArgumentCaptor<String> indexCaptor;
|
||||||
|
private ArgumentCaptor<String> typeCaptor;
|
||||||
private ArgumentCaptor<XContentBuilder> jsonCaptor;
|
private ArgumentCaptor<XContentBuilder> jsonCaptor;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
@ -35,6 +35,7 @@ public class AuditorTests extends ESTestCase {
|
||||||
client = Mockito.mock(Client.class);
|
client = Mockito.mock(Client.class);
|
||||||
indexResponse = Mockito.mock(ListenableActionFuture.class);
|
indexResponse = Mockito.mock(ListenableActionFuture.class);
|
||||||
indexCaptor = ArgumentCaptor.forClass(String.class);
|
indexCaptor = ArgumentCaptor.forClass(String.class);
|
||||||
|
typeCaptor = ArgumentCaptor.forClass(String.class);
|
||||||
jsonCaptor = ArgumentCaptor.forClass(XContentBuilder.class);
|
jsonCaptor = ArgumentCaptor.forClass(XContentBuilder.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,6 +44,7 @@ public class AuditorTests extends ESTestCase {
|
||||||
Auditor auditor = new Auditor(client, "prelert-int", "foo");
|
Auditor auditor = new Auditor(client, "prelert-int", "foo");
|
||||||
auditor.info("Here is my info");
|
auditor.info("Here is my info");
|
||||||
assertEquals("prelert-int", indexCaptor.getValue());
|
assertEquals("prelert-int", indexCaptor.getValue());
|
||||||
|
assertEquals("audit_message", typeCaptor.getValue());
|
||||||
AuditMessage auditMessage = parseAuditMessage();
|
AuditMessage auditMessage = parseAuditMessage();
|
||||||
assertEquals("foo", auditMessage.getJobId());
|
assertEquals("foo", auditMessage.getJobId());
|
||||||
assertEquals("Here is my info", auditMessage.getMessage());
|
assertEquals("Here is my info", auditMessage.getMessage());
|
||||||
|
@ -54,6 +56,7 @@ public class AuditorTests extends ESTestCase {
|
||||||
Auditor auditor = new Auditor(client, "someIndex", "bar");
|
Auditor auditor = new Auditor(client, "someIndex", "bar");
|
||||||
auditor.warning("Here is my warning");
|
auditor.warning("Here is my warning");
|
||||||
assertEquals("someIndex", indexCaptor.getValue());
|
assertEquals("someIndex", indexCaptor.getValue());
|
||||||
|
assertEquals("audit_message", typeCaptor.getValue());
|
||||||
AuditMessage auditMessage = parseAuditMessage();
|
AuditMessage auditMessage = parseAuditMessage();
|
||||||
assertEquals("bar", auditMessage.getJobId());
|
assertEquals("bar", auditMessage.getJobId());
|
||||||
assertEquals("Here is my warning", auditMessage.getMessage());
|
assertEquals("Here is my warning", auditMessage.getMessage());
|
||||||
|
@ -65,6 +68,7 @@ public class AuditorTests extends ESTestCase {
|
||||||
Auditor auditor = new Auditor(client, "someIndex", "foobar");
|
Auditor auditor = new Auditor(client, "someIndex", "foobar");
|
||||||
auditor.error("Here is my error");
|
auditor.error("Here is my error");
|
||||||
assertEquals("someIndex", indexCaptor.getValue());
|
assertEquals("someIndex", indexCaptor.getValue());
|
||||||
|
assertEquals("audit_message", typeCaptor.getValue());
|
||||||
AuditMessage auditMessage = parseAuditMessage();
|
AuditMessage auditMessage = parseAuditMessage();
|
||||||
assertEquals("foobar", auditMessage.getJobId());
|
assertEquals("foobar", auditMessage.getJobId());
|
||||||
assertEquals("Here is my error", auditMessage.getMessage());
|
assertEquals("Here is my error", auditMessage.getMessage());
|
||||||
|
@ -76,6 +80,7 @@ public class AuditorTests extends ESTestCase {
|
||||||
Auditor auditor = new Auditor(client, "someIndex", "");
|
Auditor auditor = new Auditor(client, "someIndex", "");
|
||||||
auditor.activity("Here is my activity");
|
auditor.activity("Here is my activity");
|
||||||
assertEquals("someIndex", indexCaptor.getValue());
|
assertEquals("someIndex", indexCaptor.getValue());
|
||||||
|
assertEquals("audit_message", typeCaptor.getValue());
|
||||||
AuditMessage auditMessage = parseAuditMessage();
|
AuditMessage auditMessage = parseAuditMessage();
|
||||||
assertEquals("", auditMessage.getJobId());
|
assertEquals("", auditMessage.getJobId());
|
||||||
assertEquals("Here is my activity", auditMessage.getMessage());
|
assertEquals("Here is my activity", auditMessage.getMessage());
|
||||||
|
@ -87,6 +92,7 @@ public class AuditorTests extends ESTestCase {
|
||||||
Auditor auditor = new Auditor(client, "someIndex", "");
|
Auditor auditor = new Auditor(client, "someIndex", "");
|
||||||
auditor.activity(10, 100, 5, 50);
|
auditor.activity(10, 100, 5, 50);
|
||||||
assertEquals("someIndex", indexCaptor.getValue());
|
assertEquals("someIndex", indexCaptor.getValue());
|
||||||
|
assertEquals("audit_activity", typeCaptor.getValue());
|
||||||
AuditActivity auditActivity = parseAuditActivity();
|
AuditActivity auditActivity = parseAuditActivity();
|
||||||
assertEquals(10, auditActivity.getTotalJobs());
|
assertEquals(10, auditActivity.getTotalJobs());
|
||||||
assertEquals(100, auditActivity.getTotalDetectors());
|
assertEquals(100, auditActivity.getTotalDetectors());
|
||||||
|
@ -98,9 +104,9 @@ public class AuditorTests extends ESTestCase {
|
||||||
IndexRequestBuilder indexRequestBuilder = Mockito.mock(IndexRequestBuilder.class);
|
IndexRequestBuilder indexRequestBuilder = Mockito.mock(IndexRequestBuilder.class);
|
||||||
when(indexRequestBuilder.setSource(jsonCaptor.capture())).thenReturn(indexRequestBuilder);
|
when(indexRequestBuilder.setSource(jsonCaptor.capture())).thenReturn(indexRequestBuilder);
|
||||||
when(indexRequestBuilder.execute()).thenReturn(indexResponse);
|
when(indexRequestBuilder.execute()).thenReturn(indexResponse);
|
||||||
when(client.prepareIndex(indexCaptor.capture(), eq("audit_message")))
|
when(client.prepareIndex(indexCaptor.capture(), typeCaptor.capture()))
|
||||||
.thenReturn(indexRequestBuilder);
|
.thenReturn(indexRequestBuilder);
|
||||||
when(client.prepareIndex(indexCaptor.capture(), eq("audit_activity")))
|
when(client.prepareIndex(indexCaptor.capture(), typeCaptor.capture()))
|
||||||
.thenReturn(indexRequestBuilder);
|
.thenReturn(indexRequestBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue