Search in sources :

Example 1 with EventSearchCriteria

use of com.hortonworks.streamline.streams.logsearch.EventSearchCriteria in project streamline by hortonworks.

the class AmbariInfraWithStormLogSearchTest method testEventSearchWithKeyValuesQueryAndHeadersQuery.

@Test
public void testEventSearchWithKeyValuesQueryAndHeadersQuery() throws Exception {
    stubSolrUrl();
    String searchQuery = "hello=world";
    EventSearchCriteria eventSearchCriteria = new EventSearchCriteria.Builder(TEST_APP_ID, TEST_FROM, TEST_TO).setSearchString(searchQuery).build();
    EventSearchResult result = logSearch.searchEvent(eventSearchCriteria);
    verifyEventSearchResults(result);
    // please note that space should be escaped to '+' since Wiremock doesn't handle it when matching...
    String dateRangeValue = "%s:[%s+TO+%s]";
    Instant fromInstant = Instant.ofEpochMilli(TEST_FROM);
    Instant toInstant = Instant.ofEpochMilli(TEST_TO);
    dateRangeValue = String.format(dateRangeValue, COLUMN_NAME_LOG_TIME, fromInstant.toString(), toInstant.toString());
    List<LoggedRequest> requests = wireMockRule.findAll(getRequestedFor(urlPathEqualTo(STUB_REQUEST_API_PATH)));
    assertEquals(1, requests.size());
    LoggedRequest request = requests.get(0);
    QueryParameter qParam = request.queryParameter("q");
    String expectedQuery = COLUMN_NAME_STREAMLINE_EVENT_ID + ":*";
    expectedQuery += "+AND+(";
    expectedQuery += COLUMN_NAME_STREAMLINE_EVENT_KEYVALUES + ":" + searchQuery;
    expectedQuery += "+OR+" + COLUMN_NAME_STREAMLINE_EVENT_HEADERS + ":" + searchQuery;
    expectedQuery += "+OR+" + COLUMN_NAME_STREAMLINE_EVENT_AUX_KEYVALUES + ":" + searchQuery;
    expectedQuery += ")";
    assertTrue(qParam.containsValue(expectedQuery));
    QueryParameter fqParam = request.queryParameter("fq");
    assertTrue(fqParam.containsValue(COLUMN_NAME_TYPE + ":" + COLUMN_VALUE_TYPE_EVENT));
    assertTrue(fqParam.containsValue(COLUMN_NAME_STREAMLINE_TOPOLOGY_ID + ":" + TEST_APP_ID));
    assertTrue(fqParam.containsValue(dateRangeValue));
    assertFalse(fqParam.hasValueMatching(ValuePattern.containing(COLUMN_NAME_STREAMLINE_COMPONENT_NAME)));
    QueryParameter sortParam = request.queryParameter("sort");
    assertTrue(sortParam.containsValue(COLUMN_NAME_LOG_TIME + "+asc"));
}
Also used : EventSearchCriteria(com.hortonworks.streamline.streams.logsearch.EventSearchCriteria) QueryParameter(com.github.tomakehurst.wiremock.http.QueryParameter) LoggedRequest(com.github.tomakehurst.wiremock.verification.LoggedRequest) Instant(java.time.Instant) EventSearchResult(com.hortonworks.streamline.streams.logsearch.EventSearchResult) Test(org.junit.Test)

Example 2 with EventSearchCriteria

use of com.hortonworks.streamline.streams.logsearch.EventSearchCriteria in project streamline by hortonworks.

the class AmbariInfraWithStormLogSearchTest method testEventSearchWithMinimumParameters.

