-
Notifications
You must be signed in to change notification settings - Fork 0
add kindling tester #331
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
Open
WendelHime
wants to merge
7
commits into
main
Choose a base branch
from
feat/add-kindling-tester
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+258
−32
Open
add kindling tester #331
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
281e189
feat: adding map for enabling/disabling kindling transports
WendelHime 1662ff1
feat: adding kindling-tester with docker container
WendelHime 7c0f37f
Merge branch 'main' of github-lantern:getlantern/radiance into feat/a…
WendelHime 0beec4f
fix: disabling all other transports before enabling the selected one
WendelHime 9dc1c0e
Merge branch 'main' of github-lantern:getlantern/radiance into feat/a…
WendelHime 5ca4f41
fix: only adding close to the list of closeTransports
WendelHime 63c9d01
fix: renaming var for avoiding rewriting transport
WendelHime File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # Kindling transport tester | ||
|
|
||
| Tests individual [kindling](../../kindling) transports (proxyless, fronted, amp, dnstt). | ||
| It receives all its arguments via environment variables and uses the kindling HTTP client directly | ||
|
|
||
| ## Environment variables | ||
|
|
||
| ### Required | ||
|
|
||
| - `DEVICE_ID`: The device ID to use. | ||
| - `USER_ID`: The user ID to use. | ||
| - `TOKEN`: The auth token to use. | ||
WendelHime marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - `RUN_ID`: The run ID. Added to traces as `pinger-id` — useful for looking up a specific run. | ||
| - `TARGET_URL`: The URL that will be fetched through kindling. | ||
| - `DATA`: Directory for config files, logs, and output artefacts (`output.txt`, `timing.txt`, `success`). | ||
|
|
||
| - `TRANSPORT`: The kindling transport to test. One of: `proxyless`, `fronted`, `amp`, `dnstt`. | ||
|
|
||
| ## CLI usage | ||
|
|
||
| ```bash | ||
| DEVICE_ID=1234 USER_ID=123 TOKEN=mytoken RUN_ID=run1 TARGET_URL=https://example.com DATA=./mydir \ | ||
| TRANSPORT=proxyless \ | ||
| ./kindling-tester | ||
| ``` | ||
|
|
||
| Replace `proxyless` with the transport you want to test (`fronted`, `amp`, `dnstt`). | ||
|
|
||
| Upon success the tester writes: | ||
| - `DATA/success` — empty marker file | ||
| - `DATA/output.txt` — response body | ||
| - `DATA/timing.txt` — timing breakdown (connect + fetch latency) | ||
|
|
||
| ## Docker usage | ||
|
|
||
| A separate image is built per transport. Each image bakes `TRANSPORT` in at build time via `ENV TRANSPORT=${TRANSPORT}`. | ||
|
|
||
| ### Building | ||
|
|
||
| ```bash | ||
| docker build --build-arg TRANSPORT=proxyless -t radiance-kindling-tester:proxyless -f ./docker/Dockerfile.kindling-tester . | ||
| docker build --build-arg TRANSPORT=fronted -t radiance-kindling-tester:fronted -f ./docker/Dockerfile.kindling-tester . | ||
| docker build --build-arg TRANSPORT=amp -t radiance-kindling-tester:amp -f ./docker/Dockerfile.kindling-tester . | ||
| docker build --build-arg TRANSPORT=dnstt -t radiance-kindling-tester:dnstt -f ./docker/Dockerfile.kindling-tester . | ||
| ``` | ||
|
|
||
| ### Running | ||
|
|
||
| ```bash | ||
| docker run --rm -v ./mydir:/output \ | ||
| -e DEVICE_ID=1234 \ | ||
| -e USER_ID=1234 \ | ||
| -e TOKEN=mytoken \ | ||
| -e RUN_ID=run1 \ | ||
| -e TARGET_URL=https://example.com \ | ||
| -e DATA=/output \ | ||
| radiance-kindling-tester:proxyless | ||
| ``` | ||
|
|
||
| Swap the image tag to test a different transport; no other flags need to change. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "io" | ||
| "log/slog" | ||
| "os" | ||
| "strconv" | ||
| "time" | ||
|
|
||
| "github.com/getlantern/radiance/common/settings" | ||
| "github.com/getlantern/radiance/kindling" | ||
| ) | ||
|
|
||
| func performKindlingPing(ctx context.Context, urlToHit string, runID string, deviceID string, userID int64, token string, dataDir string) error { | ||
| os.MkdirAll(dataDir, 0o755) | ||
WendelHime marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| settings.Set(settings.DataPathKey, dataDir) | ||
| settings.Set(settings.UserIDKey, userID) | ||
| settings.Set(settings.TokenKey, token) | ||
| settings.Set(settings.UserLevelKey, "") | ||
| settings.Set(settings.EmailKey, "pinger@pinger.com") | ||
| settings.Set(settings.DevicesKey, []settings.Device{ | ||
| { | ||
| ID: deviceID, | ||
| Name: deviceID, | ||
| }, | ||
| }) | ||
|
|
||
| t1 := time.Now() | ||
| kindling.SetKindling(kindling.NewKindling()) | ||
| defer kindling.Close(ctx) | ||
| cli := kindling.HTTPClient() | ||
|
|
||
| t2 := time.Now() | ||
| // Run the command and capture the output | ||
| resp, err := cli.Get(urlToHit) | ||
| if err != nil { | ||
| slog.Error("failed on get request", slog.Any("error", err)) | ||
| return err | ||
| } | ||
| defer resp.Body.Close() | ||
|
|
||
| responseBody, err := io.ReadAll(resp.Body) | ||
| if err != nil { | ||
| slog.Error("failed to read response body", slog.Any("error", err)) | ||
| return err | ||
| } | ||
| t3 := time.Now() | ||
| slog.Info("lantern ping completed successfully") | ||
| // create a marker file that will be used by the pinger to determine success | ||
| if err := os.WriteFile(dataDir+"/success", []byte(""), 0o644); err != nil { | ||
| slog.Error("failed to write success file", slog.Any("error", err), slog.String("path", dataDir+"/success")) | ||
| } | ||
| if err := os.WriteFile(dataDir+"/output.txt", responseBody, 0o644); err != nil { | ||
| slog.Error("failed to write output file", slog.Any("error", err), slog.String("path", dataDir+"/output.txt")) | ||
| } | ||
| return os.WriteFile(dataDir+"/timing.txt", []byte(fmt.Sprintf(` | ||
| result: %v | ||
| run-id: %s | ||
| err: %v | ||
| started: %s | ||
| connected: %d | ||
| fetched: %d | ||
| url: %s`, | ||
| true, runID, nil, t1, int32(t2.Sub(t1).Milliseconds()), int32(t3.Sub(t1).Milliseconds()), urlToHit)), 0o644) | ||
| } | ||
|
|
||
| func main() { | ||
| deviceID := os.Getenv("DEVICE_ID") | ||
| userID := os.Getenv("USER_ID") | ||
| token := os.Getenv("TOKEN") | ||
| runID := os.Getenv("RUN_ID") | ||
| targetURL := os.Getenv("TARGET_URL") | ||
| data := os.Getenv("DATA") | ||
| transport := os.Getenv("TRANSPORT") | ||
|
|
||
| slog.SetDefault(slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{ | ||
| Level: slog.LevelDebug, | ||
| }))) | ||
|
|
||
| if deviceID == "" || runID == "" || targetURL == "" || data == "" || transport == "" { | ||
| slog.Error("missing required environment variable(s), required environment variables: DEVICE_ID, RUN_ID, TARGET_URL, DATA, TRANSPORT", slog.String("deviceID", deviceID), slog.String("runID", runID), slog.String("targetURL", targetURL), slog.String("data", data), slog.String("transport", transport)) | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| var uid int64 | ||
|
|
||
| if userID != "" { | ||
| var err error | ||
| uid, err = strconv.ParseInt(userID, 10, 64) | ||
| if err != nil { | ||
| slog.Error("failed to parse USER_ID", slog.Any("error", err)) | ||
| os.Exit(1) | ||
| } | ||
| } | ||
|
|
||
| ctx := context.Background() | ||
|
|
||
| // disabling all other transports before enabling the selected | ||
| for name := range kindling.EnabledTransports { | ||
| kindling.EnabledTransports[name] = false | ||
| } | ||
|
|
||
| kindling.EnabledTransports[transport] = true | ||
WendelHime marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| slog.Debug("enabled transports", slog.Any("enabled_transports", kindling.EnabledTransports)) | ||
| if err := performKindlingPing(ctx, targetURL, runID, deviceID, uid, token, data); err != nil { | ||
| slog.Error("failed to perform kindling ping", slog.Any("error", err)) | ||
| os.Exit(1) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| FROM golang:1.25.1 AS builder | ||
|
|
||
| RUN apt-get update && apt-get install -y git git-lfs bsdmainutils | ||
|
|
||
| ARG TARGETOS | ||
| ARG TARGETARCH | ||
|
|
||
| WORKDIR /src | ||
|
|
||
| COPY . . | ||
|
|
||
| ENV GOCACHE=/root/.cache/go-build | ||
| RUN --mount=type=cache,target="$GOCACHE" GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o /kindling-tester ./cmd/kindling-tester/... | ||
|
|
||
| FROM debian:bookworm-slim | ||
|
|
||
| RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| COPY --from=builder /kindling-tester /kindling-tester | ||
|
|
||
| # TRANSPORT is set at build time (e.g. --build-arg TRANSPORT=proxyless). | ||
| # The entrypoint exports it as the transport-specific env var expected by the binary. | ||
| ARG TRANSPORT | ||
| ENV TRANSPORT=${TRANSPORT} | ||
|
|
||
| ENTRYPOINT ["sh", "-c", "/kindling-tester"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.