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();
}
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);
}
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));
}
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));
}
Aggregations