@Test
public void testEventSearchWithMinimumParameters() throws Exception {
    stubSolrUrl();
    EventSearchCriteria eventSearchCriteria = new EventSearchCriteria.Builder(TEST_APP_ID, TEST_FROM, TEST_TO).build();
    EventSearchResult result = logSearch.searchEvent(eventSearchCriteria);
    verifyEventSearchResults(result);
    // please note that space should be escaped to '+' since Wiremock doesn't handle it when matching...
    String dateRangeValue = "%s:[%s+TO+%s]";
    Instant fromInstant = Instant.ofEpochMilli(TEST_FROM);
    Instant toInstant = Instant.ofEpochMilli(TEST_TO);
    dateRangeValue = String.format(dateRangeValue, COLUMN_NAME_LOG_TIME, fromInstant.toString(), toInstant.toString());
    List<LoggedRequest> requests = wireMockRule.findAll(getRequestedFor(urlPathEqualTo(STUB_REQUEST_API_PATH)));
    assertEquals(1, requests.size());
    LoggedRequest request = requests.get(0);
    QueryParameter qParam = request.queryParameter("q");
    assertTrue(qParam.containsValue(COLUMN_NAME_STREAMLINE_EVENT_ID + ":*"));
    QueryParameter fqParam = request.queryParameter("fq");
    assertTrue(fqParam.containsValue(COLUMN_NAME_TYPE + ":" + COLUMN_VALUE_TYPE_EVENT));
    assertTrue(fqParam.containsValue(COLUMN_NAME_STREAMLINE_TOPOLOGY_ID + ":" + TEST_APP_ID));
    assertTrue(fqParam.containsValue(dateRangeValue));
    assertFalse(fqParam.hasValueMatching(ValuePattern.containing(COLUMN_NAME_STREAMLINE_COMPONENT_NAME)));
    assertFalse(fqParam.hasValueMatching(ValuePattern.containing(COLUMN_NAME_STREAMLINE_EVENT_ID)));
    assertFalse(fqParam.hasValueMatching(ValuePattern.containing(COLUMN_NAME_STREAMLINE_EVENT_ROOT_ID_SET)));
    assertFalse(fqParam.hasValueMatching(ValuePattern.containing(COLUMN_NAME_STREAMLINE_EVENT_PARENT_ID_SET)));
    QueryParameter sortParam = request.queryParameter("sort");
    assertTrue(sortParam.containsValue(COLUMN_NAME_LOG_TIME + "+asc"));
}
Also used : EventSearchCriteria(com.hortonworks.streamline.streams.logsearch.EventSearchCriteria) QueryParameter(com.github.tomakehurst.wiremock.http.QueryParameter) LoggedRequest(com.github.tomakehurst.wiremock.verification.LoggedRequest) Instant(java.time.Instant) EventSearchResult(com.hortonworks.streamline.streams.logsearch.EventSearchResult) Test(org.junit.Test)

Example 3 with EventSearchCriteria

use of com.hortonworks.streamline.streams.logsearch.EventSearchCriteria in project streamline by hortonworks.

the class AmbariInfraWithStormLogSearchTest method testEventSearchWithComponentNamesAndStartAndLimitAndDescendingParameters.

