-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify Bundling of UI assets (#5917)
## Which problem is this PR solving? - Closes #5913 ## Description of the changes - Created one file `assets.go` that holds both the `placeholder` and `actual` assets. - Added a helper `GetStaticFiles` to get the assets based on whether the actual filesystem has an `index.html.gz`. If it does, we return the assets. Otherwise, we return the placeholder `index.html` file. ## How was this change tested? Added unit tests and performed the following manual tests ### Test 1 Makefile Target ```Makefile .PHONY: run-all-in-one run-all-in-one: go run ./cmd/all-in-one --log-level debug ``` Clearing out the `actual` directory and ran `make run-all-in-one`. Going to `http://localhost:16686/` renders the placeholder HTML page. ### Test 2 Makefile Target ```Makefile .PHONY: run-all-in-one run-all-in-one: build-ui go run ./cmd/all-in-one --log-level debug ``` Ran `make run-all-in-one`. Going to `http://localhost:16686/` renders the Jaeger UI. ## Checklist - [x] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [x] I have signed all commits - [x] I have added unit tests for the new functionality - [x] I have run lint and test steps successfully - for `jaeger`: `make lint test` - for `jaeger-ui`: `yarn lint` and `yarn test` --------- Signed-off-by: Mahad Zaryab <[email protected]>
- Loading branch information
1 parent
5bd6980
commit 7df6975
Showing
14 changed files
with
121 additions
and
63 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 was deleted.
Oops, something went wrong.
This file contains 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,32 @@ | ||
// Copyright (c) 2024 The Jaeger Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package ui | ||
|
||
import ( | ||
"embed" | ||
"net/http" | ||
|
||
"go.uber.org/zap" | ||
|
||
"github.com/jaegertracing/jaeger/pkg/gzipfs" | ||
"github.com/jaegertracing/jaeger/pkg/httpfs" | ||
) | ||
|
||
//go:embed actual/* | ||
var actualAssetsFS embed.FS | ||
|
||
//go:embed placeholder/index.html | ||
var placeholderAssetsFS embed.FS | ||
|
||
// GetStaticFiles gets the static assets that the Jaeger UI will serve. If the actual | ||
// assets are available, then this function will return them. Otherwise, a | ||
// non-functional index.html is returned to be used as a placeholder. | ||
func GetStaticFiles(logger *zap.Logger) http.FileSystem { | ||
if _, err := actualAssetsFS.ReadFile("actual/index.html.gz"); err != nil { | ||
logger.Warn("ui assets not embedded in the binary, using a placeholder", zap.Error(err)) | ||
return httpfs.PrefixedFS("placeholder", http.FS(placeholderAssetsFS)) | ||
} | ||
|
||
return httpfs.PrefixedFS("actual", http.FS(gzipfs.New(actualAssetsFS))) | ||
} |
This file contains 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,49 @@ | ||
// Copyright (c) 2024 The Jaeger Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package ui | ||
|
||
import ( | ||
"embed" | ||
"io" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/jaegertracing/jaeger/cmd/query/app/ui/testdata" | ||
"github.com/jaegertracing/jaeger/pkg/testutils" | ||
) | ||
|
||
func TestGetStaticFiles_ReturnsPlaceholderWhenActualNotPresent(t *testing.T) { | ||
// swap out the assets FS for an empty one and then replace it back when the | ||
// test completes | ||
currentActualAssets := actualAssetsFS | ||
actualAssetsFS = embed.FS{} | ||
t.Cleanup(func() { actualAssetsFS = currentActualAssets }) | ||
|
||
logger, logBuf := testutils.NewLogger() | ||
fs := GetStaticFiles(logger) | ||
file, err := fs.Open("/index.html") | ||
require.NoError(t, err) | ||
bytes, err := io.ReadAll(file) | ||
require.NoError(t, err) | ||
require.Contains(t, string(bytes), "This is a placeholder for the Jaeger UI home page") | ||
require.Contains(t, logBuf.String(), "ui assets not embedded in the binary, using a placeholder") | ||
} | ||
|
||
func TestGetStaticFiles_ReturnsActualWhenPresent(t *testing.T) { | ||
// swap out the assets FS for a dummy one and then replace it back when the | ||
// test completes | ||
currentActualAssets := actualAssetsFS | ||
actualAssetsFS = testdata.TestFS | ||
t.Cleanup(func() { actualAssetsFS = currentActualAssets }) | ||
|
||
logger, logBuf := testutils.NewLogger() | ||
fs := GetStaticFiles(logger) | ||
file, err := fs.Open("/index.html") | ||
require.NoError(t, err) | ||
bytes, err := io.ReadAll(file) | ||
require.NoError(t, err) | ||
require.NotContains(t, string(bytes), "This is a placeholder for the Jaeger UI home page") | ||
require.NotContains(t, logBuf.String(), "ui assets not embedded in the binary, using a placeholder") | ||
} |
This file contains 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 was deleted.
Oops, something went wrong.
This file contains 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
Binary file not shown.
This file contains 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,14 @@ | ||
// Copyright (c) 2024 The Jaeger Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package testdata | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/jaegertracing/jaeger/pkg/testutils" | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
testutils.VerifyGoLeaks(m) | ||
} |
This file contains 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,9 @@ | ||
// Copyright (c) 2024 The Jaeger Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package testdata | ||
|
||
import "embed" | ||
|
||
//go:embed actual/* | ||
var TestFS embed.FS |