From ff977c428a1c6e5ec6df833da90d588bb816f784 Mon Sep 17 00:00:00 2001 From: Andrew Hayworth Date: Thu, 28 Jan 2021 13:42:42 -0600 Subject: [PATCH] Pull config from env --- README.md | 11 +++++- bin/compile | 77 ++++++++---------------------------- extra/lightstep-collector.sh | 3 +- 3 files changed, 27 insertions(+), 64 deletions(-) diff --git a/README.md b/README.md index d61267c..a5f7a0f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,11 @@ # heroku-buildpack-lightstep-collector -Heroku buildpack to run the lightstep collector in each dyno -Honestly not sure this even works yet. +Heroku buildpack to run the lightstep collector in each dyno. + +## Configuration + +Configure this buildpack by setting configuration variables for your app. At minimum, you must set: +- `COLLECTOR_SATELLITE_KEY`: the satellite requires this to function. +- `COLLECTOR_PLAIN_PORT`: the satellite tries to bind to port 80 by default, which will not work with Heroku. + +Additional configuration variables can be found [in LightStep's documentation](https://docs.lightstep.com/docs/docker-install-and-configure-satellites). diff --git a/bin/compile b/bin/compile index d8bb74a..3cfa5ba 100755 --- a/bin/compile +++ b/bin/compile @@ -1,10 +1,7 @@ #!/usr/bin/env bash set -eo pipefail - -if [[ -n "$LS_BUILDPACK_DEBUG" ]]; then - set -x -fi +set -x BUILD_DIR=$1 CACHE_DIR=$2 @@ -14,68 +11,28 @@ BUILDPACK_DIR=$(cd "$(dirname "$0")"; cd ..; pwd) LS_DIR="$BUILD_DIR/.lightstep-collector" PROFILE_DIR="$BUILD_DIR/.profile.d" -VERSION="2020.09.24.05.22.16Z" +VERSION="2021.01.26.23.02.36Z" CACHED_VERSION="$CACHE_DIR/lightstep-collector-$VERSION" arrow() { echo '----->' "$@" } -fetch_lightstep() { - if [ ! -f "$CACHED_VERSION" ]; then - arrow "Installing LightStep collector ${VERSION}" - wget \ - -O lightstep-collector.deb \ - --quiet \ - --content-disposition \ - https://packagecloud.io/lightstep/collector/packages/ubuntu/bionic/lightstep-collector_${VERSION}_amd64.deb/download.deb +if [ ! -f "$CACHED_VERSION" ]; then + arrow "Installing LightStep collector ${VERSION}" + wget \ + -O lightstep-collector.deb \ + --quiet \ + --content-disposition \ + https://packagecloud.io/lightstep/collector/packages/ubuntu/bionic/lightstep-collector_${VERSION}_amd64.deb/download.deb - dpkg -x lightstep-collector.deb "$CACHED_VERSION" - else - arrow "LightStep collector ${VERSION} found in cache" - fi -} + dpkg -x lightstep-collector.deb "$CACHED_VERSION" +else + arrow "LightStep collector ${VERSION} found in cache" +fi -write_config() { - for var in LS_API_KEY LS_POOL LS_SERVICE LS_BYTES_PER_PROJECT; do - if [[ -f "$ENV_DIR/$var" ]]; then - export "$var=$(cat "$ENV_DIR/$var")" - fi - done +mkdir -p "$LS_DIR" +cp "$CACHED_VERSION/opt/lightstep/collector" "$LS_DIR/collector" - LS_API_KEY=${LS_API_KEY:-badkey} - LS_POOL=${LS_POOL:-heroku} - LS_GUID="${LS_SERVICE:-heroku-service}-${DYNO:-unknown-dyno}" - LS_BYTES_PER_PROJECT=${LS_BYTES_PER_PROJECT:-100000} - cat < "$LS_DIR/config.yaml" -api_key: ${LS_API_KEY} -pool: ${LS_POOL} -guid: ${LS_GUID} -babysitter_port: 8000 -plain_port: 8383 -admin: - plain_port: 8080 -http: - plain_port: 8181 -grpc: - plain_port: 8282 -instrument: - start_wait_time_limit: 30s -reporter: - bytes_per_project: ${LS_BYTES_PER_PROJECT} - span_group_update_period: 2s -EOF - -} - -install_lightstep() { - mkdir -p "$LS_DIR" - cp "$CACHED_VERSION/opt/lightstep/collector" "$LS_DIR/collector" - - mkdir -p "$PROFILE_DIR" - cp "$BUILDPACK_DIR/extra/lightstep-collector.sh" "$PROFILE_DIR/lightstep-collector.sh" -} - -fetch_lightstep -install_lightstep -write_config +mkdir -p "$PROFILE_DIR" +cp "$BUILDPACK_DIR/extra/lightstep-collector.sh" "$PROFILE_DIR/lightstep-collector.sh" diff --git a/extra/lightstep-collector.sh b/extra/lightstep-collector.sh index 0290014..c4fc6fb 100644 --- a/extra/lightstep-collector.sh +++ b/extra/lightstep-collector.sh @@ -2,5 +2,4 @@ ulimit -n $(ulimit -n -H) -LS_DIR="$HOME/.lightstep-collector" -"$LS_DIR/collector" --collector_base_config="$LS_DIR/config.yaml" 2>&1 & +"$HOME/.lightstep-collector/collector" 2>&1 &