@Test
public void testEventSearchWithComponentNamesAndStartAndLimitAndDescendingParameters() throws Exception {
    stubSolrUrl();
    int testStart = 100;
    int testLimit = 2000;
    List<String> testComponentNames = Collections.singletonList("SOURCE");
    EventSearchCriteria eventSearchCriteria = new EventSearchCriteria.Builder(TEST_APP_ID, TEST_FROM, TEST_TO).setComponentNames(testComponentNames).setAscending(false).setStart(testStart).setLimit(testLimit).build();
    EventSearchResult result = logSearch.searchEvent(eventSearchCriteria);
    verifyEventSearchResults(result);
    // please note that space should be escaped to '+' since Wiremock doesn't handle it when matching...
    String dateRangeValue = "%s:[%s+TO+%s]";
    Instant fromInstant = Instant.ofEpochMilli(TEST_FROM);
    Instant toInstant = Instant.ofEpochMilli(TEST_TO);
    dateRangeValue = String.format(dateRangeValue, COLUMN_NAME_LOG_TIME, fromInstant.toString(), toInstant.toString());
    List<LoggedRequest> requests = wireMockRule.findAll(getRequestedFor(urlPathEqualTo(STUB_REQUEST_API_PATH)));
    assertEquals(1, requests.size());
    LoggedRequest request = requests.get(0);
    QueryParameter qParam = request.queryParameter("q");
    assertTrue(qParam.containsValue(COLUMN_NAME_STREAMLINE_EVENT_ID + ":*"));
    QueryParameter fqParam = request.queryParameter("fq");
    assertTrue(fqParam.containsValue(COLUMN_NAME_TYPE + ":" + COLUMN_VALUE_TYPE_EVENT));
    assertTrue(fqParam.containsValue(COLUMN_NAME_STREAMLINE_TOPOLOGY_ID + ":" + TEST_APP_ID));
    assertTrue(fqParam.containsValue(dateRangeValue));
    assertTrue(fqParam.containsValue(COLUMN_NAME_STREAMLINE_COMPONENT_NAME + ":" + testComponentNames.get(0)));
    assertFalse(fqParam.hasValueMatching(ValuePattern.containing(COLUMN_NAME_STREAMLINE_EVENT_ID)));
    assertFalse(fqParam.hasValueMatching(ValuePattern.containing(COLUMN_NAME_STREAMLINE_EVENT_ROOT_ID_SET)));
    assertFalse(fqParam.hasValueMatching(ValuePattern.containing(COLUMN_NAME_STREAMLINE_EVENT_PARENT_ID_SET)));
    QueryParameter sortParam = request.queryParameter("sort");
    assertTrue(sortParam.containsValue(COLUMN_NAME_LOG_TIME + "+desc"));
    QueryParameter startParam = request.queryParameter("start");
    assertTrue(startParam.containsValue(String.valueOf(testStart)));
    QueryParameter rowsParam = request.queryParameter("rows");
    assertTrue(rowsParam.containsValue(String.valueOf(testLimit)));
}
Also used : EventSearchCriteria(com.hortonworks.streamline.streams.logsearch.EventSearchCriteria) QueryParameter(com.github.tomakehurst.wiremock.http.QueryParameter) LoggedRequest(com.github.tomakehurst.wiremock.verification.LoggedRequest) Instant(java.time.Instant) EventSearchResult(com.hortonworks.streamline.streams.logsearch.EventSearchResult) Test(org.junit.Test)

Example 4 with EventSearchCriteria

use of com.hortonworks.streamline.streams.logsearch.EventSearchCriteria in project streamline by hortonworks.

the class AmbariInfraWithStormLogSearchTest method testEventSearchWithEventId.

