Search in sources :

Example 1 with LogSearchCriteria

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

the class TopologyLoggingResource method searchTopologyLogs.

@GET
@Path("/topologies/{topologyId}/logs")
@Timed
public Response searchTopologyLogs(@PathParam("topologyId") Long topologyId, @QueryParam("componentName") List<String> componentNames, @QueryParam("logLevel") List<String> logLevels, @QueryParam("searchString") String searchString, @QueryParam("from") Long from, @QueryParam("to") Long to, @QueryParam("start") Integer start, @QueryParam("limit") Integer limit, @QueryParam("ascending") Boolean ascending, @Context SecurityContext securityContext) {
    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");
        }
        LogSearchCriteria criteria = new LogSearchCriteria(String.valueOf(topologyId), componentNames, logLevels, searchString, from, to, start, limit, ascending);
        return WSUtils.respondEntity(logSearchService.search(topology, criteria), OK);
    }
    throw EntityNotFoundException.byId(topologyId.toString());
}
Also used : LogSearchCriteria(com.hortonworks.streamline.streams.logsearch.LogSearchCriteria) Topology(com.hortonworks.streamline.streams.catalog.Topology) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Example 2 with LogSearchCriteria

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

the class AmbariInfraWithStormLogSearchTest method testLogSearchWithMinimumParameters.

@Test
public void testLogSearchWithMinimumParameters() throws Exception {
    stubSolrUrl();
    LogSearchCriteria logSearchCriteria = new LogSearchCriteria.Builder(TEST_APP_ID, TEST_FROM, TEST_TO).build();
    LogSearchResult result = logSearch.search(logSearchCriteria);
    verifyLogSearchResults(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());
    String expectedLogLevels = "(" + String.join("+OR+", AmbariInfraWithStormLogSearch.DEFAULT_LOG_LEVELS) + ")";
    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_LOG_MESSAGE + ":*"));
    QueryParameter fqParam = request.queryParameter("fq");
    assertTrue(fqParam.containsValue(COLUMN_NAME_STREAMLINE_TOPOLOGY_ID + ":" + TEST_APP_ID));
    assertTrue(fqParam.containsValue(COLUMN_NAME_TYPE + ":" + COLUMN_VALUE_TYPE_WORKER_LOG));
    assertTrue(fqParam.containsValue(dateRangeValue));
    assertTrue(fqParam.containsValue(COLUMN_NAME_LOG_LEVEL + ":" + expectedLogLevels));
    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 : QueryParameter(com.github.tomakehurst.wiremock.http.QueryParameter) LoggedRequest(com.github.tomakehurst.wiremock.verification.LoggedRequest) LogSearchCriteria(com.hortonworks.streamline.streams.logsearch.LogSearchCriteria) Instant(java.time.Instant) LogSearchResult(com.hortonworks.streamline.streams.logsearch.LogSearchResult) Test(org.junit.Test)

Example 3 with LogSearchCriteria

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

the class AmbariInfraWithStormLogSearchTest method testLogSearchWithFullParameters.

