Skip to content

[FEATURE] Standalone PPL streams & library  #627

Closed

Description

@joshuali925

1. Overview

1.1 Introduction

Piped Processing Language (PPL), powered by OpenSearch, enables OpenSearch users with exploration and discovery of, and finding search patterns in data stored in OpenSearch, using a set of commands delimited by pipes (|). These are essentially read-only requests to process data and return results.

PPL is an OpenSearch query language alternative to DSL. It allows user to pipe output into new PPL commands, providing an experience that’s similar to the unix command line. Users can build the query command by command gradually and check intermediate results instead of getting a complex query correct at the first run. This makes the query easy to understand and allows users to correct any mistakes early. Since PPL is a generic language and not necessarily tied to OpenSearch, it is possible to separate PPL into a standalone Java library to use in other places such as data-prepper processor.

This document will focus on the design of PPL library and its integration with data-prepper, and also explore some other possibilities of PPL library.

1.2 Possible Use Cases

1. PPL for metrics extraction at ingestion time

Currently, PPL can be used in OpenSearch to aggregate multiple log lines at query time to get metrics (e.g. sum, average, standard deviation, etc). Users construct monitoring dashboards from these metrics to identify possible anomalies in their services. When an anomaly is found in metrics, users will then go to the corresponding logs to check the specific error messages. This workflow can be simplified by computing metrics at ingestion time instead of query time, which brings some benefits such as being able to use S3 as log storage to reduce indexing and storage costs (see #595 for more details). Integrating PPL into ingestion tools to achieve this can improve the user experience.

With PPL library decoupled from OpenSearch engine and integrated with ingestion tools, PPL queries used in OpenSearch to generate metrics can be pasted directly into ingestion setup. This allows metrics to be computed at ingestion time without additional configuration and learning efforts on the ingestion side. For example, data-prepper, logstash, fluentd might have different mechanisms to extract metrics. With a PPL plugin, users don’t need to learn how to configure metrics extractions for any of them. They only need to understand PPL.

2. PPL as a general command line tool

While there are many powerful tools in the command line, it can still be difficult to work with log/events data and perform meaningful computations, especially for csv or ndjson files. By implementing an input handler in the library in front of PPL engine, PPL will be able to read from STDIN or files on disk. Similar to q which lets users run SQL on csv files, PPL CLI will allow users to do the same operations they are familiar with in OpenSearch PPL to their files for analysis (for example, analyze csv downloaded from reporting plugin). This also allows them to run PPL in shell scripts or cron jobs for real time metrics monitoring without OpenSearch.

Sample usage:

tail -n 5000 ./app.log | java -jar PPL.jar \
    "source = - \
    | parse method=json \
    | where timestamp > '$(date -d'now-15min' +'%Y-%m-%dT%H:%M:%SZ')' \
    | stats count() as ip by host, response"

3. PPL as a connector to remote data sources
Additionally, it can be possible to add clients for other data sources (e.g. OpenSearch, Prometheus, S3). This gives user a consistent experience to connect to different data sources with the same experience.

Sample usage:

java -jar PPL.jar --config=ppl.yml \
    'source = s3.apache_logs \
    | parse method=grok "%{COMMONAPACHELOG}" \
    | where response = 404 \
    | stats count() as ip by host, response'

1.3 Project Goal Summary

Make PPL into a generic and universal language that can be used in different environments, including at ingestion time, to create a consistent query language experience.

2. Requirements

2.1 Functional Requirements

PPL core

  • Support more parse methods (json, grok) in addition to regex in parse command
  • Support more date formats (ISO, custom) for data type casts in cast() function
  • Support JSON schema for query response

PPL library

  • Syntax and in-memory computations in PPL library should be the same as OpenSearch PPL
  • Should allow user to define schema separately or use a default schema
  • Should be able to integrate with ingestion tools (data-prepper) through plugins

PPL library for command line usage (needs discussion or out of scope for P0)

  • Should be able to infer schema if input is JSON or CSV file
  • Support OpenSearch, S3, Prometheus as remote sources

2.2 Non-functional Requirements

  • Should be extensible: easy to integrate with other tools or add additional catalog
  • Query used for ingestion should be mostly the same as the original search query
  • Provide some help in UI for writing PPL queries to generate metrics from raw logs

3. High-Level Design

3.1 PPL Library

PPL Library will implement the in-memory version of the required components from the opensearch module. There will be no optimization since everything will be executed in memory and cannot be pushed down.

libppl-sequence

3.2 Comparison of OpenSearch PPL, PPL Library, and its integration with ingestion tools

pplcomparison drawio

3.2 Data-Prepper Integration

libppl-deployment

A new processor plugin will be added to data-prepper, which handles a batch of buffered logs at each time. The processor plugin will make calls to PPL library with logs and user queries. There can be two options to call PPL library:

Option 1: spawn a new process for PPL.jar

Will be used by non-Java ingestors.

ProcessBuilder builder = new ProcessBuilder("java", "-jar", "libppl.jar", configFile);
Process process = builder.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));

