diff --git a/.github/workflows/ci-build-tests.yml b/.github/workflows/ci-build-tests.yml index b4d19af03..bcc91b265 100644 --- a/.github/workflows/ci-build-tests.yml +++ b/.github/workflows/ci-build-tests.yml @@ -28,9 +28,9 @@ jobs: steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: python-version: '3.x' - name: Install python dependencies @@ -40,10 +40,10 @@ jobs: - name: running codespell run: codespell --skip="vendor,*.git,*.png,*.pdf,*.tiff,*.plist,*.pem,rangesim*.go,*.gz,go.mod,go.sum" --ignore-words="./testdata/ignore_words.txt" - - uses: actions/setup-go@v1 + - uses: actions/setup-go@v5 with: go-version: ${{ matrix.go }} - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 name: Get dependencies - run: | diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index af56c68c6..3f44ee6ab 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -37,11 +37,11 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v1 + uses: github/codeql-action/init@v3 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -61,4 +61,4 @@ jobs: # make release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 + uses: github/codeql-action/analyze@v3 diff --git a/.github/workflows/publish-beta-release.yaml b/.github/workflows/publish-beta-release.yaml index ad8c32f79..6bb6559b4 100644 --- a/.github/workflows/publish-beta-release.yaml +++ b/.github/workflows/publish-beta-release.yaml @@ -19,10 +19,10 @@ jobs: run: echo "baretag=$(echo ${{ github.ref }} | cut -b 12-)" >> "$GITHUB_OUTPUT" # - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 # - name: install golang - uses: actions/setup-go@v2 + uses: actions/setup-go@v5 with: go-version: "1.22" - name: Build project diff --git a/.github/workflows/publish-release-candidate.yaml b/.github/workflows/publish-release-candidate.yaml index 837e9d797..344360d29 100644 --- a/.github/workflows/publish-release-candidate.yaml +++ b/.github/workflows/publish-release-candidate.yaml @@ -19,10 +19,10 @@ jobs: run: echo "baretag=$(echo ${{ github.ref }} | cut -b 12-)" >> "$GITHUB_OUTPUT" # - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 # - name: install golang - uses: actions/setup-go@v2 + uses: actions/setup-go@v5 with: go-version: "1.22" # diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index b4b962c40..9950136c7 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -19,10 +19,10 @@ jobs: run: echo "baretag=$(echo ${{ github.ref }} | cut -b 12-)" >> "$GITHUB_OUTPUT" # - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 # - name: install golang - uses: actions/setup-go@v2 + uses: actions/setup-go@v5 with: go-version: "1.22" # diff --git a/.gitignore b/.gitignore index 029af44a3..a7bc5bd7f 100644 --- a/.gitignore +++ b/.gitignore @@ -47,6 +47,10 @@ out.log tags +# file copies that should not be committed to the repo +*.old +*.copy + # any generated test cert/keys that testing did not cleanup due to user abort .pem diff --git a/cmd/trickster/main.go b/cmd/trickster/main.go index d778f4394..8af80f89c 100644 --- a/cmd/trickster/main.go +++ b/cmd/trickster/main.go @@ -21,7 +21,8 @@ import ( "os" "sync" - "github.com/trickstercache/trickster/v2/pkg/runtime" + "github.com/trickstercache/trickster/v2/pkg/appinfo" + "github.com/trickstercache/trickster/v2/pkg/httpserver" ) var ( @@ -34,14 +35,11 @@ const ( applicationVersion = "2.0.0-beta2" ) -var wg = &sync.WaitGroup{} - -var exitFunc func() = exitFatal - func main() { - runtime.ApplicationName = applicationName - runtime.ApplicationVersion = applicationVersion - runConfig(nil, wg, nil, nil, os.Args[1:], exitFunc) + wg := &sync.WaitGroup{} + appinfo.SetAppInfo(applicationName, applicationVersion, + applicationBuildTime, applicationGitCommitID) + httpserver.Serve(nil, wg, nil, nil, os.Args[1:], exitFatal) wg.Wait() } diff --git a/cmd/trickster/main_test.go b/cmd/trickster/main_test.go deleted file mode 100644 index 94fa4f2a6..000000000 --- a/cmd/trickster/main_test.go +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2018 The Trickster Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package main - -import ( - "sync" - "testing" -) - -func TestMain(t *testing.T) { - exitFunc = nil - main() - // Successful test criteria is that the call to main returns without timing out on wg.Wait() -} - -func TestRunConfig(t *testing.T) { - wg := &sync.WaitGroup{} - runConfig(nil, wg, nil, nil, []string{}, nil) - - runConfig(nil, wg, nil, nil, []string{"-version"}, nil) - - runConfig(nil, wg, nil, nil, []string{"-provider", "rpc", "-origin-url", "http://trickstercache.org"}, nil) - -} diff --git a/cmd/trickster/usage.go b/cmd/trickster/usage/usage.go similarity index 94% rename from cmd/trickster/usage.go rename to cmd/trickster/usage/usage.go index 5dda0cae0..a03a335fe 100644 --- a/cmd/trickster/usage.go +++ b/cmd/trickster/usage/usage.go @@ -14,13 +14,13 @@ * limitations under the License. */ -package main +package usage import ( "fmt" goruntime "runtime" - "github.com/trickstercache/trickster/v2/pkg/runtime" + "github.com/trickstercache/trickster/v2/pkg/appinfo" ) const usageText = ` @@ -76,16 +76,16 @@ func version() string { os := goruntime.GOOS // use an empty string for goVer, arch, and os during unit tests // to accommodate rigid tests like ExamplePrintVersion and ExamplePrintUsage - if runtime.ApplicationVersion == "test" { + if appinfo.Version == "test" { goVer = "" arch = "" os = "" } return fmt.Sprintf("Trickster version: %s (%s/%s), buildInfo: %s %s, goVersion: %s, copyright: © 2018 The Trickster Authors", - runtime.ApplicationVersion, + appinfo.Version, os, arch, - applicationBuildTime, applicationGitCommitID, + appinfo.BuildTime, appinfo.GitCommitID, goVer, ) } diff --git a/cmd/trickster/usage_test.go b/cmd/trickster/usage/usage_test.go similarity index 95% rename from cmd/trickster/usage_test.go rename to cmd/trickster/usage/usage_test.go index 7b2804659..dfd2f5418 100644 --- a/cmd/trickster/usage_test.go +++ b/cmd/trickster/usage/usage_test.go @@ -14,15 +14,15 @@ * limitations under the License. */ -package main +package usage import ( - "github.com/trickstercache/trickster/v2/pkg/runtime" + "github.com/trickstercache/trickster/v2/pkg/appinfo" ) // ExamplePrintVersion tests the output of the PrintVersion() func func ExamplePrintVersion() { - runtime.ApplicationVersion = "test" + appinfo.Version = "test" PrintVersion() // Output: Trickster version: test (/), buildInfo: , goVersion: , copyright: © 2018 The Trickster Authors } @@ -30,7 +30,7 @@ func ExamplePrintVersion() { // ExamplePrintUsage tests the output of the PrintUsage() func func ExamplePrintUsage() { - runtime.ApplicationVersion = "test" + appinfo.Version = "test" PrintUsage() // Output: Trickster version: test (/), buildInfo: , goVersion: , copyright: © 2018 The Trickster Authors // diff --git a/go.mod b/go.mod index dad401fd8..c49117109 100644 --- a/go.mod +++ b/go.mod @@ -2,6 +2,8 @@ module github.com/trickstercache/trickster/v2 go 1.22 +toolchain go1.22.3 + require ( github.com/alicebob/miniredis v2.5.0+incompatible github.com/andybalholm/brotli v1.1.0 diff --git a/pkg/runtime/runtime.go b/pkg/appinfo/appinfo.go similarity index 58% rename from pkg/runtime/runtime.go rename to pkg/appinfo/appinfo.go index cd056ef87..bd13608aa 100644 --- a/pkg/runtime/runtime.go +++ b/pkg/appinfo/appinfo.go @@ -14,17 +14,34 @@ * limitations under the License. */ -// Package runtime holds application runtime information -package runtime +// Package app holds application build information +package appinfo import "os" -// ApplicationName is the name of the Application -var ApplicationName string +// Name is the name of the Application +var Name string -// ApplicationVersion holds the version of the Application -var ApplicationVersion string +// Version holds the version of the Application +var Version string + +// BuildTime is the Time that the Application was Built +var BuildTime string + +// GitCommitID holds the Git Commit ID of the current binary/build +var GitCommitID string // Server is the name, hostname or ip of the server as advertised in HTTP Headers // By default uses the hostname reported by the kernel var Server, _ = os.Hostname() + +func SetAppInfo(name, version, buildTime, gitCommitID string) { + Name = name + Version = version + BuildTime = buildTime + GitCommitID = gitCommitID +} + +func SetServer(server string) { + Server = server +} diff --git a/pkg/backends/alb/client.go b/pkg/backends/alb/client.go index 3a49513b4..623e22ca1 100644 --- a/pkg/backends/alb/client.go +++ b/pkg/backends/alb/client.go @@ -17,7 +17,6 @@ package alb import ( - "errors" "fmt" "net/http" "strings" @@ -29,6 +28,7 @@ import ( "github.com/trickstercache/trickster/v2/pkg/backends/providers" "github.com/trickstercache/trickster/v2/pkg/backends/providers/registration/types" "github.com/trickstercache/trickster/v2/pkg/cache" + "github.com/trickstercache/trickster/v2/pkg/errors" "github.com/trickstercache/trickster/v2/pkg/proxy/methods" "github.com/trickstercache/trickster/v2/pkg/proxy/paths/matching" po "github.com/trickstercache/trickster/v2/pkg/proxy/paths/options" @@ -157,7 +157,7 @@ func (c *Client) ValidatePool(clients backends.Backends) error { // validate and map out the pool configuration func (c *Client) ValidateAndStartPool(clients backends.Backends, hcs healthcheck.StatusLookup) error { if c.Configuration() == nil || c.Configuration().ALBOptions == nil { - return errors.New("invalid options") + return errors.ErrInvalidOptions } o := c.Configuration().ALBOptions @@ -172,7 +172,7 @@ func (c *Client) ValidateAndStartPool(clients backends.Backends, hcs healthcheck if !ok { return fmt.Errorf("invalid pool member name [%s] in backend [%s]", n, c.Name()) } - hc, _ := hcs[n] + hc := hcs[n] targets = append(targets, pool.NewTarget(tc.Router(), hc)) } c.pool = pool.New(m, targets, o.HealthyFloor) diff --git a/pkg/backends/alb/client_test.go b/pkg/backends/alb/client_test.go index 97c37209f..61c2ec6b9 100644 --- a/pkg/backends/alb/client_test.go +++ b/pkg/backends/alb/client_test.go @@ -46,25 +46,25 @@ func TestHandlers(t *testing.T) { } a.MechanismName = "fgr" - cl, err = NewClient("test", o, nil, nil, nil, nil) + _, err = NewClient("test", o, nil, nil, nil, nil) if err != nil { t.Error(err) } a.MechanismName = "nlm" - cl, err = NewClient("test", o, nil, nil, nil, nil) + _, err = NewClient("test", o, nil, nil, nil, nil) if err != nil { t.Error(err) } a.MechanismName = "tsm" - cl, err = NewClient("test", o, nil, nil, nil, types.Lookup{"prometheus": prometheus.NewClient}) + _, err = NewClient("test", o, nil, nil, nil, types.Lookup{"prometheus": prometheus.NewClient}) if err != nil { t.Error(err) } a.MechanismName = "rr" - cl, err = NewClient("test", o, nil, nil, nil, nil) + _, err = NewClient("test", o, nil, nil, nil, nil) if err != nil { t.Error(err) } diff --git a/pkg/backends/backend_test.go b/pkg/backends/backend_test.go index 65e3c5a20..8ddae1ff4 100644 --- a/pkg/backends/backend_test.go +++ b/pkg/backends/backend_test.go @@ -21,9 +21,9 @@ import ( "net/url" "testing" - "github.com/trickstercache/trickster/v2/cmd/trickster/config" bo "github.com/trickstercache/trickster/v2/pkg/backends/options" cr "github.com/trickstercache/trickster/v2/pkg/cache/registration" + "github.com/trickstercache/trickster/v2/pkg/config" tl "github.com/trickstercache/trickster/v2/pkg/observability/logging" ) diff --git a/pkg/backends/clickhouse/clickhouse_test.go b/pkg/backends/clickhouse/clickhouse_test.go index 534459c6b..c378190b5 100644 --- a/pkg/backends/clickhouse/clickhouse_test.go +++ b/pkg/backends/clickhouse/clickhouse_test.go @@ -21,11 +21,11 @@ import ( "net/url" "testing" - "github.com/trickstercache/trickster/v2/cmd/trickster/config" "github.com/trickstercache/trickster/v2/pkg/backends" "github.com/trickstercache/trickster/v2/pkg/backends/clickhouse/model" bo "github.com/trickstercache/trickster/v2/pkg/backends/options" cr "github.com/trickstercache/trickster/v2/pkg/cache/registration" + "github.com/trickstercache/trickster/v2/pkg/config" tl "github.com/trickstercache/trickster/v2/pkg/observability/logging" ) diff --git a/pkg/backends/influxdb/influxdb_test.go b/pkg/backends/influxdb/influxdb_test.go index 36c168a90..d64a3845b 100644 --- a/pkg/backends/influxdb/influxdb_test.go +++ b/pkg/backends/influxdb/influxdb_test.go @@ -19,11 +19,11 @@ package influxdb import ( "testing" - "github.com/trickstercache/trickster/v2/cmd/trickster/config" "github.com/trickstercache/trickster/v2/pkg/backends" "github.com/trickstercache/trickster/v2/pkg/backends/influxdb/model" bo "github.com/trickstercache/trickster/v2/pkg/backends/options" cr "github.com/trickstercache/trickster/v2/pkg/cache/registration" + "github.com/trickstercache/trickster/v2/pkg/config" tl "github.com/trickstercache/trickster/v2/pkg/observability/logging" ) diff --git a/pkg/backends/influxdb/url_test.go b/pkg/backends/influxdb/url_test.go index 275006ca1..08e9b5b9a 100644 --- a/pkg/backends/influxdb/url_test.go +++ b/pkg/backends/influxdb/url_test.go @@ -26,7 +26,7 @@ import ( "testing" "time" - "github.com/trickstercache/trickster/v2/cmd/trickster/config" + "github.com/trickstercache/trickster/v2/pkg/config" "github.com/trickstercache/trickster/v2/pkg/proxy/headers" "github.com/trickstercache/trickster/v2/pkg/proxy/params" "github.com/trickstercache/trickster/v2/pkg/timeseries" diff --git a/pkg/backends/irondb/health_test.go b/pkg/backends/irondb/health_test.go index 2255363f3..56a2656e8 100644 --- a/pkg/backends/irondb/health_test.go +++ b/pkg/backends/irondb/health_test.go @@ -29,9 +29,7 @@ func TestDefaultHealthCheckConfig(t *testing.T) { dho := c.DefaultHealthCheckConfig() if dho == nil { t.Error("expected non-nil result") - } - - if dho.Path != "" { + } else if dho.Path != "" { t.Error("expected / for path", dho.Path) } diff --git a/pkg/backends/irondb/irondb_test.go b/pkg/backends/irondb/irondb_test.go index 127273a0d..491d07098 100644 --- a/pkg/backends/irondb/irondb_test.go +++ b/pkg/backends/irondb/irondb_test.go @@ -19,11 +19,10 @@ package irondb import ( "testing" - "github.com/trickstercache/trickster/v2/cmd/trickster/config" "github.com/trickstercache/trickster/v2/pkg/backends" - "github.com/trickstercache/trickster/v2/pkg/backends/irondb/model" bo "github.com/trickstercache/trickster/v2/pkg/backends/options" cr "github.com/trickstercache/trickster/v2/pkg/cache/registration" + "github.com/trickstercache/trickster/v2/pkg/config" tl "github.com/trickstercache/trickster/v2/pkg/observability/logging" ) @@ -48,8 +47,6 @@ func TestIRONdbClientInterfacing(t *testing.T) { } } -var testModeler = model.NewModeler() - func TestNewClient(t *testing.T) { conf, _, err := config.Load("trickster", "test", []string{"-origin-url", "http://example.com", "-provider", "TEST_CLIENT"}) diff --git a/pkg/backends/irondb/url.go b/pkg/backends/irondb/url.go index 81edd1fc9..04f403237 100644 --- a/pkg/backends/irondb/url.go +++ b/pkg/backends/irondb/url.go @@ -17,10 +17,10 @@ package irondb import ( - "errors" "fmt" "net/http" + tkerr "github.com/trickstercache/trickster/v2/pkg/errors" terr "github.com/trickstercache/trickster/v2/pkg/proxy/errors" "github.com/trickstercache/trickster/v2/pkg/proxy/request" "github.com/trickstercache/trickster/v2/pkg/timeseries" @@ -45,7 +45,7 @@ func (c *Client) FastForwardRequest(r *http.Request) (*http.Request, error) { rsc := request.GetResources(r) if rsc == nil || rsc.PathConfig == nil { - return nil, errors.New("missing path config") + return nil, tkerr.ErrMissingPathconfig } switch rsc.PathConfig.HandlerName { @@ -68,7 +68,7 @@ func (c *Client) ParseTimeRangeQuery( rsc := request.GetResources(r) if rsc == nil || rsc.PathConfig == nil { - return nil, nil, false, errors.New("missing path config") + return nil, nil, false, tkerr.ErrMissingPathconfig } var trq *timeseries.TimeRangeQuery diff --git a/pkg/backends/irondb/url_test.go b/pkg/backends/irondb/url_test.go index 90448226f..b8ea7e17f 100644 --- a/pkg/backends/irondb/url_test.go +++ b/pkg/backends/irondb/url_test.go @@ -26,8 +26,8 @@ import ( "testing" "time" - "github.com/trickstercache/trickster/v2/cmd/trickster/config" "github.com/trickstercache/trickster/v2/pkg/backends/irondb/common" + "github.com/trickstercache/trickster/v2/pkg/config" tl "github.com/trickstercache/trickster/v2/pkg/observability/logging" "github.com/trickstercache/trickster/v2/pkg/proxy/errors" po "github.com/trickstercache/trickster/v2/pkg/proxy/paths/options" diff --git a/pkg/backends/prometheus/prometheus_test.go b/pkg/backends/prometheus/prometheus_test.go index d6ea4bd3c..b11b11067 100644 --- a/pkg/backends/prometheus/prometheus_test.go +++ b/pkg/backends/prometheus/prometheus_test.go @@ -25,12 +25,12 @@ import ( "testing" "time" - "github.com/trickstercache/trickster/v2/cmd/trickster/config" "github.com/trickstercache/trickster/v2/pkg/backends" bo "github.com/trickstercache/trickster/v2/pkg/backends/options" "github.com/trickstercache/trickster/v2/pkg/backends/prometheus/model" po "github.com/trickstercache/trickster/v2/pkg/backends/prometheus/options" cr "github.com/trickstercache/trickster/v2/pkg/cache/registration" + "github.com/trickstercache/trickster/v2/pkg/config" tl "github.com/trickstercache/trickster/v2/pkg/observability/logging" pe "github.com/trickstercache/trickster/v2/pkg/proxy/errors" "github.com/trickstercache/trickster/v2/pkg/proxy/request" diff --git a/pkg/backends/prometheus/url_test.go b/pkg/backends/prometheus/url_test.go index 4d178cd99..6e9d935f5 100644 --- a/pkg/backends/prometheus/url_test.go +++ b/pkg/backends/prometheus/url_test.go @@ -25,7 +25,7 @@ import ( "testing" "time" - "github.com/trickstercache/trickster/v2/cmd/trickster/config" + "github.com/trickstercache/trickster/v2/pkg/config" "github.com/trickstercache/trickster/v2/pkg/proxy/urls" "github.com/trickstercache/trickster/v2/pkg/timeseries" ) diff --git a/pkg/cache/redis/redis_test.go b/pkg/cache/redis/redis_test.go index 6281d1941..57cbbf265 100644 --- a/pkg/cache/redis/redis_test.go +++ b/pkg/cache/redis/redis_test.go @@ -21,10 +21,10 @@ import ( "testing" "time" - "github.com/trickstercache/trickster/v2/cmd/trickster/config" co "github.com/trickstercache/trickster/v2/pkg/cache/options" ro "github.com/trickstercache/trickster/v2/pkg/cache/redis/options" "github.com/trickstercache/trickster/v2/pkg/cache/status" + "github.com/trickstercache/trickster/v2/pkg/config" "github.com/trickstercache/trickster/v2/pkg/locks" tl "github.com/trickstercache/trickster/v2/pkg/observability/logging" diff --git a/pkg/cache/registration/registration.go b/pkg/cache/registration/registration.go index ca9bc840d..4e8bd7f09 100644 --- a/pkg/cache/registration/registration.go +++ b/pkg/cache/registration/registration.go @@ -19,7 +19,6 @@ package registration import ( - "github.com/trickstercache/trickster/v2/cmd/trickster/config" "github.com/trickstercache/trickster/v2/pkg/cache" "github.com/trickstercache/trickster/v2/pkg/cache/badger" "github.com/trickstercache/trickster/v2/pkg/cache/bbolt" @@ -27,6 +26,7 @@ import ( "github.com/trickstercache/trickster/v2/pkg/cache/memory" "github.com/trickstercache/trickster/v2/pkg/cache/options" "github.com/trickstercache/trickster/v2/pkg/cache/redis" + "github.com/trickstercache/trickster/v2/pkg/config" "github.com/trickstercache/trickster/v2/pkg/locks" ) diff --git a/pkg/cache/registration/registration_test.go b/pkg/cache/registration/registration_test.go index a078f0101..3b1acdef7 100644 --- a/pkg/cache/registration/registration_test.go +++ b/pkg/cache/registration/registration_test.go @@ -19,7 +19,6 @@ package registration import ( "testing" - "github.com/trickstercache/trickster/v2/cmd/trickster/config" bao "github.com/trickstercache/trickster/v2/pkg/cache/badger/options" bbo "github.com/trickstercache/trickster/v2/pkg/cache/bbolt/options" flo "github.com/trickstercache/trickster/v2/pkg/cache/filesystem/options" @@ -27,6 +26,7 @@ import ( co "github.com/trickstercache/trickster/v2/pkg/cache/options" "github.com/trickstercache/trickster/v2/pkg/cache/providers" ro "github.com/trickstercache/trickster/v2/pkg/cache/redis/options" + "github.com/trickstercache/trickster/v2/pkg/config" tl "github.com/trickstercache/trickster/v2/pkg/observability/logging" ) diff --git a/cmd/trickster/config/config.go b/pkg/config/config.go similarity index 99% rename from cmd/trickster/config/config.go rename to pkg/config/config.go index d1b229e83..457fbc271 100644 --- a/cmd/trickster/config/config.go +++ b/pkg/config/config.go @@ -25,11 +25,11 @@ import ( "sync" "time" - reload "github.com/trickstercache/trickster/v2/cmd/trickster/config/reload/options" bo "github.com/trickstercache/trickster/v2/pkg/backends/options" rule "github.com/trickstercache/trickster/v2/pkg/backends/rule/options" "github.com/trickstercache/trickster/v2/pkg/cache/negative" cache "github.com/trickstercache/trickster/v2/pkg/cache/options" + reload "github.com/trickstercache/trickster/v2/pkg/config/reload/options" fropt "github.com/trickstercache/trickster/v2/pkg/frontend/options" lo "github.com/trickstercache/trickster/v2/pkg/observability/logging/options" mo "github.com/trickstercache/trickster/v2/pkg/observability/metrics/options" diff --git a/cmd/trickster/config/config_test.go b/pkg/config/config_test.go similarity index 99% rename from cmd/trickster/config/config_test.go rename to pkg/config/config_test.go index 8ec6ead1d..9043e20b9 100644 --- a/cmd/trickster/config/config_test.go +++ b/pkg/config/config_test.go @@ -30,7 +30,7 @@ import ( to "github.com/trickstercache/trickster/v2/pkg/proxy/tls/options" ) -const emptyFilePath = "../../../testdata/test.empty.conf" +const emptyFilePath = "../../testdata/test.empty.conf" // EmptyTestConfig returns an empty config based on the testdata empty conf func emptyTestConfig() (*Config, string) { diff --git a/cmd/trickster/config/defaults.go b/pkg/config/defaults.go similarity index 100% rename from cmd/trickster/config/defaults.go rename to pkg/config/defaults.go diff --git a/cmd/trickster/config/defaults_unix.go b/pkg/config/defaults_unix.go similarity index 100% rename from cmd/trickster/config/defaults_unix.go rename to pkg/config/defaults_unix.go diff --git a/cmd/trickster/config/defaults_windows.go b/pkg/config/defaults_windows.go similarity index 100% rename from cmd/trickster/config/defaults_windows.go rename to pkg/config/defaults_windows.go diff --git a/cmd/trickster/config/env.go b/pkg/config/env.go similarity index 100% rename from cmd/trickster/config/env.go rename to pkg/config/env.go diff --git a/cmd/trickster/config/env_test.go b/pkg/config/env_test.go similarity index 100% rename from cmd/trickster/config/env_test.go rename to pkg/config/env_test.go diff --git a/pkg/config/errors.go b/pkg/config/errors.go new file mode 100644 index 000000000..a1e00a412 --- /dev/null +++ b/pkg/config/errors.go @@ -0,0 +1,5 @@ +package config + +import "errors" + +var ErrNoValidBackends = errors.New("no valid backends configured") diff --git a/cmd/trickster/config/flags.go b/pkg/config/flags.go similarity index 100% rename from cmd/trickster/config/flags.go rename to pkg/config/flags.go diff --git a/cmd/trickster/config/flags_test.go b/pkg/config/flags_test.go similarity index 100% rename from cmd/trickster/config/flags_test.go rename to pkg/config/flags_test.go diff --git a/cmd/trickster/config/loader.go b/pkg/config/loader.go similarity index 97% rename from cmd/trickster/config/loader.go rename to pkg/config/loader.go index c5946f13b..ef48206e5 100644 --- a/cmd/trickster/config/loader.go +++ b/pkg/config/loader.go @@ -17,7 +17,6 @@ package config import ( - "errors" "net/url" "time" @@ -72,7 +71,7 @@ func Load(applicationName string, applicationVersion string, arguments []string) } if len(c.Backends) == 0 { - return nil, flags, errors.New("no valid backends configured") + return nil, flags, ErrNoValidBackends } ncl, err := negative.ConfigLookup(c.NegativeCacheConfigs).Validate() diff --git a/cmd/trickster/config/loader_test.go b/pkg/config/loader_test.go similarity index 95% rename from cmd/trickster/config/loader_test.go rename to pkg/config/loader_test.go index 2375017ce..8a128cb92 100644 --- a/cmd/trickster/config/loader_test.go +++ b/pkg/config/loader_test.go @@ -56,35 +56,35 @@ func TestLoadConfigurationFileFailures(t *testing.T) { expected string }{ { // Case 0 - "../../../testdata/test.missing-origin-url.conf", + "../../testdata/test.missing-origin-url.conf", `missing origin-url for backend "test"`, }, { // Case 1 - "../../../testdata/test.bad_origin_url.conf", + "../../testdata/test.bad_origin_url.conf", "first path segment in URL cannot contain colon", }, { // Case 2 - "../../../testdata/test.missing_backend_provider.conf", + "../../testdata/test.missing_backend_provider.conf", `missing provider for backend "test"`, }, { // Case 3 - "../../../testdata/test.bad-cache-name.conf", + "../../testdata/test.bad-cache-name.conf", `invalid cache name "test_fail" provided in backend options "test"`, }, { // Case 4 - "../../../testdata/test.invalid-negative-cache-1.conf", + "../../testdata/test.invalid-negative-cache-1.conf", `invalid negative cache config in default: a is not a valid status code`, }, { // Case 5 - "../../../testdata/test.invalid-negative-cache-2.conf", + "../../testdata/test.invalid-negative-cache-2.conf", `invalid negative cache config in default: 1212 is not >= 400 and < 600`, }, { // Case 6 - "../../../testdata/test.invalid-negative-cache-3.conf", + "../../testdata/test.invalid-negative-cache-3.conf", `invalid negative cache name: foo`, }, { // Case 7 - "../../../testdata/test.invalid-pcf-name.conf", + "../../testdata/test.invalid-pcf-name.conf", `invalid collapsed_forwarding name: INVALID`, }, } @@ -122,7 +122,7 @@ func TestFullLoadConfiguration(t *testing.T) { t.Error(err) } - b, err := os.ReadFile("../../../testdata/test.full.02.conf") + b, err := os.ReadFile("../../testdata/test.full.02.conf") if err != nil { t.Error(err) } @@ -403,7 +403,7 @@ func TestFullLoadConfiguration(t *testing.T) { } func TestEmptyLoadConfiguration(t *testing.T) { - a := []string{"-config", "../../../testdata/test.empty.conf"} + a := []string{"-config", "../../testdata/test.empty.conf"} // it should not error if config path is not set conf, _, err := Load("trickster-test", "0", a) if err != nil { @@ -583,7 +583,7 @@ func TestLoadConfigurationBadArg(t *testing.T) { func TestLoadConfigurationWarning1(t *testing.T) { - a := []string{"-config", "../../../testdata/test.warning1.conf"} + a := []string{"-config", "../../testdata/test.warning1.conf"} // it should not error if config path is not set conf, _, err := Load("trickster-test", "0", a) if err != nil { @@ -601,7 +601,7 @@ func TestLoadConfigurationWarning1(t *testing.T) { func TestLoadConfigurationWarning2(t *testing.T) { - a := []string{"-config", "../../../testdata/test.warning2.conf"} + a := []string{"-config", "../../testdata/test.warning2.conf"} // it should not error if config path is not set conf, _, err := Load("trickster-test", "0", a) if err != nil { @@ -620,7 +620,7 @@ func TestLoadConfigurationWarning2(t *testing.T) { func TestLoadEmptyArgs(t *testing.T) { a := []string{} _, _, err := Load("trickster-test", "0", a) - if err == nil { - t.Error("expected error: no valid backends configured") + if err != ErrNoValidBackends { + t.Error("expected error:", ErrNoValidBackends) } } diff --git a/cmd/trickster/config/reload/options/defaults.go b/pkg/config/reload/options/defaults.go similarity index 100% rename from cmd/trickster/config/reload/options/defaults.go rename to pkg/config/reload/options/defaults.go diff --git a/cmd/trickster/config/reload/options/options.go b/pkg/config/reload/options/options.go similarity index 100% rename from cmd/trickster/config/reload/options/options.go rename to pkg/config/reload/options/options.go diff --git a/cmd/trickster/config/reload/options/options_test.go b/pkg/config/reload/options/options_test.go similarity index 100% rename from cmd/trickster/config/reload/options/options_test.go rename to pkg/config/reload/options/options_test.go diff --git a/cmd/trickster/config/reload/reload.go b/pkg/config/reload/reload.go similarity index 94% rename from cmd/trickster/config/reload/reload.go rename to pkg/config/reload/reload.go index 72cb41323..40792dde1 100644 --- a/cmd/trickster/config/reload/reload.go +++ b/pkg/config/reload/reload.go @@ -20,8 +20,8 @@ package reload import ( "sync" - "github.com/trickstercache/trickster/v2/cmd/trickster/config" "github.com/trickstercache/trickster/v2/pkg/cache" + "github.com/trickstercache/trickster/v2/pkg/config" tl "github.com/trickstercache/trickster/v2/pkg/observability/logging" ) diff --git a/cmd/trickster/config/tls.go b/pkg/config/tls.go similarity index 100% rename from cmd/trickster/config/tls.go rename to pkg/config/tls.go diff --git a/cmd/trickster/config/tls_test.go b/pkg/config/tls_test.go similarity index 100% rename from cmd/trickster/config/tls_test.go rename to pkg/config/tls_test.go diff --git a/pkg/errors/errors.go b/pkg/errors/errors.go index 35fa03671..fafc47b8a 100644 --- a/pkg/errors/errors.go +++ b/pkg/errors/errors.go @@ -20,3 +20,9 @@ import "errors" // ErrNilWriter is an error for a nil writer when a non-nil writer was expected var ErrNilWriter = errors.New("nil writer") + +// ErrInvalidOptions is an error for when a configuration is invalid +var ErrInvalidOptions = errors.New("invalid options") + +// ErrMissingPathconfig is an error for when a configuration is missing a path value +var ErrMissingPathconfig = errors.New("missing path config") diff --git a/cmd/trickster/config.go b/pkg/httpserver/httpserver.go similarity index 90% rename from cmd/trickster/config.go rename to pkg/httpserver/httpserver.go index 337450cd6..de3d995b2 100644 --- a/cmd/trickster/config.go +++ b/pkg/httpserver/httpserver.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package httpserver import ( "errors" @@ -26,31 +26,35 @@ import ( "sync" "time" - "github.com/trickstercache/trickster/v2/cmd/trickster/config" - ro "github.com/trickstercache/trickster/v2/cmd/trickster/config/reload/options" + "github.com/trickstercache/trickster/v2/cmd/trickster/usage" + "github.com/trickstercache/trickster/v2/pkg/appinfo" "github.com/trickstercache/trickster/v2/pkg/backends/alb" "github.com/trickstercache/trickster/v2/pkg/backends/healthcheck" "github.com/trickstercache/trickster/v2/pkg/cache" "github.com/trickstercache/trickster/v2/pkg/cache/memory" "github.com/trickstercache/trickster/v2/pkg/cache/providers" "github.com/trickstercache/trickster/v2/pkg/cache/registration" + "github.com/trickstercache/trickster/v2/pkg/config" + ro "github.com/trickstercache/trickster/v2/pkg/config/reload/options" + "github.com/trickstercache/trickster/v2/pkg/httpserver/signal" tl "github.com/trickstercache/trickster/v2/pkg/observability/logging" "github.com/trickstercache/trickster/v2/pkg/observability/metrics" tr "github.com/trickstercache/trickster/v2/pkg/observability/tracing/registration" "github.com/trickstercache/trickster/v2/pkg/proxy/handlers" "github.com/trickstercache/trickster/v2/pkg/router" "github.com/trickstercache/trickster/v2/pkg/routing" - "github.com/trickstercache/trickster/v2/pkg/runtime" ) var cfgLock = &sync.Mutex{} var hc healthcheck.HealthChecker -func runConfig(oldConf *config.Config, wg *sync.WaitGroup, logger *tl.Logger, +var _ signal.ServeFunc = Serve + +func Serve(oldConf *config.Config, wg *sync.WaitGroup, logger *tl.Logger, oldCaches map[string]cache.Cache, args []string, errorFunc func()) error { metrics.BuildInfo.WithLabelValues(goruntime.Version(), - applicationGitCommitID, applicationVersion).Set(1) + appinfo.GitCommitID, appinfo.Version).Set(1) cfgLock.Lock() defer cfgLock.Unlock() @@ -65,11 +69,11 @@ func runConfig(oldConf *config.Config, wg *sync.WaitGroup, logger *tl.Logger, } // load the config - conf, flags, err := config.Load(runtime.ApplicationName, runtime.ApplicationVersion, sargs) + conf, flags, err := config.Load(appinfo.Name, appinfo.Version, sargs) if err != nil { fmt.Println("\nERROR: Could not load configuration:", err.Error()) if flags != nil && !flags.ValidateConfig { - PrintUsage() + usage.PrintUsage() } handleStartupIssue("", nil, nil, errorFunc) return err @@ -77,7 +81,7 @@ func runConfig(oldConf *config.Config, wg *sync.WaitGroup, logger *tl.Logger, // if it's a -version command, print version and exit if flags.PrintVersion { - PrintVersion() + usage.PrintVersion() return nil } @@ -105,7 +109,7 @@ func applyConfig(conf, oldConf *config.Config, wg *sync.WaitGroup, logger *tl.Lo if conf.Main.ServerName == "" { conf.Main.ServerName, _ = os.Hostname() } - runtime.Server = conf.Main.ServerName + appinfo.SetServer(conf.Main.ServerName) if conf.ReloadConfig == nil { conf.ReloadConfig = ro.New() @@ -131,7 +135,7 @@ func applyConfig(conf, oldConf *config.Config, wg *sync.WaitGroup, logger *tl.Lo r.HandleFunc(conf.Main.PingHandlerPath, handlers.PingHandleFunc(conf)).Methods(http.MethodGet) var caches = applyCachingConfig(conf, oldConf, logger, oldCaches) - rh := handlers.ReloadHandleFunc(runConfig, conf, wg, logger, caches, args) + rh := handlers.ReloadHandleFunc(Serve, conf, wg, logger, caches, args) o, err := routing.RegisterProxyRoutes(conf, r, mr, caches, tracers, logger, false) if err != nil { @@ -152,7 +156,7 @@ func applyConfig(conf, oldConf *config.Config, wg *sync.WaitGroup, logger *tl.Lo alb.StartALBPools(o, hc.Statuses()) routing.RegisterDefaultBackendRoutes(r, o, logger, tracers) routing.RegisterHealthHandler(mr, conf.Main.HealthHandlerPath, hc) - applyListenerConfigs(conf, oldConf, r, http.HandlerFunc(rh), mr, logger, tracers, o) + applyListenerConfigs(conf, oldConf, r, http.HandlerFunc(rh), mr, logger, tracers, o, wg, errorFunc) metrics.LastReloadSuccessfulTimestamp.Set(float64(time.Now().Unix())) metrics.LastReloadSuccessful.Set(1) @@ -160,7 +164,7 @@ func applyConfig(conf, oldConf *config.Config, wg *sync.WaitGroup, logger *tl.Lo if oldConf != nil && oldConf.Resources != nil { oldConf.Resources.QuitChan <- true // this signals the old hup monitor goroutine to exit } - startHupMonitor(conf, wg, logger, caches, args) + signal.StartHupMonitor(conf, wg, logger, caches, args, Serve) return nil } @@ -261,13 +265,13 @@ func initLogger(c *config.Config) *tl.Logger { logger := tl.New(c) tl.Info(logger, "application loaded from configuration", tl.Pairs{ - "name": runtime.ApplicationName, - "version": runtime.ApplicationVersion, + "name": appinfo.Name, + "version": appinfo.Version, "goVersion": goruntime.Version(), "goArch": goruntime.GOARCH, "goOS": goruntime.GOOS, - "commitID": applicationGitCommitID, - "buildTime": applicationBuildTime, + "commitID": appinfo.GitCommitID, + "buildTime": appinfo.BuildTime, "logLevel": c.Logging.LogLevel, "config": c.ConfigFilePath(), "pid": os.Getpid(), diff --git a/cmd/trickster/listeners.go b/pkg/httpserver/listeners.go similarity index 94% rename from cmd/trickster/listeners.go rename to pkg/httpserver/listeners.go index 1ae6f0ea3..89b2f3e7b 100644 --- a/cmd/trickster/listeners.go +++ b/pkg/httpserver/listeners.go @@ -14,15 +14,16 @@ * limitations under the License. */ -package main +package httpserver import ( "crypto/tls" "net/http" + "sync" "time" - "github.com/trickstercache/trickster/v2/cmd/trickster/config" "github.com/trickstercache/trickster/v2/pkg/backends" + "github.com/trickstercache/trickster/v2/pkg/config" tl "github.com/trickstercache/trickster/v2/pkg/observability/logging" "github.com/trickstercache/trickster/v2/pkg/observability/metrics" "github.com/trickstercache/trickster/v2/pkg/observability/tracing" @@ -35,8 +36,9 @@ import ( var lg = listener.NewListenerGroup() func applyListenerConfigs(conf, oldConf *config.Config, - router, reloadHandler http.Handler, metricsRouter *http.ServeMux, log *tl.Logger, - tracers tracing.Tracers, o backends.Backends) { + router, reloadHandler http.Handler, metricsRouter *http.ServeMux, + log *tl.Logger, tracers tracing.Tracers, o backends.Backends, + wg *sync.WaitGroup, errorFunc func()) { var err error var tlsConfig *tls.Config @@ -93,7 +95,7 @@ func applyListenerConfigs(conf, oldConf *config.Config, tracerFlusherSet = true go lg.StartListener("tlsListener", conf.Frontend.TLSListenAddress, conf.Frontend.TLSListenPort, - conf.Frontend.ConnectionsLimit, tlsConfig, router, wg, tracers, exitFunc, + conf.Frontend.ConnectionsLimit, tlsConfig, router, wg, tracers, errorFunc, time.Duration(conf.ReloadConfig.DrainTimeoutMS)*time.Millisecond, log) } } else if !conf.Frontend.ServeTLS && hasOldFC && oldConf.Frontend.ServeTLS { @@ -101,7 +103,7 @@ func applyListenerConfigs(conf, oldConf *config.Config, // the TLS listener port needs to be stopped lg.DrainAndClose("tlsListener", drainTimeout) } else if conf.Frontend.ServeTLS && ttls.OptionsChanged(conf, oldConf) { - tlsConfig, _ = conf.TLSCertConfig() + tlsConfig, err = conf.TLSCertConfig() if err != nil { tl.Error(log, "unable to update tls config to certificate error", tl.Pairs{"detail": err}) return @@ -127,7 +129,7 @@ func applyListenerConfigs(conf, oldConf *config.Config, } go lg.StartListener("httpListener", conf.Frontend.ListenAddress, conf.Frontend.ListenPort, - conf.Frontend.ConnectionsLimit, nil, router, wg, t2, exitFunc, 0, log) + conf.Frontend.ConnectionsLimit, nil, router, wg, t2, errorFunc, 0, log) } // if the Metrics HTTP port is configured, then set up the http listener instance @@ -143,7 +145,7 @@ func applyListenerConfigs(conf, oldConf *config.Config, wg.Add(1) go lg.StartListener("metricsListener", conf.Metrics.ListenAddress, conf.Metrics.ListenPort, - conf.Frontend.ConnectionsLimit, nil, metricsRouter, wg, nil, exitFunc, 0, log) + conf.Frontend.ConnectionsLimit, nil, metricsRouter, wg, nil, errorFunc, 0, log) } else { metricsRouter.Handle("/metrics", metrics.Handler()) metricsRouter.HandleFunc(conf.Main.ConfigHandlerPath, handlers.ConfigHandleFunc(conf)) @@ -166,7 +168,7 @@ func applyListenerConfigs(conf, oldConf *config.Config, } go lg.StartListener("reloadListener", conf.ReloadConfig.ListenAddress, conf.ReloadConfig.ListenPort, - conf.Frontend.ConnectionsLimit, nil, rr, wg, nil, exitFunc, 0, log) + conf.Frontend.ConnectionsLimit, nil, rr, wg, nil, errorFunc, 0, log) } else { rr.HandleFunc(conf.Main.ConfigHandlerPath, handlers.ConfigHandleFunc(conf)) rr.Handle(conf.ReloadConfig.HandlerPath, reloadHandler) diff --git a/cmd/trickster/signal.go b/pkg/httpserver/signal/signal.go similarity index 77% rename from cmd/trickster/signal.go rename to pkg/httpserver/signal/signal.go index cf0c5e260..9278db134 100644 --- a/cmd/trickster/signal.go +++ b/pkg/httpserver/signal/signal.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package signal import ( "os" @@ -22,8 +22,8 @@ import ( "sync" "syscall" - "github.com/trickstercache/trickster/v2/cmd/trickster/config" "github.com/trickstercache/trickster/v2/pkg/cache" + "github.com/trickstercache/trickster/v2/pkg/config" tl "github.com/trickstercache/trickster/v2/pkg/observability/logging" ) @@ -33,9 +33,12 @@ func init() { signal.Notify(hups, syscall.SIGHUP) } -func startHupMonitor(conf *config.Config, wg *sync.WaitGroup, log *tl.Logger, - caches map[string]cache.Cache, args []string) { - if conf == nil || conf.Resources == nil { +type ServeFunc = func(*config.Config, *sync.WaitGroup, *tl.Logger, + map[string]cache.Cache, []string, func()) error + +func StartHupMonitor(conf *config.Config, wg *sync.WaitGroup, log *tl.Logger, + caches map[string]cache.Cache, args []string, f ServeFunc) { + if conf == nil || conf.Resources == nil || f == nil { return } // assumes all parameters are instantiated @@ -46,7 +49,7 @@ func startHupMonitor(conf *config.Config, wg *sync.WaitGroup, log *tl.Logger, conf.Main.ReloaderLock.Lock() if conf.IsStale() { tl.Warn(log, "configuration reload starting now", tl.Pairs{"source": "sighup"}) - err := runConfig(conf, wg, log, caches, args, nil) + err := f(conf, wg, log, caches, args, nil) if err == nil { conf.Main.ReloaderLock.Unlock() return // runConfig will start a new HupMonitor in place of this one diff --git a/cmd/trickster/signal_test.go b/pkg/httpserver/signal/signal_test.go similarity index 71% rename from cmd/trickster/signal_test.go rename to pkg/httpserver/signal/signal_test.go index 701e06c8c..5b0634254 100644 --- a/cmd/trickster/signal_test.go +++ b/pkg/httpserver/signal/signal_test.go @@ -14,18 +14,26 @@ * limitations under the License. */ -package main +package signal import ( "net/http/httptest" + "sync" "syscall" "testing" "time" - "github.com/trickstercache/trickster/v2/cmd/trickster/config" + "github.com/trickstercache/trickster/v2/pkg/cache" + "github.com/trickstercache/trickster/v2/pkg/config" "github.com/trickstercache/trickster/v2/pkg/observability/logging" + tl "github.com/trickstercache/trickster/v2/pkg/observability/logging" ) +func mockServe(oldConf *config.Config, wg *sync.WaitGroup, logger *tl.Logger, + oldCaches map[string]cache.Cache, args []string, errorFunc func()) error { + return nil +} + func TestStartHupMonitor(t *testing.T) { // passing case for this test is no panics or hangs @@ -33,16 +41,16 @@ func TestStartHupMonitor(t *testing.T) { w := httptest.NewRecorder() logger := logging.StreamLogger(w, "WARN") - startHupMonitor(nil, nil, nil, nil, nil) + StartHupMonitor(nil, nil, nil, nil, nil, mockServe) qch := make(chan bool) conf := config.NewConfig() conf.Resources = &config.Resources{QuitChan: qch} - startHupMonitor(conf, nil, logger, nil, nil) + StartHupMonitor(conf, nil, logger, nil, nil, mockServe) time.Sleep(time.Millisecond * 100) qch <- true - startHupMonitor(conf, nil, logger, nil, nil) + StartHupMonitor(conf, nil, logger, nil, nil, mockServe) time.Sleep(time.Millisecond * 100) hups <- syscall.SIGHUP time.Sleep(time.Millisecond * 100) @@ -55,7 +63,7 @@ func TestStartHupMonitor(t *testing.T) { now := time.Unix(1577836800, 0) nowMinus1m := time.Now().Add(-1 * time.Minute) conf.Main.SetStalenessInfo("../../testdata/test.empty.conf", now, nowMinus1m) - startHupMonitor(conf, nil, logger, nil, nil) + StartHupMonitor(conf, nil, logger, nil, nil, mockServe) time.Sleep(time.Millisecond * 100) hups <- syscall.SIGHUP time.Sleep(time.Millisecond * 100) diff --git a/pkg/observability/logging/logging.go b/pkg/observability/logging/logging.go index 226e347f1..af4a54618 100644 --- a/pkg/observability/logging/logging.go +++ b/pkg/observability/logging/logging.go @@ -26,7 +26,7 @@ import ( "strings" "sync" - "github.com/trickstercache/trickster/v2/cmd/trickster/config" + "github.com/trickstercache/trickster/v2/pkg/config" gkl "github.com/go-kit/log" "github.com/go-kit/log/level" diff --git a/pkg/observability/logging/logging_test.go b/pkg/observability/logging/logging_test.go index 83482c075..8910a7c34 100644 --- a/pkg/observability/logging/logging_test.go +++ b/pkg/observability/logging/logging_test.go @@ -23,7 +23,7 @@ import ( "testing" "time" - "github.com/trickstercache/trickster/v2/cmd/trickster/config" + "github.com/trickstercache/trickster/v2/pkg/config" "github.com/trickstercache/trickster/v2/pkg/observability/logging/options" gkl "github.com/go-kit/log" @@ -58,7 +58,6 @@ func TestNew(t *testing.T) { if logger.level != "info" { t.Errorf("expected %s got %s", "info", logger.level) } - logger.Close() } func TestNewLogger_LogFile(t *testing.T) { diff --git a/pkg/observability/tracing/registration/registration.go b/pkg/observability/tracing/registration/registration.go index 6ea418a8a..38b4cb7d9 100644 --- a/pkg/observability/tracing/registration/registration.go +++ b/pkg/observability/tracing/registration/registration.go @@ -21,7 +21,7 @@ import ( "errors" "fmt" - "github.com/trickstercache/trickster/v2/cmd/trickster/config" + "github.com/trickstercache/trickster/v2/pkg/config" tl "github.com/trickstercache/trickster/v2/pkg/observability/logging" "github.com/trickstercache/trickster/v2/pkg/observability/tracing" "github.com/trickstercache/trickster/v2/pkg/observability/tracing/exporters/jaeger" diff --git a/pkg/observability/tracing/registration/registration_test.go b/pkg/observability/tracing/registration/registration_test.go index 6d1eee429..424d92e1c 100644 --- a/pkg/observability/tracing/registration/registration_test.go +++ b/pkg/observability/tracing/registration/registration_test.go @@ -19,7 +19,7 @@ package registration import ( "testing" - "github.com/trickstercache/trickster/v2/cmd/trickster/config" + "github.com/trickstercache/trickster/v2/pkg/config" tl "github.com/trickstercache/trickster/v2/pkg/observability/logging" "github.com/trickstercache/trickster/v2/pkg/observability/tracing/options" ) diff --git a/pkg/proxy/engines/access_logs_test.go b/pkg/proxy/engines/access_logs_test.go index 622a4941a..c1cde0f2f 100644 --- a/pkg/proxy/engines/access_logs_test.go +++ b/pkg/proxy/engines/access_logs_test.go @@ -21,7 +21,7 @@ import ( "os" "testing" - "github.com/trickstercache/trickster/v2/cmd/trickster/config" + "github.com/trickstercache/trickster/v2/pkg/config" tl "github.com/trickstercache/trickster/v2/pkg/observability/logging" tlo "github.com/trickstercache/trickster/v2/pkg/observability/logging/options" ) diff --git a/pkg/proxy/engines/cache_chunk_test.go b/pkg/proxy/engines/cache_chunk_test.go index a17463486..63699e340 100644 --- a/pkg/proxy/engines/cache_chunk_test.go +++ b/pkg/proxy/engines/cache_chunk_test.go @@ -25,8 +25,8 @@ import ( "testing" "time" - "github.com/trickstercache/trickster/v2/cmd/trickster/config" cr "github.com/trickstercache/trickster/v2/pkg/cache/registration" + "github.com/trickstercache/trickster/v2/pkg/config" tc "github.com/trickstercache/trickster/v2/pkg/proxy/context" "github.com/trickstercache/trickster/v2/pkg/proxy/headers" "github.com/trickstercache/trickster/v2/pkg/proxy/ranges/byterange" diff --git a/pkg/proxy/engines/cache_test.go b/pkg/proxy/engines/cache_test.go index 8ed500c3a..ca8941f27 100644 --- a/pkg/proxy/engines/cache_test.go +++ b/pkg/proxy/engines/cache_test.go @@ -28,10 +28,10 @@ import ( "testing" "time" - "github.com/trickstercache/trickster/v2/cmd/trickster/config" co "github.com/trickstercache/trickster/v2/pkg/cache/options" cr "github.com/trickstercache/trickster/v2/pkg/cache/registration" "github.com/trickstercache/trickster/v2/pkg/cache/status" + "github.com/trickstercache/trickster/v2/pkg/config" "github.com/trickstercache/trickster/v2/pkg/locks" tc "github.com/trickstercache/trickster/v2/pkg/proxy/context" "github.com/trickstercache/trickster/v2/pkg/proxy/headers" diff --git a/pkg/proxy/engines/httpproxy_test.go b/pkg/proxy/engines/httpproxy_test.go index bc2217252..14e3f08d6 100644 --- a/pkg/proxy/engines/httpproxy_test.go +++ b/pkg/proxy/engines/httpproxy_test.go @@ -24,7 +24,7 @@ import ( "testing" "time" - "github.com/trickstercache/trickster/v2/cmd/trickster/config" + "github.com/trickstercache/trickster/v2/pkg/config" tl "github.com/trickstercache/trickster/v2/pkg/observability/logging" tc "github.com/trickstercache/trickster/v2/pkg/proxy/context" "github.com/trickstercache/trickster/v2/pkg/proxy/forwarding" diff --git a/pkg/proxy/engines/proxy_request_test.go b/pkg/proxy/engines/proxy_request_test.go index 5cabf658e..b3b7cefc8 100644 --- a/pkg/proxy/engines/proxy_request_test.go +++ b/pkg/proxy/engines/proxy_request_test.go @@ -23,10 +23,10 @@ import ( "testing" "time" - "github.com/trickstercache/trickster/v2/cmd/trickster/config" bo "github.com/trickstercache/trickster/v2/pkg/backends/options" cr "github.com/trickstercache/trickster/v2/pkg/cache/registration" "github.com/trickstercache/trickster/v2/pkg/cache/status" + "github.com/trickstercache/trickster/v2/pkg/config" tl "github.com/trickstercache/trickster/v2/pkg/observability/logging" "github.com/trickstercache/trickster/v2/pkg/proxy/headers" "github.com/trickstercache/trickster/v2/pkg/proxy/ranges/byterange" diff --git a/pkg/proxy/handlers/config.go b/pkg/proxy/handlers/config.go index 19a3be1c4..151de5355 100644 --- a/pkg/proxy/handlers/config.go +++ b/pkg/proxy/handlers/config.go @@ -19,7 +19,7 @@ package handlers import ( "net/http" - "github.com/trickstercache/trickster/v2/cmd/trickster/config" + "github.com/trickstercache/trickster/v2/pkg/config" "github.com/trickstercache/trickster/v2/pkg/proxy/headers" ) diff --git a/pkg/proxy/handlers/config_test.go b/pkg/proxy/handlers/config_test.go index be7601158..f9fc357c1 100644 --- a/pkg/proxy/handlers/config_test.go +++ b/pkg/proxy/handlers/config_test.go @@ -22,7 +22,7 @@ import ( "strings" "testing" - "github.com/trickstercache/trickster/v2/cmd/trickster/config" + "github.com/trickstercache/trickster/v2/pkg/config" ) func TestConfigHandler(t *testing.T) { diff --git a/pkg/proxy/handlers/local_test.go b/pkg/proxy/handlers/local_test.go index 8a0c97a0e..661e3a5d4 100644 --- a/pkg/proxy/handlers/local_test.go +++ b/pkg/proxy/handlers/local_test.go @@ -21,7 +21,7 @@ import ( "net/http/httptest" "testing" - "github.com/trickstercache/trickster/v2/cmd/trickster/config" + "github.com/trickstercache/trickster/v2/pkg/config" tl "github.com/trickstercache/trickster/v2/pkg/observability/logging" tc "github.com/trickstercache/trickster/v2/pkg/proxy/context" "github.com/trickstercache/trickster/v2/pkg/proxy/headers" diff --git a/pkg/proxy/handlers/ping.go b/pkg/proxy/handlers/ping.go index a85dc5e8e..f21895ea0 100644 --- a/pkg/proxy/handlers/ping.go +++ b/pkg/proxy/handlers/ping.go @@ -19,7 +19,7 @@ package handlers import ( "net/http" - "github.com/trickstercache/trickster/v2/cmd/trickster/config" + "github.com/trickstercache/trickster/v2/pkg/config" "github.com/trickstercache/trickster/v2/pkg/proxy/headers" ) diff --git a/pkg/proxy/handlers/ping_test.go b/pkg/proxy/handlers/ping_test.go index 5ad129524..9685bd944 100644 --- a/pkg/proxy/handlers/ping_test.go +++ b/pkg/proxy/handlers/ping_test.go @@ -21,7 +21,7 @@ import ( "net/http/httptest" "testing" - "github.com/trickstercache/trickster/v2/cmd/trickster/config" + "github.com/trickstercache/trickster/v2/pkg/config" ) func TestPingHandler(t *testing.T) { diff --git a/pkg/proxy/handlers/purge.go b/pkg/proxy/handlers/purge.go index 8a42ea8de..50fa05921 100644 --- a/pkg/proxy/handlers/purge.go +++ b/pkg/proxy/handlers/purge.go @@ -19,9 +19,9 @@ package handlers import ( "net/http" - "github.com/trickstercache/trickster/v2/cmd/trickster/config" "github.com/trickstercache/trickster/v2/pkg/backends" "github.com/trickstercache/trickster/v2/pkg/checksum/md5" + "github.com/trickstercache/trickster/v2/pkg/config" "github.com/trickstercache/trickster/v2/pkg/observability/logging" "github.com/trickstercache/trickster/v2/pkg/proxy/headers" "github.com/trickstercache/trickster/v2/pkg/proxy/request" diff --git a/pkg/proxy/handlers/reload.go b/pkg/proxy/handlers/reload.go index eeab53ad6..d527ba847 100644 --- a/pkg/proxy/handlers/reload.go +++ b/pkg/proxy/handlers/reload.go @@ -20,9 +20,9 @@ import ( "net/http" "sync" - "github.com/trickstercache/trickster/v2/cmd/trickster/config" - "github.com/trickstercache/trickster/v2/cmd/trickster/config/reload" "github.com/trickstercache/trickster/v2/pkg/cache" + "github.com/trickstercache/trickster/v2/pkg/config" + "github.com/trickstercache/trickster/v2/pkg/config/reload" tl "github.com/trickstercache/trickster/v2/pkg/observability/logging" "github.com/trickstercache/trickster/v2/pkg/proxy/headers" ) diff --git a/pkg/proxy/handlers/reload_test.go b/pkg/proxy/handlers/reload_test.go index 1144d2bd4..d21f7fddc 100644 --- a/pkg/proxy/handlers/reload_test.go +++ b/pkg/proxy/handlers/reload_test.go @@ -24,8 +24,8 @@ import ( "testing" "time" - "github.com/trickstercache/trickster/v2/cmd/trickster/config" "github.com/trickstercache/trickster/v2/pkg/cache" + "github.com/trickstercache/trickster/v2/pkg/config" tl "github.com/trickstercache/trickster/v2/pkg/observability/logging" ) diff --git a/pkg/proxy/headers/forwarding.go b/pkg/proxy/headers/forwarding.go index 0a1b5ae45..579c1793a 100644 --- a/pkg/proxy/headers/forwarding.go +++ b/pkg/proxy/headers/forwarding.go @@ -22,7 +22,7 @@ import ( "net/http" "strings" - "github.com/trickstercache/trickster/v2/pkg/runtime" + "github.com/trickstercache/trickster/v2/pkg/appinfo" ) const ( @@ -207,9 +207,9 @@ func SetVia(r *http.Request, hop *Hop) { return } if hop.Via != "" { - r.Header.Set(NameVia, hop.Via+", "+hop.Protocol+" "+runtime.Server) + r.Header.Set(NameVia, hop.Via+", "+hop.Protocol+" "+appinfo.Server) } else { - r.Header.Set(NameVia, hop.Protocol+" "+runtime.Server) + r.Header.Set(NameVia, hop.Protocol+" "+appinfo.Server) } } diff --git a/pkg/proxy/headers/headers_test.go b/pkg/proxy/headers/headers_test.go index 8a799a406..11c8da010 100644 --- a/pkg/proxy/headers/headers_test.go +++ b/pkg/proxy/headers/headers_test.go @@ -21,7 +21,7 @@ import ( "reflect" "testing" - "github.com/trickstercache/trickster/v2/pkg/runtime" + "github.com/trickstercache/trickster/v2/pkg/appinfo" ) func TestExtractHeader(t *testing.T) { @@ -32,8 +32,8 @@ func TestExtractHeader(t *testing.T) { const appVer = "tests" const appString = appName + " " + appVer - runtime.ApplicationName = appName - runtime.ApplicationVersion = appVer + appinfo.Name = appName + appinfo.Version = appVer const testIP = "0.0.0.0" @@ -116,8 +116,8 @@ func TestMerge(t *testing.T) { func TestAddResponseHeaders(t *testing.T) { headers := http.Header{} - runtime.ApplicationName = "trickster-test" - runtime.ApplicationVersion = "tests" + appinfo.Name = "trickster-test" + appinfo.Version = "tests" AddResponseHeaders(headers) diff --git a/pkg/proxy/listener/listener_test.go b/pkg/proxy/listener/listener_test.go index bf47f0e27..a3c6e0f93 100644 --- a/pkg/proxy/listener/listener_test.go +++ b/pkg/proxy/listener/listener_test.go @@ -29,7 +29,7 @@ import ( "testing" "time" - "github.com/trickstercache/trickster/v2/cmd/trickster/config" + "github.com/trickstercache/trickster/v2/pkg/config" tl "github.com/trickstercache/trickster/v2/pkg/observability/logging" "github.com/trickstercache/trickster/v2/pkg/observability/tracing" "github.com/trickstercache/trickster/v2/pkg/observability/tracing/exporters/stdout" diff --git a/pkg/proxy/tls/tls.go b/pkg/proxy/tls/tls.go index ec2da485c..610d3d398 100644 --- a/pkg/proxy/tls/tls.go +++ b/pkg/proxy/tls/tls.go @@ -17,7 +17,7 @@ // Package tls handles options for TLS (https) requests package tls -import "github.com/trickstercache/trickster/v2/cmd/trickster/config" +import "github.com/trickstercache/trickster/v2/pkg/config" // OptionsChanged will return true if the TLS options for any backend // is different between configs diff --git a/pkg/proxy/tls/tls_test.go b/pkg/proxy/tls/tls_test.go index 702711c7a..fc88d1f50 100644 --- a/pkg/proxy/tls/tls_test.go +++ b/pkg/proxy/tls/tls_test.go @@ -21,7 +21,7 @@ import ( "strings" "testing" - "github.com/trickstercache/trickster/v2/cmd/trickster/config" + "github.com/trickstercache/trickster/v2/pkg/config" "github.com/trickstercache/trickster/v2/pkg/proxy/tls/options" tlstest "github.com/trickstercache/trickster/v2/pkg/testutil/tls" ) diff --git a/pkg/routing/routing.go b/pkg/routing/routing.go index 1f8f3c5d8..48766aa8f 100644 --- a/pkg/routing/routing.go +++ b/pkg/routing/routing.go @@ -24,7 +24,6 @@ import ( "sort" "strings" - "github.com/trickstercache/trickster/v2/cmd/trickster/config" "github.com/trickstercache/trickster/v2/pkg/backends" "github.com/trickstercache/trickster/v2/pkg/backends/alb" "github.com/trickstercache/trickster/v2/pkg/backends/healthcheck" @@ -34,6 +33,7 @@ import ( "github.com/trickstercache/trickster/v2/pkg/backends/reverseproxycache" "github.com/trickstercache/trickster/v2/pkg/backends/rule" "github.com/trickstercache/trickster/v2/pkg/cache" + "github.com/trickstercache/trickster/v2/pkg/config" encoding "github.com/trickstercache/trickster/v2/pkg/encoding/handler" tl "github.com/trickstercache/trickster/v2/pkg/observability/logging" "github.com/trickstercache/trickster/v2/pkg/observability/tracing" diff --git a/pkg/routing/routing_test.go b/pkg/routing/routing_test.go index e9cbe1e2a..71dd56e8b 100644 --- a/pkg/routing/routing_test.go +++ b/pkg/routing/routing_test.go @@ -23,7 +23,6 @@ import ( "strings" "testing" - "github.com/trickstercache/trickster/v2/cmd/trickster/config" "github.com/trickstercache/trickster/v2/pkg/backends" "github.com/trickstercache/trickster/v2/pkg/backends/alb/options" "github.com/trickstercache/trickster/v2/pkg/backends/healthcheck" @@ -31,6 +30,7 @@ import ( "github.com/trickstercache/trickster/v2/pkg/backends/reverseproxycache" "github.com/trickstercache/trickster/v2/pkg/backends/rule" "github.com/trickstercache/trickster/v2/pkg/cache/registration" + "github.com/trickstercache/trickster/v2/pkg/config" "github.com/trickstercache/trickster/v2/pkg/observability/logging" "github.com/trickstercache/trickster/v2/pkg/observability/tracing" "github.com/trickstercache/trickster/v2/pkg/observability/tracing/exporters/zipkin" diff --git a/pkg/testutil/testing.go b/pkg/testutil/testing.go index f775afcf9..0e0ed25d1 100644 --- a/pkg/testutil/testing.go +++ b/pkg/testutil/testing.go @@ -26,9 +26,10 @@ import ( "strings" "time" - "github.com/trickstercache/trickster/v2/cmd/trickster/config" + "github.com/trickstercache/trickster/v2/pkg/appinfo" bo "github.com/trickstercache/trickster/v2/pkg/backends/options" cr "github.com/trickstercache/trickster/v2/pkg/cache/registration" + "github.com/trickstercache/trickster/v2/pkg/config" tl "github.com/trickstercache/trickster/v2/pkg/observability/logging" "github.com/trickstercache/trickster/v2/pkg/observability/tracing" to "github.com/trickstercache/trickster/v2/pkg/observability/tracing/options" @@ -39,7 +40,6 @@ import ( "github.com/trickstercache/trickster/v2/pkg/proxy/request" "github.com/trickstercache/trickster/v2/pkg/proxy/request/rewriter" "github.com/trickstercache/trickster/v2/pkg/proxy/request/rewriter/options" - "github.com/trickstercache/trickster/v2/pkg/runtime" "github.com/trickstercache/mockster/pkg/testutil" ) @@ -56,7 +56,7 @@ var ErrTest = errors.New("test error") // this actively sets the ApplicationName for testing purposes // do not import this package from main or any of its recursive imports func init() { - runtime.ApplicationName = "trickster-unit-tests" + appinfo.Name = "trickster-unit-tests" } // NewTestServer returns a new httptest.Server that responds with the provided code, body and headers