@Test
public void testEventSearchWithEventId() throws Exception {
    stubSolrUrl();
    String testEventId = "b7715c60-74ad-43dd-814a-8a40403a31bc";
    EventSearchCriteria eventSearchCriteria = new EventSearchCriteria.Builder(TEST_APP_ID, TEST_FROM, TEST_TO).setSearchEventId(testEventId).build();
    EventSearchResult result = logSearch.searchEvent(eventSearchCriteria);
    verifyEventSearchResults(result);
    // please note that space should be escaped to '+' since Wiremock doesn't handle it when matching...
    String dateRangeValue = "%s:[%s+TO+%s]";
    Instant fromInstant = Instant.ofEpochMilli(TEST_FROM);
    Instant toInstant = Instant.ofEpochMilli(TEST_TO);
    dateRangeValue = String.format(dateRangeValue, COLUMN_NAME_LOG_TIME, fromInstant.toString(), toInstant.toString());
    List<LoggedRequest> requests = wireMockRule.findAll(getRequestedFor(urlPathEqualTo(STUB_REQUEST_API_PATH)));
    assertEquals(1, requests.size());
    LoggedRequest request = requests.get(0);
    QueryParameter qParam = request.queryParameter("q");
    assertTrue(qParam.containsValue(COLUMN_NAME_STREAMLINE_EVENT_ID + ":*"));
    QueryParameter fqParam = request.queryParameter("fq");
    assertTrue(fqParam.containsValue(COLUMN_NAME_TYPE + ":" + COLUMN_VALUE_TYPE_EVENT));
    assertTrue(fqParam.containsValue(COLUMN_NAME_STREAMLINE_TOPOLOGY_ID + ":" + TEST_APP_ID));
    assertTrue(fqParam.containsValue(dateRangeValue));
    assertFalse(fqParam.hasValueMatching(ValuePattern.containing(COLUMN_NAME_STREAMLINE_COMPONENT_NAME)));
    String expectedEventIdQuery = COLUMN_NAME_STREAMLINE_EVENT_ID + ":" + testEventId;
    expectedEventIdQuery += "+OR+" + COLUMN_NAME_STREAMLINE_EVENT_ROOT_ID_SET + ":*" + testEventId + "*";
    expectedEventIdQuery += "+OR+" + COLUMN_NAME_STREAMLINE_EVENT_PARENT_ID_SET + ":*" + testEventId + "*";
    assertTrue(fqParam.containsValue(expectedEventIdQuery));
    QueryParameter sortParam = request.queryParameter("sort");
    assertTrue(sortParam.containsValue(COLUMN_NAME_LOG_TIME + "+asc"));
}
Also used : EventSearchCriteria(com.hortonworks.streamline.streams.logsearch.EventSearchCriteria) QueryParameter(com.github.tomakehurst.wiremock.http.QueryParameter) LoggedRequest(com.github.tomakehurst.wiremock.verification.LoggedRequest) Instant(java.time.Instant) EventSearchResult(com.hortonworks.streamline.streams.logsearch.EventSearchResult) Test(org.junit.Test)

Example 5 with EventSearchCriteria

use of com.hortonworks.streamline.streams.logsearch.EventSearchCriteria in project streamline by hortonworks.

the class TopologyLoggingResource method searchEvents.

@GET
@Path("/topologies/{topologyId}/events")
@Timed
public Response searchEvents(@PathParam("topologyId") Long topologyId, @QueryParam("componentName") List<String> componentNames, @QueryParam("searchString") String searchString, @QueryParam("searchEventId") String searchEventId, @QueryParam("from") Long from, @QueryParam("to") Long to, @QueryParam("start") Integer start, @QueryParam("limit") Integer limit, @QueryParam("ascending") Boolean ascending, @Context SecurityContext securityContext) throws Exception {
    SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_USER, NAMESPACE, topologyId, READ);
    Topology topology = catalogService.getTopology(topologyId);
    if (topology != null) {
        if (from == null) {
            throw BadRequestException.missingParameter("from");
        }
        if (to == null) {
            throw BadRequestException.missingParameter("to");
        }
        EventSearchCriteria criteria = new EventSearchCriteria(String.valueOf(topologyId), componentNames, searchString, searchEventId, from, to, start, limit, ascending);
        return WSUtils.respondEntity(logSearchService.searchEvent(topology, criteria), OK);
    }
    throw EntityNotFoundException.byId(topologyId.toString());
}
Also used : EventSearchCriteria(com.hortonworks.streamline.streams.logsearch.EventSearchCriteria) Topology(com.hortonworks.streamline.streams.catalog.Topology) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Aggregations

EventSearchCriteria (com.hortonworks.streamline.streams.logsearch.EventSearchCriteria)5 QueryParameter (com.github.tomakehurst.wiremock.http.QueryParameter)4 LoggedRequest (com.github.tomakehurst.wiremock.verification.LoggedRequest)4 EventSearchResult (com.hortonworks.streamline.streams.logsearch.EventSearchResult)4 Instant (java.time.Instant)4 Test (org.junit.Test)4 Timed (com.codahale.metrics.annotation.Timed)1 Topology (com.hortonworks.streamline.streams.catalog.Topology)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1