@Test
public void testLogSearchWithFullParameters() throws Exception {
    stubSolrUrl();
    int testStart = 100;
    int testLimit = 2000;
    List<String> testLogLevels = Lists.newArrayList("INFO", "DEBUG");
    String testSearchString = "helloworld";
    List<String> testComponentNames = Lists.newArrayList("testComponent", "testComponent2");
    LogSearchCriteria logSearchCriteria = new LogSearchCriteria.Builder(TEST_APP_ID, TEST_FROM, TEST_TO).setLogLevels(testLogLevels).setSearchString(testSearchString).setComponentNames(testComponentNames).setStart(testStart).setLimit(testLimit).setAscending(false).build();
    LogSearchResult result = logSearch.search(logSearchCriteria);
    // note that the result doesn't change given that we just provide same result from file
    verifyLogSearchResults(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());
    String expectedComponentNames = "(" + String.join("+OR+", testComponentNames) + ")";
    String expectedLogLevels = "(" + String.join("+OR+", testLogLevels) + ")";
    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_LOG_MESSAGE + ":" + testSearchString));
    QueryParameter fqParam = request.queryParameter("fq");
    assertTrue(fqParam.containsValue(COLUMN_NAME_STREAMLINE_TOPOLOGY_ID + ":" + TEST_APP_ID));
    assertTrue(fqParam.containsValue(COLUMN_NAME_TYPE + ":" + COLUMN_VALUE_TYPE_WORKER_LOG));
    assertTrue(fqParam.containsValue(COLUMN_NAME_STREAMLINE_COMPONENT_NAME + ":" + expectedComponentNames));
    assertTrue(fqParam.containsValue(COLUMN_NAME_LOG_LEVEL + ":" + expectedLogLevels));
    assertTrue(fqParam.containsValue(dateRangeValue));
    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 : QueryParameter(com.github.tomakehurst.wiremock.http.QueryParameter) LoggedRequest(com.github.tomakehurst.wiremock.verification.LoggedRequest) LogSearchCriteria(com.hortonworks.streamline.streams.logsearch.LogSearchCriteria) Instant(java.time.Instant) LogSearchResult(com.hortonworks.streamline.streams.logsearch.LogSearchResult) Test(org.junit.Test)

Example 4 with LogSearchCriteria

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

the class AmbariInfraWithStormLogSearchTest method testLogSearchWithSingleComponentNameAndLogLevelParameters.

@Test
public void testLogSearchWithSingleComponentNameAndLogLevelParameters() throws Exception {
    stubSolrUrl();
    int testStart = 100;
    int testLimit = 2000;
    List<String> testLogLevels = Collections.singletonList("INFO");
    String testSearchString = "helloworld";
    List<String> testComponentNames = Collections.singletonList("testComponent");
    LogSearchCriteria logSearchCriteria = new LogSearchCriteria.Builder(TEST_APP_ID, TEST_FROM, TEST_TO).setLogLevels(testLogLevels).setSearchString(testSearchString).setComponentNames(testComponentNames).setStart(testStart).setLimit(testLimit).build();
    LogSearchResult result = logSearch.search(logSearchCriteria);
    // note that the result doesn't change given that we just provide same result from file
    verifyLogSearchResults(result);
    // others are covered from testLogSearchWithFullParameters()
    List<LoggedRequest> requests = wireMockRule.findAll(getRequestedFor(urlPathEqualTo(STUB_REQUEST_API_PATH)));
    assertEquals(1, requests.size());
    LoggedRequest request = requests.get(0);
    QueryParameter fqParam = request.queryParameter("fq");
    assertTrue(fqParam.containsValue(COLUMN_NAME_STREAMLINE_COMPONENT_NAME + ":" + testComponentNames.get(0)));
    assertTrue(fqParam.containsValue(COLUMN_NAME_TYPE + ":" + COLUMN_VALUE_TYPE_WORKER_LOG));
    assertTrue(fqParam.containsValue(COLUMN_NAME_LOG_LEVEL + ":" + testLogLevels.get(0)));
}
Also used : QueryParameter(com.github.tomakehurst.wiremock.http.QueryParameter) LoggedRequest(com.github.tomakehurst.wiremock.verification.LoggedRequest) LogSearchCriteria(com.hortonworks.streamline.streams.logsearch.LogSearchCriteria) LogSearchResult(com.hortonworks.streamline.streams.logsearch.LogSearchResult) Test(org.junit.Test)

Aggregations

LogSearchCriteria (com.hortonworks.streamline.streams.logsearch.LogSearchCriteria)4 QueryParameter (com.github.tomakehurst.wiremock.http.QueryParameter)3 LoggedRequest (com.github.tomakehurst.wiremock.verification.LoggedRequest)3 LogSearchResult (com.hortonworks.streamline.streams.logsearch.LogSearchResult)3 Test (org.junit.Test)3 Instant (java.time.Instant)2 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