-
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.
Merge branch 'main' into renovate/github.com-prometheus-common-0.x
- Loading branch information
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 |