Search in sources :

Example 31 with UserAgentAnalyzer

use of nl.basjes.parse.useragent.UserAgentAnalyzer in project yauaa by nielsbasjes.

the class TestBuilder method testLoadOnlyCompanyCustomFormatRules.

@Test
void testLoadOnlyCompanyCustomFormatRules() {
    UserAgentAnalyzer userAgentAnalyzer = UserAgentAnalyzer.newBuilder().withoutCache().hideMatcherLoadStats().dropDefaultResources().addResources("CompanyInternalUserAgents.yaml").withFields("ApplicationName", "ApplicationVersion").withFields(Arrays.asList("ApplicationInstance", "ApplicationGitCommit")).withField("ServerName").build();
    UserAgent parsedAgent = userAgentAnalyzer.parse("TestApplication/1.2.3 (node123.datacenter.example.nl; 1234; d71922715c2bfe29343644b14a4731bf5690e66e)");
    // The requested fields
    assertEquals("TestApplication", parsedAgent.getValue("ApplicationName"));
    assertEquals("1.2.3", parsedAgent.getValue("ApplicationVersion"));
    assertEquals("1234", parsedAgent.getValue("ApplicationInstance"));
    assertEquals("d71922715c2bfe29343644b14a4731bf5690e66e", parsedAgent.getValue("ApplicationGitCommit"));
    assertEquals("node123.datacenter.example.nl", parsedAgent.getValue("ServerName"));
}
Also used : UserAgentAnalyzer(nl.basjes.parse.useragent.UserAgentAnalyzer) UserAgent(nl.basjes.parse.useragent.UserAgent) Test(org.junit.jupiter.api.Test)

Example 32 with UserAgentAnalyzer

use of nl.basjes.parse.useragent.UserAgentAnalyzer in project yauaa by nielsbasjes.

the class TestMemoryFootprint method checkForMemoryLeaks.

@Disabled("This is too unreliable and fails much too often.")
@Test
void checkForMemoryLeaks() {
    // ----------------------------------------------
    long memoryInitial = getMemoryUsageAfterGC();
    LOG.info(String.format("1: Startup + GC --> Used memory is %10d bytes (%5d MiB).", memoryInitial, bytesToMegabytes(memoryInitial)));
    // ----------------------------------------------
    UserAgentAnalyzer uaa = UserAgentAnalyzer.newBuilder().immediateInitialization().keepTests().build();
    LOG.info("Init complete");
    long memoryAfterInit = getMemoryUsageAfterGC();
    LOG.info(String.format("2: Init Analyzer + GC --> Used memory is %10d bytes (%5d MiB).", memoryAfterInit, bytesToMegabytes(memoryAfterInit)));
    // ----------------------------------------------
    LOG.info("Run preheat");
    uaa.preHeat();
    LOG.info("Preheat completed");
    long memoryAfterRun = getMemoryUsageAfterGC();
    LOG.info(String.format("3: Run Analyzer + GC --> Used memory is %10d bytes (%5d MiB).", memoryAfterRun, bytesToMegabytes(memoryAfterRun)));
    // ----------------------------------------------
    long memoryAfterDestroy = getMemoryUsageAfterGC();
    LOG.info(String.format("4: Destroy Analyzer + GC --> Used memory is %10d bytes (%5d MiB).", memoryAfterDestroy, bytesToMegabytes(memoryAfterDestroy)));
    // ----------------------------------------------
    long memoryAfterClean = getMemoryUsageAfterGC();
    LOG.info(String.format("5: Null Analyzer + GC --> Used memory is %10d bytes (%5d MiB).", memoryAfterClean, bytesToMegabytes(memoryAfterClean)));
    // ----------------------------------------------
    // Assert the overall delta is below 20 MB
    assertTrue((memoryAfterClean - memoryInitial) < 20_000_000, "To much memory remained after cleanup");
}
Also used : UserAgentAnalyzer(nl.basjes.parse.useragent.UserAgentAnalyzer) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 33 with UserAgentAnalyzer

use of nl.basjes.parse.useragent.UserAgentAnalyzer in project yauaa by nielsbasjes.

the class TestMemoryFootprint method profileMemoryFootprint.

