Search in sources :

Example 1 with SignatureStatus2

use of io.codekvast.javaagent.model.v2.SignatureStatus2 in project codekvast by crispab.

the class DashboardServiceImpl method getMethods2.

@Override
@Transactional(readOnly = true)
public GetMethodsResponse2 getMethods2(@Valid GetMethodsRequest request) {
    long startedAt = clock.millis();
    Long customerId = customerIdProvider.getCustomerId();
    PricePlan pricePlan = customerService.getCustomerDataByCustomerId(customerId).getPricePlan();
    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("latestCollectedSince", clock.instant().minus(request.getMinCollectedDays(), DAYS));
    params.addValue("now", new Timestamp(clock.millis()));
    params.addValue("customerId", customerId);
    String whereClause = "i.customerId = :customerId AND m.modifiers NOT LIKE '%abstract%'";
    String normalizedSignature = request.getNormalizedSignature();
    if (!normalizedSignature.equals("%")) {
        params.addValue("signature", normalizedSignature);
        whereClause += // Make it case-insensitive
        " AND m.signature LIKE :signature COLLATE utf8mb4_general_ci";
    }
    if (request.getApplications() != null && !request.getApplications().isEmpty()) {
        params.addValue("applicationIds", translateNamesToIds("applications", "name", request.getApplications()));
        whereClause += " AND i.applicationId IN (:applicationIds)";
    }
    if (request.getEnvironments() != null && !request.getEnvironments().isEmpty()) {
        params.addValue("environmentIds", translateNamesToIds("environments", "name", request.getEnvironments()));
        whereClause += " AND i.environmentId IN (:environmentIds)";
    }
    if (request.getLocations() != null && !request.getLocations().isEmpty()) {
        params.addValue("locationIds", translateNamesToIds("method_locations", "locationNoVersion", request.getLocations()));
        whereClause += " AND ml.id IN (:locationIds)";
    }
    String sql = "SELECT m.id, m.signature, " + "MAX(i.createdAt) AS latestCollectedSince, " + "MAX(i.status) AS status, " + "MAX(i.invokedAtMillis) AS lastInvokedAtMillis, " + "MAX(i.timestamp) AS lastPublishedAt, " + "m.annotation AS methodAnnotation, " + "ml.annotation AS methodLocationAnnotation, " + "p.annotation AS packageAnnotation, " + "t.annotation AS typeAnnotation " + "FROM invocations i " + "  INNER JOIN methods m ON i.methodId = m.id AND m.customerId = i.customerId " + "  INNER JOIN types t ON m.declaringType = t.name AND t.customerId = m.customerId " + "  INNER JOIN packages p ON m.packageName = p.name AND p.customerId = m.customerId " + "  LEFT JOIN method_locations ml ON ml.methodId = m.id AND ml.customerId = m.customerId " + "WHERE " + whereClause + " GROUP BY i.methodId " + "HAVING latestCollectedSince <= :latestCollectedSince " + "ORDER BY lastInvokedAtMillis ";
    List<MethodDescriptor2> methods = new ArrayList<>(request.getMaxResults());
    namedParameterJdbcTemplate.query(sql, params, rs -> {
        if (methods.size() >= request.getMaxResults()) {
            logger.trace("Ignoring row {}, since max result already achieved", rs.getRow());
            return;
        }
        String signature = rs.getString("signature");
        SignatureStatus2 status = SignatureStatus2.valueOf(rs.getString("status"));
        if (request.isSuppressUntrackedMethods() && !status.isTracked()) {
            logger.trace("Suppressing untracked method {} with status {}", signature, status);
            return;
        }
        Long lastInvokedAtMillis = pricePlan.adjustTimestampMillis(rs.getLong("lastInvokedAtMillis"), clock);
        if (lastInvokedAtMillis > request.getOnlyInvokedBeforeMillis()) {
            logger.trace("Suppressing method invoked after requested range");
            return;
        }
        if (lastInvokedAtMillis < request.getOnlyInvokedAfterMillis()) {
            logger.trace("Suppressing method invoked before requested range");
            return;
        }
        methods.add(MethodDescriptor2.builder().id(rs.getLong("id")).signature(signature).trackedPercent(status.isTracked() ? 100 : 0).collectedDays(pricePlan.adjustCollectedDays(getCollectedDays(rs.getTimestamp("latestCollectedSince")))).lastInvokedAtMillis(lastInvokedAtMillis).collectedToMillis(rs.getTimestamp("lastPublishedAt").getTime()).methodAnnotation(rs.getString("methodAnnotation")).methodLocationAnnotation(rs.getString("methodLocationAnnotation")).typeAnnotation(rs.getString("typeAnnotation")).packageAnnotation(rs.getString("packageAnnotation")).build());
    });
    methods.sort(Comparator.comparing(MethodDescriptor2::getSignature));
    long queryTimeMillis = clock.millis() - startedAt;
    logger.debug("Processed {} in {} ms.", request, queryTimeMillis);
    return GetMethodsResponse2.builder().timestamp(startedAt).request(request).numMethods(methods.size()).methods(methods).queryTimeMillis(queryTimeMillis).build();
}
Also used : SignatureStatus2(io.codekvast.javaagent.model.v2.SignatureStatus2) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) ArrayList(java.util.ArrayList) MethodDescriptor2(io.codekvast.dashboard.dashboard.model.methods.MethodDescriptor2) Timestamp(java.sql.Timestamp) PricePlan(io.codekvast.common.customer.PricePlan) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with SignatureStatus2

