Coder Social home page Coder Social logo

segment-logs's Introduction

segment-logs

Load and process Segment logs from S3.

Getting started

Local processing using Spark

Install dependencies

brew install parallel

python -m venv .venv
source .venv/bin/activate
pip install pyspark

Fetch data

aws configure --profile lightspeed-telemetry
export AWS_PROFILE=lightspeed-telemetry
export AWS_S3_URL=s3://host/prefix
aws s3 sync $AWS_S3_URL data/raw

(Optional) Extract local data and cache (for better local performance)

find data/raw -type f | parallel --bar 'gzcat {} | jq -c "."' > data/all.jsonl

Start PySpark

pyspark

Process data in PySpark

spark.conf.set("spark.sql.debug.maxToStringFields", 1000)
df_all = spark.read.json("./data/all.jsonl")

Example query

from pyspark.sql.functions import col

completions = df_all.alias("completions").alias("completions")
feedback = df_all.filter("event == 'inlineSuggestionFeedback'").alias("feedback")

top = completions.join(feedback, col("completions.properties.metadata.activityId") == col("feedback.properties.activityId")) \
    .where(col("feedback.properties.action") == 0) \
    .groupBy(col("completions.properties.request.prompt")) \
    .count() \
    .orderBy("count", ascending=False)

top.show()

Remote processing using Jupyter

Run the notebook

AWS_S3_URI=s3://<bucket>/segment-logs/<path> \
AWS_PROFILE=<profile name> \
jupyter notebook load.ipynb

Development

Install dependencies

python -m venv .venv
source .venv/bin/activate
pip3 install -r requirements-dev.txt

Run checks

tox -e linters

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.