@Disabled
@Test
void profileMemoryFootprint() {
    // NOSONAR: Do not complain about ignored performance test
    printCurrentMemoryProfile("Before ");
    UserAgentAnalyzer uaa = UserAgentAnalyzer.newBuilder().hideMatcherLoadStats().withoutCache().keepTests().build();
    printCurrentMemoryProfile("Loaded ");
    uaa.initializeMatchers();
    printCurrentMemoryProfile("Init   ");
    Runtime.getRuntime().gc();
    printCurrentMemoryProfile("Post GC");
    uaa.setCacheSize(1000);
    uaa.preHeat();
    Runtime.getRuntime().gc();
    printCurrentMemoryProfile("Cache 1K");
    uaa.setCacheSize(10000);
    uaa.preHeat();
    Runtime.getRuntime().gc();
    printCurrentMemoryProfile("Cache 10K");
    uaa.dropTests();
    Runtime.getRuntime().gc();
    printCurrentMemoryProfile("NoTest ");
}
Also used : UserAgentAnalyzer(nl.basjes.parse.useragent.UserAgentAnalyzer) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 34 with UserAgentAnalyzer

use of nl.basjes.parse.useragent.UserAgentAnalyzer in project yauaa by nielsbasjes.

the class TestMemoryFootprint method assesMemoryImpactPerFieldName.

@Disabled
@Test
void assesMemoryImpactPerFieldName() {
    // NOSONAR: Do not complain about ignored performance test
    // Get the Java runtime
    Runtime runtime = Runtime.getRuntime();
    // Calculate the used memory
    long memory = runtime.totalMemory() - runtime.freeMemory();
    LOG.error(String.format("Without Yauaa present and GC --> Used memory is %10d bytes (%5d MiB)", memory, bytesToMegabytes(memory)));
    UserAgentAnalyzer uaa = UserAgentAnalyzer.newBuilder().hideMatcherLoadStats().withoutCache().keepTests().build();
    uaa.preHeat();
    runtime.gc();
    uaa.preHeat();
    runtime.gc();
    // Calculate the used memory
    memory = runtime.totalMemory() - runtime.freeMemory();
    LOG.error(String.format("Querying for 'All fields' and GC --> Used memory is %10d bytes (%5d MiB)", memory, bytesToMegabytes(memory)));
    for (String fieldName : uaa.getAllPossibleFieldNamesSorted()) {
        uaa = UserAgentAnalyzer.newBuilder().withoutCache().withField(fieldName).hideMatcherLoadStats().keepTests().build();
        uaa.preHeat();
        runtime.gc();
        uaa.preHeat();
        runtime.gc();
        // Calculate the used memory
        memory = runtime.totalMemory() - runtime.freeMemory();
        LOG.error(String.format("Querying for %s and GC --> Used memory is %10d bytes (%5d MiB)", fieldName, memory, bytesToMegabytes(memory)));
    }
}
Also used : UserAgentAnalyzer(nl.basjes.parse.useragent.UserAgentAnalyzer) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 35 with UserAgentAnalyzer

use of nl.basjes.parse.useragent.UserAgentAnalyzer in project yauaa by nielsbasjes.

the class TestUserAgentAnalyzerKryoSerialization method deserialize.

UserAgentAnalyzer deserialize(byte[] bytes) {
    Kryo kryo = new Kryo();
    UserAgentAnalyzer.configureKryo(kryo);
    ByteBufferInput byteBufferInput = new ByteBufferInput(bytes);
    return (UserAgentAnalyzer) kryo.readClassAndObject(byteBufferInput);
}
Also used : ByteBufferInput(com.esotericsoftware.kryo.io.ByteBufferInput) UserAgentAnalyzer(nl.basjes.parse.useragent.UserAgentAnalyzer) Kryo(com.esotericsoftware.kryo.Kryo)

Aggregations

UserAgentAnalyzer (nl.basjes.parse.useragent.UserAgentAnalyzer)38 Test (org.junit.jupiter.api.Test)24 UserAgent (nl.basjes.parse.useragent.UserAgent)11 ArrayList (java.util.ArrayList)4 Disabled (org.junit.jupiter.api.Disabled)4 Map (java.util.Map)3 UserAgentAnalyzerBuilder (nl.basjes.parse.useragent.UserAgentAnalyzer.UserAgentAnalyzerBuilder)3 MissingUserAgentException (nl.basjes.parse.useragent.servlet.exceptions.MissingUserAgentException)3 Kryo (com.esotericsoftware.kryo.Kryo)2 ByteBufferInput (com.esotericsoftware.kryo.io.ByteBufferInput)2 Operation (io.swagger.v3.oas.annotations.Operation)2 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ObjectInput (java.io.ObjectInput)2 ObjectInputStream (java.io.ObjectInputStream)2 Field (java.lang.reflect.Field)2 HashMap (java.util.HashMap)2 TestCase (nl.basjes.parse.useragent.config.TestCase)2 IngestDocument (org.elasticsearch.ingest.IngestDocument)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2