use of io.codekvast.javaagent.model.v2.SignatureStatus2 in project codekvast by crispab.

the class ImportDAOImpl method ensureInitialInvocations.

private void ensureInitialInvocations(CommonPublicationData2 data, long customerId, long appId, long environmentId, long jvmId, Collection<CodeBaseEntry2> entries, Map<String, Long> existingMethods, Set<Long> existingInvocations) {
    long startedAtMillis = System.currentTimeMillis();
    int importCount = 0;
    for (CodeBaseEntry2 entry : entries) {
        long methodId = existingMethods.get(entry.getSignature());
        if (!existingInvocations.contains(methodId)) {
            SignatureStatus2 initialStatus = calculateInitialStatus(data, entry);
            jdbcTemplate.update(new InsertInvocationStatement(customerId, appId, environmentId, jvmId, methodId, initialStatus, 0L, 0L));
            existingInvocations.add(methodId);
            importCount += 1;
        }
    }
    logger.debug("Imported {} invocations in {} ms", importCount, System.currentTimeMillis() - startedAtMillis);
}
Also used : SignatureStatus2(io.codekvast.javaagent.model.v2.SignatureStatus2) CodeBaseEntry2(io.codekvast.javaagent.model.v2.CodeBaseEntry2)

Example 3 with SignatureStatus2

use of io.codekvast.javaagent.model.v2.SignatureStatus2 in project codekvast by crispab.

the class DashboardIntegrationTest method should_store_all_signature_status_enum_values_correctly.

@Test
@Sql(scripts = "/sql/base-data.sql")
public void should_store_all_signature_status_enum_values_correctly() {
    // given
    // when
    int methodId = 0;
    for (SignatureStatus2 status : SignatureStatus2.values()) {
        methodId += 1;
        jdbcTemplate.update("INSERT INTO invocations(customerId, applicationId, environmentId, methodId, invokedAtMillis, status) VALUES(1, 1, 1, ?, " + "0, ?)", methodId, status.toString());
    }
    // then
    assertThat("Wrong number of invocations rows", countRowsInTable("invocations"), is(SignatureStatus2.values().length));
}
Also used : SignatureStatus2(io.codekvast.javaagent.model.v2.SignatureStatus2) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Example 4 with SignatureStatus2

use of io.codekvast.javaagent.model.v2.SignatureStatus2 in project codekvast by crispab.

the class IntakeIntegrationTest method should_store_all_signature_status_enum_values_correctly.

@Test
@Sql(scripts = "/sql/base-data.sql")
public void should_store_all_signature_status_enum_values_correctly() {
    // given
    // when
    int methodId = 0;
    for (SignatureStatus2 status : SignatureStatus2.values()) {
        methodId += 1;
        jdbcTemplate.update("INSERT INTO invocations(customerId, applicationId, environmentId, methodId, invokedAtMillis, status) VALUES(1, 1, 1, ?, " + "0, ?)", methodId, status.toString());
    }
    // then
    assertThat("Wrong number of invocations rows", countRowsInTable("invocations"), is(SignatureStatus2.values().length));
}
Also used : SignatureStatus2(io.codekvast.javaagent.model.v2.SignatureStatus2) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Aggregations

SignatureStatus2 (io.codekvast.javaagent.model.v2.SignatureStatus2)4 Test (org.junit.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 Sql (org.springframework.test.context.jdbc.Sql)2 PricePlan (io.codekvast.common.customer.PricePlan)1 MethodDescriptor2 (io.codekvast.dashboard.dashboard.model.methods.MethodDescriptor2)1 CodeBaseEntry2 (io.codekvast.javaagent.model.v2.CodeBaseEntry2)1 Timestamp (java.sql.Timestamp)1 ArrayList (java.util.ArrayList)1 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)1 Transactional (org.springframework.transaction.annotation.Transactional)1