Skip to content
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

Add channel to worker logs #4316

Merged
merged 6 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
run: git config --global --add safe.directory "$(pwd)"

- name: Run unit tests
run: go test -race -covermode=atomic -coverprofile=coverage.txt -coverpkg=$(go list ./... | grep -v rpmmd/test$ | tr "\n" ",") ./...
run: make unit-tests

- uses: codecov/codecov-action@v4
if: env.CODECOV_TOKEN
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ __pycache__
container_composer_golangci_built.info
processed-templates

coverage.txt
coverage.html

coverage_splunk_logger.txt
coverage_splunk_logger.html
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ help:
@echo " (do this before pushing!)"
@echo " lint: Runs linters as close as github workflow as possible"
@echo " process-templates: Execute the OpenShift CLI to check the templates"
@echo " coverage-report: Run unit tests and generate HTML coverage reports"

$(BUILDDIR)/:
mkdir -p "$@"
Expand Down Expand Up @@ -234,8 +235,17 @@ worker-key-pair: ca
rm /etc/osbuild-composer/worker-csr.pem

.PHONY: unit-tests
.ONESHELL:
unit-tests:
go test -race ./...
go test -race -covermode=atomic -coverprofile=coverage.txt -coverpkg=$$(go list ./... | tr "\n" ",") ./...
# go modules with go.mod in subdirs are not tested automatically
cd pkg/splunk_logger
go test -race -covermode=atomic -coverprofile=../../coverage_splunk_logger.txt -coverpkg=$$(go list ./... | tr "\n" ",") ./...

.PHONY: coverage-report
coverage-report: unit-tests
go tool cover -o coverage.html -html coverage.txt
go tool cover -o coverage_splunk_logger.html -html coverage_splunk_logger.txt

#
# Building packages
Expand Down
2 changes: 1 addition & 1 deletion cmd/osbuild-composer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func main() {
}

if config.DeploymentChannel != "" {
logrus.AddHook(&common.EnvironmentHook{Channel: config.DeploymentChannel})
logrus.AddHook(&slogger.EnvironmentHook{Channel: config.DeploymentChannel})
}

if config.SplunkHost != "" {
Expand Down
3 changes: 3 additions & 0 deletions cmd/osbuild-worker/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ type workerConfig struct {
// default value: &{ Type: host }
OSBuildExecutor *executorConfig `toml:"osbuild_executor"`
RepositoryMTLSConfig *repositoryMTLSConfig `toml:"repository_mtls"`
// something like "production" or "staging" to be added to logging
DeploymentChannel string `toml:"deployment_channel"`
}

func parseConfig(file string) (*workerConfig, error) {
Expand All @@ -112,6 +114,7 @@ func parseConfig(file string) (*workerConfig, error) {
OSBuildExecutor: &executorConfig{
Type: "host",
},
DeploymentChannel: "local",
}

_, err := toml.DecodeFile(file, &config)
Expand Down
13 changes: 13 additions & 0 deletions cmd/osbuild-worker/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ cloudwatch_group = "osbuild-worker"
Credentials: "/etc/osbuild-worker/pulp-creds",
ServerURL: "https://example.com/pulp",
},
DeploymentChannel: "local",
},
},
{
Expand All @@ -146,6 +147,18 @@ cloudwatch_group = "osbuild-worker"
OSBuildExecutor: &executorConfig{
Type: "host",
},
DeploymentChannel: "local",
},
},
{
name: "set_channel",
config: `deployment_channel = "staging"`,
want: &workerConfig{
BasePath: "/api/worker/v1",
OSBuildExecutor: &executorConfig{
Type: "host",
},
DeploymentChannel: "staging",
},
},
}
Expand Down
5 changes: 5 additions & 0 deletions cmd/osbuild-worker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"errors"
"flag"
"fmt"
slogger "github.com/osbuild/osbuild-composer/pkg/splunk_logger"
"net/url"
"os"
"path"
Expand Down Expand Up @@ -193,6 +194,10 @@ func main() {
logrus.Fatalf("Could not print config: %v", err)
}

if config.DeploymentChannel != "" {
logrus.AddHook(&slogger.EnvironmentHook{Channel: config.DeploymentChannel})
}