// send logs to PPL
logs.forEach(logLine -> {
    writer.write(logs);
    writer.newLine();
});
writer.close();

// read PPL response
reader.lines();

Option 2: import PPL.jar as a dependency

Will be used by Java based ingestors.

public class LibPPLQueryActionFactory {
  public static LibPPLQueryAction create(Collection<Map<String, Object>> input);
}

public class LibPPLQueryAction {
  public void execute(String pplQuery);
}

Activity

  1. added
    enhancement
    on May 25, 2022
  2. self-assigned this
    on May 25, 2022
  3. changed the title [-][FEATURE] Standalone PPL Library[/-] [+][FEATURE] Standalone PPL streams library [/+] on May 27, 2022
  4. changed the title [-][FEATURE] Standalone PPL streams library [/-] [+][FEATURE] Standalone PPL streams & library [/+] on May 27, 2022
  5. xinlamzn commented on Jun 2, 2022

    @xinlamzn
    Member

    why do we need to integration with S3 in the PPL library? It should be handled by the upstream or downstream, like DataPepper. Direct integration only adds complexity to the PPL library itself.

  6. xinlamzn commented on Jun 2, 2022

    @xinlamzn
    Member

    Regarding DataPepper integration, how could we make sure all required docs are processed by the same PPL instance? The related docs could come from multiple sources and DataPepper may also have multiple workers for scalability. Would the DataPepper docs routing understand the PPL aggregation requirement?

  7. joshuali925 commented on Jun 6, 2022

    @joshuali925
    MemberAuthor

    why do we need to integration with S3 in the PPL library?

    currently it's the only way to get raw logs to S3, but I agree it's not correct design. We can utilize conditional routing from data-prepper 2.0 to support multiple sinks

    how could we make sure all required docs are processed by the same PPL instance?

    just a thought we can have metrics at ingestion node level and aggregate again when displaying in UI, but i can still see issues. this will need more investigation with the data-prepper peer-forwarder


    status update:

    currently PPL library works inside data prepper as a processor plugin, sample pipeline configuration:

    simple-sample-pipeline:
      workers: 1
      delay: "1000"
      source:
        http:
          ssl: false
          authentication:
            unauthenticated:
          port: 2021
      processor:
        - ppl:
            query:
              - "source = stdin | stats count() by method"
              - "source = stdin | stats count() as throughput"
              - "source = stdin | where status > 299 | stats count() as errors"
              - "source = stdin | stats avg(bytes) as avgBytes"
              - "source = stdin | stats sum(bytes) as totalBytes"
      sink:
        - stdout:
        - opensearch:
            hosts: [ "http://localhost:9200" ]
            insecure: true
            index: data_prepper_results
    sample response
    GET {{BASE}}/data_prepper_results/_search
    
          {
            "_index": "data_prepper_results",
            "_id": "8HVkO4EBJcL4QVEgLHSS",
            "_score": 1,
            "_source": {
              "count()": 2,
              "method": "DELETE",
              "timeReceived": "2022-06-06T23:40:29.666388Z"
            }
          },
          {
            "_index": "data_prepper_results",
            "_id": "8XVkO4EBJcL4QVEgLHST",
            "_score": 1,
            "_source": {
              "count()": 1,
              "method": "POST",
              "timeReceived": "2022-06-06T23:40:29.666388Z"
            }
          },
          {
            "_index": "data_prepper_results",
            "_id": "8nVkO4EBJcL4QVEgLHST",
            "_score": 1,
            "_source": {
              "count()": 2,
              "method": "GET",
              "timeReceived": "2022-06-06T23:40:29.666388Z"
            }
          },
          {
            "_index": "data_prepper_results",
            "_id": "83VkO4EBJcL4QVEgLHST",
            "_score": 1,
            "_source": {
              "count()": 2,
              "method": "PATCH",
              "timeReceived": "2022-06-06T23:40:29.666388Z"
            }
          },
          {
            "_index": "data_prepper_results",
            "_id": "9HVkO4EBJcL4QVEgLHST",
            "_score": 1,
            "_source": {
              "count()": 1,
              "method": "PUT",
              "timeReceived": "2022-06-06T23:40:29.666388Z"
            }
          },
          {
            "_index": "data_prepper_results",
            "_id": "9XVkO4EBJcL4QVEgLHST",
            "_score": 1,
            "_source": {
              "throughput": 8,
              "timeReceived": "2022-06-06T23:40:29.666388Z"
            }
          },
          {
            "_index": "data_prepper_results",
            "_id": "9nVkO4EBJcL4QVEgLHST",
            "_score": 1,
            "_source": {
              "errors": 4,
              "timeReceived": "2022-06-06T23:40:29.666388Z"
            }
          },
          {
            "_index": "data_prepper_results",
            "_id": "93VkO4EBJcL4QVEgLHST",
            "_score": 1,
            "_source": {
              "avgBytes": 16886.25,
              "timeReceived": "2022-06-06T23:40:29.666388Z"
            }
          },
          {
            "_index": "data_prepper_results",
            "_id": "-HVkO4EBJcL4QVEgLHST",
            "_score": 1,
            "_source": {
              "timeReceived": "2022-06-06T23:40:29.666388Z",
              "totalBytes": 135090
            }
          },
          {
            "_index": "data_prepper_results",
            "_id": "-XVkO4EBJcL4QVEgMnRj",
            "_score": 1,
            "_source": {
              "count()": 2,
              "method": "HEAD",
              "timeReceived": "2022-06-06T23:40:31.193580Z"
            }
          }

    Currently working on implementing an independent log ingestion and output solution using PPL library, as there are a few dependencies blocked by data-prepper 2.0

  8. dlvenable commented on Jun 22, 2022

    @dlvenable
    Member

    @joshuali925 ,

    Thank you for this proposal. I'd like to suggest that the source = stdin | seems superfluous as a user. Is this adding some value that is not obvious?

    Could this be updated so that users can configure like the following?

    simple-sample-pipeline:
      ...
      processor:
        - ppl:
            query:
              - "stats count() by method"
              - "stats count() as throughput"
              - "where status > 299 | stats count() as errors"
              - "stats avg(bytes) as avgBytes"
              - "stats sum(bytes) as totalBytes"
      sink:
        - stdout:
        - opensearch:
    
  9. joshuali925 commented on Jun 23, 2022

    @joshuali925
    MemberAuthor

    accidentally closed the issue..

    @dlvenable right, the source command is needed in OpenSearch PPL but is not necessary here since source is controlled by the pipeline's source. I kept it as a placeholder but I agree removing it would be better

  10. anirudha commented on Jun 23, 2022

    @anirudha
    Collaborator

    source = stdin | is meant for PPL CLI

  11. anirudha commented on Nov 17, 2022

    @anirudha
    Collaborator

    Requirements

    1. A rest endpoint for plugins in DP which can reload config. or live change config.
    2. we need control plane apis for DP
  12. dlvenable commented on Nov 17, 2022

    @dlvenable
    Member

    @joshuali925 ,

    There may be some confusion about getting events to S3 and OpenSearch. Data Prepper supports routing events to other pipelines.

    I think the ideal solution is that the Data Prepper pipeline route events to two pipelines:

    1. A raw Event pipeline to send to S3
    2. A PPL Processor pipeline to produce results and send to OpenSearch.

    I'm attaching a concept diagram of the pipelines that would be involved.

    PPLPipelineConcept

  13. added and removed
    enhancement
    on Feb 8, 2023
  14. qianheng-aws commented on Apr 1, 2026

    @qianheng-aws
    Collaborator

    Close as resolved by #3734

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions