Search in sources :

Example 1 with InvocationDataPublication2

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

the class HttpInvocationDataPublisherImpl method doPublishInvocationData.

@Override
void doPublishInvocationData(long recordingIntervalStartedAtMillis, Set<String> invocations) throws CodekvastPublishingException {
    if (invocations.isEmpty()) {
        logger.fine("Codekvast detected no invocations to publish");
        return;
    }
    String url = getConfig().getInvocationDataUploadEndpoint();
    File file = null;
    try {
        InvocationDataPublication2 publication = createPublication(getCustomerId(), recordingIntervalStartedAtMillis, invocations);
        file = FileUtils.serializeToFile(publication, getConfig().getFilenamePrefix("invocations-"), ".ser");
        doPost(file, url, getCodeBaseFingerprint().toString(), publication.getInvocations().size());
        logger.fine(String.format("Codekvast uploaded %d invocations (%s) to %s", publication.getInvocations().size(), LogUtil.humanReadableByteCount(file.length()), url));
    } catch (Exception e) {
        throw new CodekvastPublishingException("Cannot upload invocation data to " + url, e);
    } finally {
        FileUtils.safeDelete(file);
    }
}
Also used : CodekvastPublishingException(io.codekvast.javaagent.publishing.CodekvastPublishingException) File(java.io.File) CodekvastPublishingException(io.codekvast.javaagent.publishing.CodekvastPublishingException) InvocationDataPublication2(io.codekvast.javaagent.model.v2.InvocationDataPublication2)

Example 2 with InvocationDataPublication2

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

the class IntakeIntegrationTest method should_import_invocationDataPublication.

@Test
public void should_import_invocationDataPublication() {
    // given
    assertThat(countRowsInTable("applications"), is(0));
    assertThat(countRowsInTable("environments"), is(0));
    assertThat(countRowsInTable("jvms"), is(0));
    assertThat(countRowsInTable("methods"), is(0));
    assertThat(countRowsInTable("invocations"), is(0));
    long intervalStartedAtMillis = System.currentTimeMillis();
    InvocationDataPublication2 publication = InvocationDataPublication2.builder().commonData(CommonPublicationData2.sampleCommonPublicationData()).recordingIntervalStartedAtMillis(intervalStartedAtMillis).invocations(new HashSet<>(asList("signature", SYNTHETIC_SIGNATURE))).build();
    // when
    invocationDataImporter.importPublication(publication);
    // then
    assertThat(countRowsInTable("applications WHERE name = ?", publication.getCommonData().getAppName()), is(1));
    assertThat(countRowsInTable("environments WHERE name = ?", publication.getCommonData().getEnvironment()), is(1));
    assertThat(countRowsInTable("jvms WHERE uuid = ?", publication.getCommonData().getJvmUuid()), is(1));
    assertThat(countRowsInTable("methods"), is(1));
    assertThat(countRowsInTable("methods WHERE signature = ?", "signature"), is(1));
    assertThat(countRowsInTable("invocations"), is(1));
    assertThat(countRowsInTable("invocations WHERE invokedAtMillis = ?", intervalStartedAtMillis), is(1));
    assertThat(countRowsInTable("invocations WHERE status = ?", INVOKED.name()), is(1));
}
Also used : InvocationDataPublication2(io.codekvast.javaagent.model.v2.InvocationDataPublication2) HashSet(java.util.HashSet) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 3 with InvocationDataPublication2

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

the class IntakeIntegrationTest method should_import_invocationDataPublication_then_codeBasePublication.

@Test
public void should_import_invocationDataPublication_then_codeBasePublication() {
    // given
    assertThat(countRowsInTable("applications"), is(0));
    assertThat(countRowsInTable("environments"), is(0));
    assertThat(countRowsInTable("jvms"), is(0));
    assertThat(countRowsInTable("methods"), is(0));
    assertThat(countRowsInTable("invocations"), is(0));
    CommonPublicationData2 commonData = CommonPublicationData2.sampleCommonPublicationData();
    CodeBaseEntry3 codeBaseEntry = CodeBaseEntry3.sampleCodeBaseEntry();
    CodeBasePublication3 codeBasePublication = CodeBasePublication3.builder().commonData(commonData).entries(asList(codeBaseEntry)).build();
    val signature = codeBaseEntry.getSignature();
    long intervalStartedAtMillis = System.currentTimeMillis();
    InvocationDataPublication2 invocationDataPublication = InvocationDataPublication2.builder().commonData(commonData).recordingIntervalStartedAtMillis(intervalStartedAtMillis).invocations(singleton(signature)).build();
    // when
    invocationDataImporter.importPublication(invocationDataPublication);
    // then
    assertThat(countRowsInTable("applications WHERE name = ?", codeBasePublication.getCommonData().getAppName()), is(1));
    assertThat(countRowsInTable("environments WHERE name = ?", codeBasePublication.getCommonData().getEnvironment()), is(1));
    assertThat(countRowsInTable("jvms WHERE uuid = ?", codeBasePublication.getCommonData().getJvmUuid()), is(1));
    assertThat(countRowsInTable("methods WHERE signature = ?", signature), is(1));
    assertThat(countRowsInTable("method_locations"), is(0));
    assertThat(countRowsInTable("invocations"), is(1));
    assertThat(countRowsInTable("invocations WHERE invokedAtMillis = ?", intervalStartedAtMillis), is(1));
    assertThat(countRowsInTable("invocations WHERE status = ?", INVOKED.name()), is(1));
    // given
    long intervalStartedAtMillis2 = intervalStartedAtMillis + 3600;
    // when
    invocationDataImporter.importPublication(invocationDataPublication.toBuilder().recordingIntervalStartedAtMillis(intervalStartedAtMillis2).build());
    // then
    assertThat(countRowsInTable("invocations"), is(1));
    assertThat(countRowsInTable("invocations WHERE invokedAtMillis = ?", intervalStartedAtMillis2), is(1));
    assertThat(countRowsInTable("invocations WHERE status = ?", INVOKED.name()), is(1));
    // when
    codeBaseImporter.importPublication(codeBasePublication);
    // then
    assertThat(countRowsInTable("applications WHERE name = ?", codeBasePublication.getCommonData().getAppName()), is(1));
    assertThat(countRowsInTable("environments WHERE name = ?", codeBasePublication.getCommonData().getEnvironment()), is(1));
    assertThat(countRowsInTable("jvms WHERE uuid = ?", codeBasePublication.getCommonData().getJvmUuid()), is(1));
    assertThat(countRowsInTable("methods WHERE signature = ?", signature), is(1));
    assertThat(countRowsInTable("method_locations WHERE location = ?", codeBaseEntry.getMethodSignature().getLocation()), is(1));
    assertThat(countRowsInTable("invocations"), is(1));
    assertThat(countRowsInTable("invocations WHERE invokedAtMillis = ?", intervalStartedAtMillis2), is(1));
    assertThat(countRowsInTable("invocations WHERE status = ?", INVOKED.name()), is(1));
}
Also used : lombok.val(lombok.val) CommonPublicationData2(io.codekvast.javaagent.model.v2.CommonPublicationData2) CodeBasePublication3(io.codekvast.javaagent.model.v3.CodeBasePublication3) CodeBaseEntry3(io.codekvast.javaagent.model.v3.CodeBaseEntry3) InvocationDataPublication2(io.codekvast.javaagent.model.v2.InvocationDataPublication2) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 4 with InvocationDataPublication2

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

the class IntakeIntegrationTest method should_import_codeBasePublication_then_invocationDataPublication_twice.