cacheDirectory, ok := os.LookupEnv("CACHE_DIRECTORY")
if !ok {
logrus.Fatal("CACHE_DIRECTORY is not set. Is the service file missing CacheDirectory=?")
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ require (
github.com/openshift-online/ocm-sdk-go v0.1.432
github.com/oracle/oci-go-sdk/v54 v54.0.0
github.com/osbuild/images v0.79.0
github.com/osbuild/osbuild-composer/pkg/splunk_logger v0.0.0-20231117174845-e969a9dc3cd1
github.com/osbuild/osbuild-composer/pkg/splunk_logger v0.0.0-20240814102216-0239db53236d
github.com/osbuild/pulp-client v0.1.0
github.com/prometheus/client_golang v1.19.1
github.com/segmentio/ksuid v1.0.4
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -510,8 +510,8 @@ github.com/oracle/oci-go-sdk/v54 v54.0.0 h1:CDLjeSejv2aDpElAJrhKpi6zvT/zhZCZuXch
github.com/oracle/oci-go-sdk/v54 v54.0.0/go.mod h1:+t+yvcFGVp+3ZnztnyxqXfQDsMlq8U25faBLa+mqCMc=
github.com/osbuild/images v0.79.0 h1:6kBRo0WzmyQTZ4ojX1oU9nIxBazZOO4I3FLsZaz8268=
github.com/osbuild/images v0.79.0/go.mod h1:Rzud9PFt0L9qFFlisL9I6OsZ2h0M6viMBdPhPtpwfwg=
github.com/osbuild/osbuild-composer/pkg/splunk_logger v0.0.0-20231117174845-e969a9dc3cd1 h1:UFEJIcPa46W8gtWgOYzriRKYyy1t6SWL0BI7fPTuVvc=
github.com/osbuild/osbuild-composer/pkg/splunk_logger v0.0.0-20231117174845-e969a9dc3cd1/go.mod h1:z+WA+dX6qMwc7fqY5jCzESDIlg4WR2sBQezxsoXv9Ik=
github.com/osbuild/osbuild-composer/pkg/splunk_logger v0.0.0-20240814102216-0239db53236d h1:r9BFPDv0uuA9k1947Jybcxs36c/pTywWS1gjeizvtcQ=
github.com/osbuild/osbuild-composer/pkg/splunk_logger v0.0.0-20240814102216-0239db53236d/go.mod h1:zR1iu/hOuf+OQNJlk70tju9IqzzM4ycq0ectkFBm94U=
github.com/osbuild/pulp-client v0.1.0 h1:L0C4ezBJGTamN3BKdv+rKLuq/WxXJbsFwz/Hj7aEmJ8=
github.com/osbuild/pulp-client v0.1.0/go.mod h1:rd/MLdfwwO2cQI1s056h8z32zAi3Bo90XhlAAryIvWc=
github.com/ostreedev/ostree-go v0.0.0-20210805093236-719684c64e4f h1:/UDgs8FGMqwnHagNDPGOlts35QkhAZ8by3DR7nMih7M=
Expand Down
30 changes: 0 additions & 30 deletions internal/common/environment_hook_test.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jq -r ".client_secret" /tmp/client-credentials.json > /etc/osbuild-worker/client
rm -f /tmp/client-credentials.json

sudo tee -a /etc/osbuild-worker/osbuild-worker.toml > /dev/null << EOF
deployment_channel = "${CHANNEL:-local}"
schuellerf marked this conversation as resolved.
Show resolved Hide resolved
[authentication]
oauth_url = "${TOKEN_URL:-https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token}"
client_id = "${CLIENT_ID}"
Expand Down
2 changes: 2 additions & 0 deletions tmt/plans/edge-test.fmf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ provision:
cpu:
processors: ">= 2"
memory: ">= 6 GB"
disk:
- size: ">= 15 GB"

/edge-x86-commit:
summary: Test edge commit
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -989,8 +989,8 @@ github.com/osbuild/images/pkg/rhsm
github.com/osbuild/images/pkg/rhsm/facts
github.com/osbuild/images/pkg/rpmmd
github.com/osbuild/images/pkg/runner
# github.com/osbuild/osbuild-composer/pkg/splunk_logger v0.0.0-20231117174845-e969a9dc3cd1
## explicit; go 1.19
# github.com/osbuild/osbuild-composer/pkg/splunk_logger v0.0.0-20240814102216-0239db53236d
## explicit; go 1.21
github.com/osbuild/osbuild-composer/pkg/splunk_logger
# github.com/osbuild/pulp-client v0.1.0
## explicit; go 1.19
Expand Down
Loading