-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Simplify Bundling of UI assets #5917
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
yurishkuro
merged 19 commits into
jaegertracing:main
from
mahadzaryab1:simplify-ui-binding
Sep 2, 2024
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
dc470ff
Remove Dependency on ui Build Tag
mahadzaryab1 4f0cad6
Fix Documentation For ui Package
mahadzaryab1 435fc38
Fix Contribution Guide
mahadzaryab1 54d12b7
Fix Placeholder index.html To Remove Reference To Tags
mahadzaryab1 b1de7bd
Remove ui Tags From Makefile Targets
mahadzaryab1 c5c9cb8
Add godoc Comment For New Helper
mahadzaryab1 3f900ae
Add Warning Log
mahadzaryab1 8dd1053
Fix godoc Comment
mahadzaryab1 1a7eb63
Provide Logger From Static Handler
mahadzaryab1 7397acc
Fix Linting Error
mahadzaryab1 db19d3a
Add Test For Non Existing Assets Case
mahadzaryab1 c69cbb6
Swap Out Wrong Import
mahadzaryab1 ed259ec
Address Feedback From PR Review
mahadzaryab1 b5e1bc7
Merge branch 'main' into simplify-ui-binding
mahadzaryab1 331536d
Pass Logger To Tests
mahadzaryab1 7551104
Add Test For Actual Present Case
mahadzaryab1 a312899
Run Formatter
mahadzaryab1 f4c63f4
Fix Comment
mahadzaryab1 2b62656
Add Empty Test
mahadzaryab1 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
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
This file was deleted.
Oops, something went wrong.
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,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)) | ||
yurishkuro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
return httpfs.PrefixedFS("actual", http.FS(gzipfs.New(actualAssetsFS))) | ||
} |
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,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 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 was deleted.
Oops, something went wrong.
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
Binary file not shown.
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,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 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,9 @@ | ||
// Copyright (c) 2024 The Jaeger Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package testdata | ||
|
||
import "embed" | ||
|
||
//go:embed actual/* | ||
var TestFS embed.FS |
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.
Uh oh!
There was an error while loading. Please reload this page.