-
Notifications
You must be signed in to change notification settings - Fork 4
add otel-cli tests #2
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
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
3fae209
shellspec --init
159beb0
empty OTEL_EXPORTER_OTLP_INSECURE should not log
33c83c8
add a test program
ce0ba79
make test program dump state to json
c537702
add a safe function for extracting config from context
827a6f9
remove outdated comment
d715404
set conf to empty config on retrieval error
0289524
add tests!
539aec4
remove shellspec
5ab65ba
add an explanatory comment to main.go
e6a4a27
first pass at data tests
9a395d9
move fixtures to testdata/, clean up
c7c0106
add a full-loop test using otel-cli
2945fe1
add basic github actions test runner
0a26dbe
add unit tests for otelinit/config.go
61a34aa
add godoc to type
da8a9c7
try not to leak envvars prefixed with GITHUB
8fa63e5
get rid of hard-coded paths
38a6c3f
download the latest otel-cli release for tests
bf0c89b
try the engineerd/configurator downloader instead
39d5de6
try templating the url & set token
39ee3f3
fix ordering
d722e1f
avoid releases to avoid needing a token for now
65b3c10
simplify stub path, have CI build stub before test
ded69d4
try working-directory instead of path
09e88c7
move build up
ac34806
fix up horrible comments
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| name: CI | ||
| on: | ||
| push: | ||
| branches: [ main ] | ||
| pull_request: | ||
| branches: [ main ] | ||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v2 | ||
| - name: Setup | ||
| uses: actions/setup-go@v2 | ||
| with: | ||
| go-version: 1.16 | ||
| - name: Build otelinit | ||
| run: go build -v ./... | ||
| - name: Build test stub | ||
| working-directory: ./cmd/test-otel-init-go | ||
| run: go build -v | ||
| - name: Install otel-cli for tests | ||
| uses: engineerd/[email protected] | ||
| with: | ||
| name: "otel-cli" | ||
| pathInArchive: /otel-cli | ||
| url: "https://github.com/equinix-labs/otel-cli/releases/download/v0.0.5/otel-cli-0.0.5-Linux-x86_64.tar.gz" | ||
| - name: Test | ||
| run: go test -v ./... | ||
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
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,73 @@ | ||
| package main | ||
|
|
||
| // All this program does is load up otel-init-go, create one trace, dump state | ||
| // in json for all these things, then exit. This data is intended to be consumed | ||
| // in main_test.go, which is really about testing otel-cli-init itself. | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "log" | ||
| "os" | ||
| "strconv" | ||
| "strings" | ||
|
|
||
| "github.com/equinix-labs/otel-init-go/otelinit" | ||
| "go.opentelemetry.io/otel" | ||
| ) | ||
|
|
||
| func main() { | ||
| ctx := context.Background() | ||
| ctx, otelShutdown := otelinit.InitOpenTelemetry(ctx, "otel-init-go-test") | ||
| defer otelShutdown(ctx) | ||
|
|
||
| tracer := otel.Tracer("otel-init-go-test") | ||
| ctx, span := tracer.Start(ctx, "dump state") | ||
|
|
||
| env := make(map[string]string) | ||
| for _, e := range os.Environ() { | ||
| parts := strings.SplitN(e, "=", 2) | ||
| if len(parts) == 2 { | ||
| // it's not great to hard-code a specific envvar here but this is | ||
| // probably the most dangerous one we don't want to blithely print | ||
| // here. open to suggestions... | ||
| if !strings.HasPrefix(parts[0], "GITHUB") { | ||
| env[parts[0]] = parts[1] | ||
| } | ||
| } else { | ||
| log.Fatalf("BUG this shouldn't happen") | ||
| } | ||
| } | ||
|
|
||
| // public.go stuffs the config in the context just so we can do this | ||
| conf, ok := otelinit.ConfigFromContext(ctx) | ||
| if !ok { | ||
| log.Println("failed to retrieve otelinit.Config pointer from context, test results may be invalid") | ||
| conf = &otelinit.Config{} | ||
| } | ||
| sc := span.SpanContext() | ||
| outData := map[string]map[string]string{ | ||
| "config": { | ||
| "endpoint": conf.Endpoint, | ||
| "service_name": conf.Servicename, | ||
| "insecure": strconv.FormatBool(conf.Insecure), | ||
| }, | ||
| "otel": { | ||
| "trace_id": sc.TraceID().String(), | ||
| "span_id": sc.SpanID().String(), | ||
| "trace_flags": sc.TraceFlags().String(), | ||
| "is_sampled": strconv.FormatBool(sc.IsSampled()), | ||
| }, | ||
| "env": env, | ||
| } | ||
|
|
||
| js, err := json.MarshalIndent(outData, "", " ") | ||
| if err != nil { | ||
| log.Fatal(err) | ||
| } | ||
|
|
||
| os.Stdout.Write(js) | ||
| os.Stdout.WriteString("\n") | ||
|
|
||
| span.End() | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using this or similar: https://github.com/marketplace/actions/fetch-github-release-asset
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it require a GITHUB_TOKEN secret? I think I tried that first and it wanted me to set up more stuff and the way these repos are configured I didn't feel it was worth the trouble.
In any case I'll probably refactor this out soon.