Skip to content

Commit

Permalink
allow token to be set during autoinstall
Browse files Browse the repository at this point in the history
  • Loading branch information
smithclay committed Feb 28, 2024
1 parent 6bc3369 commit 277cf92
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 18 deletions.
4 changes: 2 additions & 2 deletions collector/config/otelcol-linux-hostmetrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ exporters:
otlp/lightstep:
endpoint: ingest.lightstep.com:443
headers:
"lightstep-access-token": "${LS_TOKEN}"
"lightstep-access-token": "YOUR_TOKEN"
sending_queue:
enabled: true
num_consumers: 4
Expand Down Expand Up @@ -78,4 +78,4 @@ service:
metrics/host:
receivers: [hostmetrics]
processors: [batch, resourcedetection]
exporters: [debug]
exporters: [debug, otlp/lightstep]
6 changes: 3 additions & 3 deletions collector/config/otelcol-macos-hostmetrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ exporters:
otlp/lightstep:
endpoint: ingest.lightstep.com:443
headers:
"lightstep-access-token": "${LS_TOKEN}"
"lightstep-access-token": "YOUR_TOKEN"
sending_queue:
enabled: true
num_consumers: 4
Expand Down Expand Up @@ -74,8 +74,8 @@ service:
metrics/collector:
receivers: [prometheus/self]
processors: [batch, resourcedetection]
exporters: [debug]
exporters: [debug, otlp/lightstep]
metrics/host:
receivers: [hostmetrics]
processors: [batch, resourcedetection]
exporters: [debug]
exporters: [debug, otlp/lightstep]
15 changes: 11 additions & 4 deletions collector/scripts/install/install-macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,6 @@ set_ingest_token()
fi

INGEST_TOKEN="$ingest_token"

if [ -n "$INGEST_TOKEN" ] && [ -z "$INGEST_ENDPOINT" ]; then
error_exit "$LINENO" "An endpoint must be specified when providing an ingest token"
fi
}

# latest_version gets the tag of the latest release, without the v prefix.
Expand All @@ -377,6 +373,12 @@ latest_version()
sed -E 's/ *"tag_name": "v([0-9]+\.[0-9]+\.[0-9+])",/\1/'
}

# set the access token, if one was specified
set_access_token()
{
sed -i "s/YOUR_TOKEN/$INGEST_TOKEN/g" /opt/sn-collector/config.yaml
}

# This will install the package by downloading & unpacking the tarball into the install directory
install_package()
{
Expand Down Expand Up @@ -447,6 +449,11 @@ install_package()
launchctl load -w "/Library/LaunchDaemons/$SERVICE_NAME.plist" > /dev/null 2>&1 || error_exit "$LINENO" "Failed to load service file /Library/LaunchDaemons/$SERVICE_NAME.plist"
succeeded

if [ -n "$INGEST_TOKEN" ]; then
info "Setting access token..."
set_access_token
fi

info "Starting service..."
launchctl start "$SERVICE_NAME" || error_exit "$LINENO" "Failed to start service file $SERVICE_NAME"
succeeded
Expand Down
17 changes: 12 additions & 5 deletions collector/scripts/install/install-unix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -492,10 +492,6 @@ set_ingest_token()
fi

INGEST_TOKEN="$ingest_token"

if [ -n "$INGEST_TOKEN" ] && [ -z "$INGEST_ENDPOINT" ]; then
error_exit "$LINENO" "An endpoint must be specified when providing an ingest token"
fi
}


Expand All @@ -507,6 +503,12 @@ latest_version()
sed -E 's/ *"tag_name": "v([0-9]+\.[0-9]+\.[0-9+])",/\1/'
}

# set the access token, if one was specified
set_access_token()
{
sed -i "s/YOUR_TOKEN/$INGEST_TOKEN/g" /opt/sn-collector/config.yaml
}

# This will install the package by downloading the archived agent,
# extracting the binaries, and then removing the archive.
install_package()
Expand Down Expand Up @@ -543,6 +545,11 @@ install_package()
unpack_package || error_exit "$LINENO" "Failed to extract package"
succeeded

if [ -n "$INGEST_TOKEN" ]; then
info "Setting access token..."
set_access_token
fi

if [ "$(systemctl is-enabled sn-collector)" = "enabled" ]; then
# The unit is already enabled; It may be running, too, if this was an upgrade.
# We'll want to restart, which will start it if it wasn't running already,
Expand Down Expand Up @@ -586,7 +593,7 @@ display_results()
info "Collector Config: $(fg_cyan "/opt/sn-collector/config.yaml")$(reset)"
info "Start Command: $(fg_cyan "sudo systemctl start sn-collector")$(reset)"
info "Stop Command: $(fg_cyan "sudo systemctl stop sn-collector")$(reset)"
info "Logs Command: $(fg_cyan "sudo tail -F /opt/sn-collector/log/collector.log")$(reset)"
info "Logs Command: $(fg_cyan "sudo journalctl -u sn-collector -f")$(reset)"
decrease_indent

banner 'Support'
Expand Down
5 changes: 3 additions & 2 deletions docs/monitor-linux.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@

This install approach automatically downloads dependencies and installs the collector as a service on Linux using a Debian or RPM package. Priviliged (root) access is needed.

1. As `sudo`, run the following in your shell:
1. As `sudo`, run the following in your shell. If you do not specify an optional token, edit the configuration file after install complete.
- ```sh
sudo sh -c "$(curl -fsSlL https://github.com/lightstep/sn-collector/releases/latest/download/install-unix.sh)" install_unix.sh
export CLOUDOBS_TOKEN='your-cloudobs-access-token'
sudo sh -c "$(curl -fsSlL https://github.com/lightstep/sn-collector/releases/latest/download/install-unix.sh)" install_unix.sh --ingest-token $CLOUDOBS_TOKEN
```

2. Review the collector configuration installed in `/opt/sn-collector/config.yaml`. The collector will automatically start running with the default configuration.
Expand Down
5 changes: 3 additions & 2 deletions docs/monitor-macos.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ The last three macOS versions are supported on both Intel (AMD64) and Apple Sili

This install approach automatically downloads dependencies and installs the collector as a service on macOS. Priviliged (root) access is needed.

1. As `sudo`, run the following in your shell:
1. As `sudo`, run the following in your shell. If you do not specify an optional token, edit the configuration file after install complete.
- ```sh
sudo sh -c "$(curl -fsSlL https://github.com/lightstep/sn-collector/releases/latest/download/install-macos.sh)" install_macos.sh
export CLOUDOBS_TOKEN='your-cloudobs-access-token'
sudo sh -c "$(curl -fsSlL https://github.com/lightstep/sn-collector/releases/latest/download/install-macos.sh)" install_macos.sh --ingest-token $CLOUDOBS_TOKEN
```

2. Review the collector configuration installed in `/opt/sn-collector/config.yaml`. The collector will automatically start running with the default configuration.
Expand Down

0 comments on commit 277cf92

Please sign in to comment.