@Test
public void should_import_codeBasePublication_then_invocationDataPublication_twice() {
    // given
    assertThat(countRowsInTable("applications"), is(0));
    assertThat(countRowsInTable("environments"), is(0));
    assertThat(countRowsInTable("jvms"), is(0));
    assertThat(countRowsInTable("methods"), is(0));
    assertThat(countRowsInTable("invocations"), is(0));
    String signature1 = "signature1";
    String signature2 = "signature2";
    CodeBaseEntry3 codeBaseEntry1 = CodeBaseEntry3.sampleCodeBaseEntry().toBuilder().signature(signature1).build();
    CodeBaseEntry3 codeBaseEntry2 = CodeBaseEntry3.sampleCodeBaseEntry().toBuilder().signature(signature2).build();
    CommonPublicationData2 commonData = CommonPublicationData2.sampleCommonPublicationData();
    CodeBasePublication3 codeBasePublication = CodeBasePublication3.builder().commonData(commonData).entries(asList(codeBaseEntry1, codeBaseEntry2)).build();
    // when Import a code base with two distinct signatures
    codeBaseImporter.importPublication(codeBasePublication);
    // then
    assertThat(countRowsInTable("applications WHERE name = ?", codeBasePublication.getCommonData().getAppName()), is(1));
    assertThat(countRowsInTable("environments WHERE name = ?", codeBasePublication.getCommonData().getEnvironment()), is(1));
    assertThat(countRowsInTable("jvms WHERE uuid = ?", codeBasePublication.getCommonData().getJvmUuid()), is(1));
    assertThat(countRowsInTable("methods"), is(2));
    assertThat(countRowsInTable("methods WHERE signature = ?", signature1), is(1));
    assertThat(countRowsInTable("methods WHERE signature = ?", signature2), is(1));
    assertThat(countRowsInTable("method_locations"), is(2));
    assertThat(countRowsInTable("invocations"), is(2));
    assertThat(countRowsInTable("invocations WHERE invokedAtMillis = 0"), is(2));
    assertThat(countRowsInTable("invocations WHERE status = ?", NOT_INVOKED.name()), is(2));
    // given
    long intervalStartedAtMillis1 = System.currentTimeMillis();
    InvocationDataPublication2 invocationDataPublication1 = InvocationDataPublication2.builder().commonData(commonData).recordingIntervalStartedAtMillis(intervalStartedAtMillis1).invocations(singleton(signature1)).build();
    long intervalStartedAtMillis2 = intervalStartedAtMillis1 + 3600;
    InvocationDataPublication2 invocationDataPublication2 = invocationDataPublication1.toBuilder().recordingIntervalStartedAtMillis(intervalStartedAtMillis2).build();
    // when Record the invocation of one of the signatures twice in reversed time order
    invocationDataImporter.importPublication(invocationDataPublication2);
    invocationDataImporter.importPublication(invocationDataPublication1);
    // then
    assertThat(countRowsInTable("invocations"), is(2));
    assertThat(countRowsInTable("invocations WHERE invokedAtMillis = ?", 0), is(1));
    assertThat(countRowsInTable("invocations WHERE invokedAtMillis = ?", intervalStartedAtMillis1), is(0));
    assertThat(countRowsInTable("invocations WHERE invokedAtMillis = ?", intervalStartedAtMillis2), is(1));
    assertThat(countRowsInTable("invocations WHERE status = ?", NOT_INVOKED.name()), is(1));
    assertThat(countRowsInTable("invocations WHERE status = ?", INVOKED.name()), is(1));
    // given
    setSecurityContextCustomerId(commonData.getCustomerId());
}
Also used : CommonPublicationData2(io.codekvast.javaagent.model.v2.CommonPublicationData2) CodeBasePublication3(io.codekvast.javaagent.model.v3.CodeBasePublication3) CodeBaseEntry3(io.codekvast.javaagent.model.v3.CodeBaseEntry3) InvocationDataPublication2(io.codekvast.javaagent.model.v2.InvocationDataPublication2) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 5 with InvocationDataPublication2

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

the class InvocationDataImporterImpl method importPublication.

@Override
@Transactional(rollbackFor = Exception.class)
public boolean importPublication(InvocationDataPublication2 publication) {
    logger.info("Importing {}", publication);
    CommonPublicationData2 commonData = publication.getCommonData();
    long customerId = commonData.getCustomerId();
    long appId = importDAO.importApplication(commonData);
    long environmentId = importDAO.importEnvironment(commonData);
    long jvmId = importDAO.importJvm(commonData, appId, environmentId);
    importDAO.importInvocations(customerId, appId, environmentId, jvmId, publication.getRecordingIntervalStartedAtMillis(), new TreeSet<>(publication.getInvocations()));
    return true;
}
Also used : CommonPublicationData2(io.codekvast.javaagent.model.v2.CommonPublicationData2) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

InvocationDataPublication2 (io.codekvast.javaagent.model.v2.InvocationDataPublication2)5 CommonPublicationData2 (io.codekvast.javaagent.model.v2.CommonPublicationData2)3 Test (org.junit.Test)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 CodeBaseEntry3 (io.codekvast.javaagent.model.v3.CodeBaseEntry3)2 CodeBasePublication3 (io.codekvast.javaagent.model.v3.CodeBasePublication3)2 CodekvastPublishingException (io.codekvast.javaagent.publishing.CodekvastPublishingException)1 BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 ObjectInputStream (java.io.ObjectInputStream)1 HashSet (java.util.HashSet)1 lombok.val (lombok.val)1 Test (org.junit.jupiter.api.Test)1 Transactional (org.springframework.transaction.annotation.Transactional)1