Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] The user_agent processor throws exceptions with multiple threads. #4618

Closed
dlvenable opened this issue Jun 11, 2024 · 2 comments · Fixed by #4619
Closed

[BUG] The user_agent processor throws exceptions with multiple threads. #4618

dlvenable opened this issue Jun 11, 2024 · 2 comments · Fixed by #4619
Assignees
Labels
bug Something isn't working
Milestone

Comments

@dlvenable
Copy link
Member

Describe the bug

I'm seeing a number of errors such as:

2024-06-05T20:54:54.420 [my-pipeline-processor-worker-1-thread-2] ERROR org.opensearch.dataprepper.plugins.processor.useragent.UserAgentProcessor - An exception occurred when parsing user agent data from event [******] with source key [******]
java.lang.IllegalStateException: Entry.next=null, data[removeIndex]=***
 previous=***
 key=***
 size=1000 maxSize=1000 This should not occur if your keys are immutable, and you have used synchronization properly.
 at org.apache.commons.collections4.map.LRUMap.reuseMapping(LRUMap.java:384) ~[commons-collections4-4.4.jar:4.4]
 at org.apache.commons.collections4.map.LRUMap.addMapping(LRUMap.java:349) ~[commons-collections4-4.4.jar:4.4]
 at org.apache.commons.collections4.map.AbstractHashedMap.put(AbstractHashedMap.java:289) ~[commons-collections4-4.4.jar:4.4]
 at ua_parser.CachingParser.parseUserAgent(CachingParser.java:92) ~[uap-java-1.6.1.jar:?]
 at ua_parser.Parser.parse(Parser.java:83) ~[uap-java-1.6.1.jar:?]
 at ua_parser.CachingParser.parse(CachingParser.java:72) ~[uap-java-1.6.1.jar:?]
 at org.opensearch.dataprepper.plugins.processor.useragent.UserAgentProcessor.doExecute(UserAgentProcessor.java:51) ~[user-agent-processor-2.x.88.jar:?]
 at org.opensearch.dataprepper.model.processor.AbstractProcessor.lambda$execute$0(AbstractProcessor.java:54) ~[data-prepper-api-2.x.88.jar:?]
 at io.micrometer.core.instrument.composite.CompositeTimer.record(CompositeTimer.java:69) ~[micrometer-core-1.13.0.jar:1.13.0]
 at org.opensearch.dataprepper.model.processor.AbstractProcessor.execute(AbstractProcessor.java:54) ~[data-prepper-api-2.x.88.jar:?]

To Reproduce

It is not very easy to reproduce this consistently.

  1. Create a pipeline with the user_agent processor.
  2. Be sure to have multiple workers in the pipeline.
  3. Ingest a significant volume of data
  4. These errors should occur.

Expected behavior

No errors, and cache works.

@dlvenable
Copy link
Member Author

I found this issue which seems to be the cause.

ua-parser/uap-java#41

Rather than try to synchronize in the processor, I'm going to write a new implementation of Parser which uses a Caffeine cache.

dlvenable added a commit to dlvenable/data-prepper that referenced this issue Jun 12, 2024
dlvenable added a commit to dlvenable/data-prepper that referenced this issue Jun 12, 2024
@dlvenable dlvenable added this to the v2.9 milestone Jun 12, 2024
@dlvenable dlvenable moved this from Unplanned to In progress in Data Prepper Tracking Board Jun 12, 2024
@dlvenable dlvenable moved this from In progress to In review in Data Prepper Tracking Board Jun 12, 2024
@dlvenable
Copy link
Member Author

Reproduction

pipeline.yaml

empty-dlq-pipeline:
  workers: 2
  source:
    http:

  buffer:
    bounded_blocking:
      buffer_size: 500000
      batch_size: 10000

  processor:
    - user_agent:
        source: log
        target: user_agent

  sink:
    #- stdout:
    - opensearch:
        hosts: [ "https://opensearch:9200" ]
        insecure: true
        username: admin
        password: admin
        index: test_documents

docker-compose.yml

services:
  data-prepper:
    container_name: data-prepper
    #image: opensearchproject/data-prepper:2
    image: opensearch-data-prepper:2.9.0-SNAPSHOT
    depends_on:
      - opensearch
    volumes:
      - ./data-prepper/pipelines:/usr/share/data-prepper/pipelines
      - ./data-prepper/config/data-prepper-config.yaml:/usr/share/data-prepper/config/data-prepper-config.yaml
    ports:
      - "2021:2021"
      - "4900:4900"
    networks:
      - data-prepper-test

  opensearch:
    container_name: opensearch
    image: opensearchproject/opensearch:2.11.1
    environment:
      - discovery.type=single-node
      - bootstrap.memory_lock=true # along with the memlock settings below, disables swapping
      - "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m" # minimum and maximum Java heap size, recommend setting both to 50% of system RAM
    ulimits:
      memlock:
        soft: -1
        hard: -1
      nofile:
        soft: 65536 # maximum number of open files for the OpenSearch user, set to at least 65536 on modern systems
        hard: 65536
    ports:
      - 9200:9200
      - 9600:9600 # required for Performance Analyzer
    networks:
      - data-prepper-test
  dashboards:
    image: opensearchproject/opensearch-dashboards:2.11.1
    container_name: opensearch-dashboards
    ports:
      - 5601:5601
    expose:
      - "5601"
    environment:
      OPENSEARCH_HOSTS: '["https://opensearch:9200"]'
    depends_on:
      - opensearch
    networks:
      - data-prepper-test

networks:
  data-prepper-test:

Test execution

Change Chain::sendApacheCommonLogPostRequest in performance-test project to:

    public static ChainBuilder sendApacheCommonLogPostRequest(final String name, final int batchSize) {
        return CoreDsl.exec(
                HttpDsl.http(name)
                        .post(PathTarget.getPath())
                        .body(CoreDsl.StringBody(Templates.userAgent(batchSize))));
    }

Run:

./gradlew :performance-test:gatlingRun-org.opensearch.dataprepper.test.performance.TargetRpsSimulation

dlvenable added a commit that referenced this issue Jun 13, 2024
Adds and uses a Caffeine-based caching parser for the user_agent processor. Resolves #4618

Signed-off-by: David Venable <[email protected]>
@github-project-automation github-project-automation bot moved this from In review to Done in Data Prepper Tracking Board Jun 13, 2024
dlvenable added a commit that referenced this issue Jun 14, 2024
…4620)

Changes to the performance-test project to generate User Agent strings. Used to help reproduce and test #4618.

Signed-off-by: David Venable <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Development

Successfully merging a pull request may close this issue.

1 participant