Skip to content

Commit

Permalink
Merge branch 'main' into migrate-to-google-protobuf
Browse files Browse the repository at this point in the history
  • Loading branch information
yurishkuro authored Nov 8, 2023
2 parents e5ec104 + 90906f1 commit c346f36
Show file tree
Hide file tree
Showing 16 changed files with 198 additions and 89 deletions.
5 changes: 5 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@ updates:
schedule:
interval: "weekly"
labels: [ "changelog:dependencies" ]

- package-ecosystem: docker
directory: /
schedule:
interval: daily
5 changes: 5 additions & 0 deletions .github/workflows/ci-label-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ jobs:
check-label:
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@1b05615854632b887b69ae1be8cbefe72d3ae423 # v2.6.0
with:
egress-policy: audit

- name: Check PR author
id: check_author
run: echo "::set-output name=is_dependabot::$(echo ${{ github.event.pull_request.user.login }} | grep -o 'dependabot')"
Expand Down
37 changes: 37 additions & 0 deletions .github/workflows/ci-lint-checks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Lint Checks

on:
push:
branches: [main]

pull_request:
branches: [main]

concurrency:
group: ${{ github.workflow }}-${{ (github.event.pull_request && github.event.pull_request.number) || github.ref || github.run_id }}
cancel-in-progress: true

# See https://github.com/ossf/scorecard/blob/main/docs/checks.md#token-permissions
permissions: # added using https://github.com/step-security/secure-workflows
contents: read

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@1b05615854632b887b69ae1be8cbefe72d3ae423
with:
egress-policy: audit # TODO: change to 'egress-policy: block' after a couple of runs

- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608

- uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe
with:
go-version: 1.21.x

- name: Install tools
run: make install-test-tools

- name: Lint
run: make lint
2 changes: 1 addition & 1 deletion .github/workflows/ci-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:

- name: Configure GPG Key
id: import_gpg
uses: crazy-max/ghaction-import-gpg@v6
uses: crazy-max/ghaction-import-gpg@82a020f1f7f605c65dd2449b392a52c3fcfef7ef # v6.0.0
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.GPG_PASSPHRASE }}
Expand Down
6 changes: 0 additions & 6 deletions .github/workflows/ci-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ jobs:
with:
go-version: 1.21.x

- name: Install tools
run: make install-test-tools

- name: Run unit tests
run: make test-ci

Expand All @@ -50,6 +47,3 @@ jobs:
flags: unittests
fail_ci_if_error: true
token: ${{ env.CODECOV_TOKEN }}

- name: Lint
run: make lint
10 changes: 9 additions & 1 deletion .github/workflows/ci-validation-of-shell-scripts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,21 @@ on:
pull_request:
branches: [main]

permissions:
contents: read

jobs:
validation-of-shell-scripts:
runs-on: ubuntu-latest

steps:
- name: Harden Runner
uses: step-security/harden-runner@1b05615854632b887b69ae1be8cbefe72d3ae423 # v2.6.0
with:
egress-policy: audit

- name: check out code
uses: actions/checkout@v4
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Install shellcheck
run: sudo apt-get install shellcheck
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ jobs:
# actions: read

steps:
- name: Harden Runner
uses: step-security/harden-runner@1b05615854632b887b69ae1be8cbefe72d3ae423 # v2.6.0
with:
egress-policy: audit

- name: "Checkout code"
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
Expand Down
10 changes: 6 additions & 4 deletions cmd/query/app/fixture/index.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<base href="/" data-inject-target="BASE_URL"/>
<title>Test Page</title>
<!--
<meta charset="UTF-8">
<base href="/" data-inject-target="BASE_URL" />
<title>Test Page</title>
<!--
// JAEGER_CONFIG_JS
// the line above may be replaced by user-provided JS file that should define a UIConfig function.
JAEGER_CONFIG=DEFAULT_CONFIG;
JAEGER_STORAGE_CAPABILITIES=DEFAULT_STORAGE_CAPABILITIES;
JAEGER_VERSION=DEFAULT_VERSION;
-->

</html>
19 changes: 19 additions & 0 deletions cmd/query/app/querysvc/query_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ type QueryServiceOptions struct {
Adjuster adjuster.Adjuster
}

// StorageCapabilities is a feature flag for query service
type StorageCapabilities struct {
ArchiveStorage bool `json:"archiveStorage"`
// SupportRegex bool
// SupportTagFilter bool
}

