-
Notifications
You must be signed in to change notification settings - Fork 107
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
cloudapi: git sha version api and journal for workers #4484
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
exclude-dirs: | ||
- vendor | ||
|
||
linters-settings: | ||
govet: | ||
disable: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ import ( | |
"errors" | ||
"flag" | ||
"fmt" | ||
"io" | ||
"log" | ||
"net/url" | ||
"os" | ||
"path" | ||
|
@@ -17,11 +19,13 @@ import ( | |
slogger "github.com/osbuild/osbuild-composer/pkg/splunk_logger" | ||
|
||
"github.com/BurntSushi/toml" | ||
"github.com/coreos/go-systemd/journal" | ||
"github.com/sirupsen/logrus" | ||
|
||
"github.com/osbuild/images/pkg/arch" | ||
"github.com/osbuild/images/pkg/dnfjson" | ||
"github.com/osbuild/osbuild-composer/internal/cloud/awscloud" | ||
"github.com/osbuild/osbuild-composer/internal/common" | ||
"github.com/osbuild/osbuild-composer/internal/upload/azure" | ||
"github.com/osbuild/osbuild-composer/internal/upload/koji" | ||
"github.com/osbuild/osbuild-composer/internal/upload/oci" | ||
|
@@ -168,6 +172,11 @@ func RequestAndRunJob(client *worker.Client, acceptedJobTypes []string, jobImpls | |
} | ||
|
||
var run = func() { | ||
// Redirect Go standard logger into logrus before it's used by other packages | ||
log.SetOutput(common.Logger()) | ||
// Ensure the Go standard logger does not have any prefix or timestamp | ||
log.SetFlags(0) | ||
|
||
var unix bool | ||
flag.BoolVar(&unix, "unix", false, "Interpret 'address' as a path to a unix domain socket instead of a network address") | ||
|
||
|
@@ -189,6 +198,39 @@ var run = func() { | |
logrus.Fatalf("Could not load config file '%s': %v", configFile, err) | ||
} | ||
|
||
logrus.SetReportCaller(true) | ||
logrus.AddHook(&common.BuildHook{}) | ||
logrus.SetOutput(os.Stdout) | ||
logLevel, err := logrus.ParseLevel(config.Logging.Level) | ||
if err != nil { | ||
logrus.Info("Failed to load loglevel from config:", err) | ||
} else { | ||
logrus.SetLevel(logLevel) | ||
} | ||
|
||
// logger configuration | ||
switch config.Logging.Format { | ||
case "journal", "": | ||
// If we are running under systemd, use the journal. Otherwise, | ||
// fallback to text formatter. | ||
if journal.Enabled() { | ||
logrus.Info("Switching to journal logging mode, use logging.no_discard to keep writing to standard output/error") | ||
logrus.SetFormatter(&logrus.JSONFormatter{}) | ||
logrus.AddHook(&common.JournalHook{}) | ||
if !config.Logging.NoDiscard { | ||
logrus.SetOutput(io.Discard) | ||
} | ||
} else { | ||
logrus.SetFormatter(&logrus.TextFormatter{}) | ||
} | ||
case "text": | ||
logrus.SetFormatter(&logrus.TextFormatter{}) | ||
case "json": | ||
logrus.SetFormatter(&logrus.JSONFormatter{}) | ||
default: | ||
logrus.Infof("Failed to set logging format from config, '%s' is not a valid option", config.Logging.Format) | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI this was copy-pasted from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it make sense to have some common logging setup function to actually benefit from having both composer and worker in the same repo? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would say no, these are completely different binaries, separated by design. Little bit of copying is sometimes better than a dependency. |
||
logrus.Info("Composer configuration:") | ||
encoder := toml.NewEncoder(logrus.StandardLogger().WriterLevel(logrus.InfoLevel)) | ||
err = encoder.Encode(&config) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,19 @@ func (b binder) Bind(i interface{}, ctx echo.Context) error { | |
return nil | ||
} | ||
|
||
func (h *apiHandlers) GetVersion(ctx echo.Context) error { | ||
spec, err := GetSwagger() | ||
if err != nil { | ||
return HTTPError(ErrorFailedToLoadOpenAPISpec) | ||
} | ||
version := Version{ | ||
Version: spec.Info.Version, | ||
BuildCommit: common.ToPtr(common.BuildCommit), | ||
BuildTime: common.ToPtr(common.BuildTime), | ||
} | ||
return ctx.JSON(http.StatusOK, version) | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have the very same code in image-builder too, this is a copy-paste literally. |
||
func (h *apiHandlers) GetOpenapi(ctx echo.Context) error { | ||
spec, err := GetSwagger() | ||
if err != nil { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For full transparency, I sneaked this hunk in with the last amend, I realized that go linter lints also vendor directories and that slows it significantly. Can do a separate PR if requested.