// QueryService contains span utils required by the query-service.
type QueryService struct {
spanReader spanstore.Reader
Expand Down Expand Up @@ -122,6 +129,13 @@ func (qs QueryService) GetDependencies(ctx context.Context, endTs time.Time, loo
return qs.dependencyReader.GetDependencies(ctx, endTs, lookback)
}

// GetCapabilities returns the features supported by the query service.
func (qs QueryService) GetCapabilities() StorageCapabilities {
return StorageCapabilities{
ArchiveStorage: qs.options.hasArchiveStorage(),
}
}

// InitArchiveStorage tries to initialize archive storage reader/writer if storage factory supports them.
func (opts *QueryServiceOptions) InitArchiveStorage(storageFactory storage.Factory, logger *zap.Logger) bool {
archiveFactory, ok := storageFactory.(storage.ArchiveFactory)
Expand Down Expand Up @@ -151,3 +165,8 @@ func (opts *QueryServiceOptions) InitArchiveStorage(storageFactory storage.Facto
opts.ArchiveSpanWriter = writer
return true
}

// hasArchiveStorage returns true if archive storage reader/writer are initialized.
func (opts *QueryServiceOptions) hasArchiveStorage() bool {
return opts.ArchiveSpanReader != nil && opts.ArchiveSpanWriter != nil
}
18 changes: 18 additions & 0 deletions cmd/query/app/querysvc/query_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,24 @@ func TestGetDependencies(t *testing.T) {
assert.Equal(t, expectedDependencies, actualDependencies)
}

// Test QueryService.GetCapacities()
func TestGetCapabilities(t *testing.T) {
tqs := initializeTestService()
expectedStorageCapabilities := StorageCapabilities{
ArchiveStorage: false,
}
assert.Equal(t, expectedStorageCapabilities, tqs.queryService.GetCapabilities())
}

func TestGetCapabilitiesWithSupportsArchive(t *testing.T) {
tqs := initializeTestService(withArchiveSpanReader(), withArchiveSpanWriter())

expectedStorageCapabilities := StorageCapabilities{
ArchiveStorage: true,
}
assert.Equal(t, expectedStorageCapabilities, tqs.queryService.GetCapabilities())
}

type fakeStorageFactory1 struct{}

type fakeStorageFactory2 struct {
Expand Down
2 changes: 1 addition & 1 deletion cmd/query/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func createHTTPServer(querySvc *querysvc.QueryService, metricsQuerySvc querysvc.
}

apiHandler.RegisterRoutes(r)
RegisterStaticHandler(r, logger, queryOpts)
RegisterStaticHandler(r, logger, queryOpts, querySvc.GetCapabilities())
var handler http.Handler = r
handler = additionalHeadersHandler(handler, queryOpts.AdditionalHeaders)
if queryOpts.BearerTokenPropagation {
Expand Down
62 changes: 35 additions & 27 deletions cmd/query/app/static_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,29 @@ import (
"github.com/gorilla/mux"
"go.uber.org/zap"

"github.com/jaegertracing/jaeger/cmd/query/app/querysvc"
"github.com/jaegertracing/jaeger/cmd/query/app/ui"
"github.com/jaegertracing/jaeger/pkg/fswatcher"
"github.com/jaegertracing/jaeger/pkg/version"
)

var (
// The following patterns are searched and replaced in the index.html as a way of customizing the UI.
configPattern = regexp.MustCompile("JAEGER_CONFIG *= *DEFAULT_CONFIG;")
configJsPattern = regexp.MustCompile(`(?im)^\s*\/\/\s*JAEGER_CONFIG_JS.*\n.*`)
versionPattern = regexp.MustCompile("JAEGER_VERSION *= *DEFAULT_VERSION;")
basePathPattern = regexp.MustCompile(`<base href="/"`) // Note: tag is not closed
configPattern = regexp.MustCompile("JAEGER_CONFIG *= *DEFAULT_CONFIG;")
configJsPattern = regexp.MustCompile(`(?im)^\s*\/\/\s*JAEGER_CONFIG_JS.*\n.*`)
versionPattern = regexp.MustCompile("JAEGER_VERSION *= *DEFAULT_VERSION;")
compabilityPattern = regexp.MustCompile("JAEGER_STORAGE_CAPABILITIES *= *DEFAULT_STORAGE_CAPABILITIES;")
basePathPattern = regexp.MustCompile(`<base href="/"`) // Note: tag is not closed
)

// RegisterStaticHandler adds handler for static assets to the router.
func RegisterStaticHandler(r *mux.Router, logger *zap.Logger, qOpts *QueryOptions) {
func RegisterStaticHandler(r *mux.Router, logger *zap.Logger, qOpts *QueryOptions, qCapabilities querysvc.StorageCapabilities) {
staticHandler, err := NewStaticAssetsHandler(qOpts.StaticAssets.Path, StaticAssetsHandlerOptions{
BasePath: qOpts.BasePath,
UIConfigPath: qOpts.UIConfig,
Logger: logger,
LogAccess: qOpts.StaticAssets.LogAccess,
BasePath: qOpts.BasePath,
UIConfigPath: qOpts.UIConfig,
StorageCapabilities: qCapabilities,
Logger: logger,
LogAccess: qOpts.StaticAssets.LogAccess,
})
if err != nil {
logger.Panic("Could not create static assets handler", zap.Error(err))
Expand All @@ -68,10 +71,11 @@ type StaticAssetsHandler struct {

// StaticAssetsHandlerOptions defines options for NewStaticAssetsHandler
type StaticAssetsHandlerOptions struct {
BasePath string
UIConfigPath string
LogAccess bool
Logger *zap.Logger
BasePath string
UIConfigPath string
LogAccess bool
StorageCapabilities querysvc.StorageCapabilities
Logger *zap.Logger
}

type loadedConfig struct {
Expand All @@ -90,16 +94,16 @@ func NewStaticAssetsHandler(staticAssetsRoot string, options StaticAssetsHandler
options.Logger = zap.NewNop()
}

indexHTML, err := loadAndEnrichIndexHTML(assetsFS.Open, options)
if err != nil {
return nil, err
}

h := &StaticAssetsHandler{
options: options,
assetsFS: assetsFS,
}

indexHTML, err := h.loadAndEnrichIndexHTML(assetsFS.Open)
if err != nil {
return nil, err
}

options.Logger.Info("Using UI configuration", zap.String("path", options.UIConfigPath))
watcher, err := fswatcher.New([]string{options.UIConfigPath}, h.reloadUIConfig, h.options.Logger)
if err != nil {
Expand All @@ -112,38 +116,42 @@ func NewStaticAssetsHandler(staticAssetsRoot string, options StaticAssetsHandler
return h, nil
}

func loadAndEnrichIndexHTML(open func(string) (http.File, error), options StaticAssetsHandlerOptions) ([]byte, error) {
func (sH *StaticAssetsHandler) loadAndEnrichIndexHTML(open func(string) (http.File, error)) ([]byte, error) {
indexBytes, err := loadIndexHTML(open)
if err != nil {
return nil, fmt.Errorf("cannot load index.html: %w", err)
}
// replace UI config
if configObject, err := loadUIConfig(options.UIConfigPath); err != nil {
if configObject, err := loadUIConfig(sH.options.UIConfigPath); err != nil {
return nil, err
} else if configObject != nil {
indexBytes = configObject.regexp.ReplaceAll(indexBytes, configObject.config)
}
// replace storage capabilities
capabilitiesJSON, _ := json.Marshal(sH.options.StorageCapabilities)
capabilitiesString := fmt.Sprintf("JAEGER_STORAGE_CAPABILITIES = %s;", string(capabilitiesJSON))
indexBytes = compabilityPattern.ReplaceAll(indexBytes, []byte(capabilitiesString))
// replace Jaeger version
versionJSON, _ := json.Marshal(version.Get())
versionString := fmt.Sprintf("JAEGER_VERSION = %s;", string(versionJSON))
indexBytes = versionPattern.ReplaceAll(indexBytes, []byte(versionString))
// replace base path
if options.BasePath == "" {
options.BasePath = "/"
if sH.options.BasePath == "" {
sH.options.BasePath = "/"
}
if options.BasePath != "/" {
if !strings.HasPrefix(options.BasePath, "/") || strings.HasSuffix(options.BasePath, "/") {
return nil, fmt.Errorf("invalid base path '%s'. Must start but not end with a slash '/', e.g. '/jaeger/ui'", options.BasePath)
if sH.options.BasePath != "/" {
if !strings.HasPrefix(sH.options.BasePath, "/") || strings.HasSuffix(sH.options.BasePath, "/") {
return nil, fmt.Errorf("invalid base path '%s'. Must start but not end with a slash '/', e.g. '/jaeger/ui'", sH.options.BasePath)
}
indexBytes = basePathPattern.ReplaceAll(indexBytes, []byte(fmt.Sprintf(`<base href="%s/"`, options.BasePath)))
indexBytes = basePathPattern.ReplaceAll(indexBytes, []byte(fmt.Sprintf(`<base href="%s/"`, sH.options.BasePath)))
}

return indexBytes, nil
}

func (sH *StaticAssetsHandler) reloadUIConfig() {
sH.options.Logger.Info("reloading UI config", zap.String("filename", sH.options.UIConfigPath))
content, err := loadAndEnrichIndexHTML(sH.assetsFS.Open, sH.options)
content, err := sH.loadAndEnrichIndexHTML(sH.assetsFS.Open)
if err != nil {
sH.options.Logger.Error("error while reloading the UI config", zap.Error(err))
}
Expand Down
Loading

0 comments on commit c346f36

Please sign in to comment.