-
Notifications
You must be signed in to change notification settings - Fork 148
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 logging to sriov-cni #276
Conversation
8ba3960
to
f2ea5fe
Compare
@mlguerrero12 @SchSeba Sorry for the random ping - would any of this here make sense? I'm currently working on a customer case and needed to build a debug image to troubleshoot a race condition, and debug logging would have been helpful to me |
@andreaskaris maybe use : https://github.com/k8snetworkplumbingwg/cni-log generally im +1 with adding logs to sriov-cni |
Will do, have a couple of improvements for k8snetworkplumbingwg/cni-log though |
@adrianchiris I submitted a few improvements for https://github.com/k8snetworkplumbingwg/cni-log |
Pull Request Test Coverage Report for Build 5516021612
💛 - Coveralls |
Done! lets get cni-log changes in first |
f2ea5fe
to
4388de4
Compare
b46c194
to
47510ee
Compare
@andreaskaris great to see this PR! I have a question if we put in debug but we leave the file empty will crio call still work? I need to test this one. |
47510ee
to
63b16aa
Compare
@SchSeba I have to admit that I don't follow exactly what you mean (my fault, not yours). Can you elaborate a bit more (rough reproducer / test steps) and I'll try it out? |
pkg/logging/logging.go
Outdated
cnilog.SetLogStderr(true) | ||
return | ||
} | ||
cnilog.SetLogStderr(false) |
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.
to remove and error message cni-log: filename is required when logging to stderr is off - will not log anything
please switch between this 2 lines
meaning first put the setLogFile and then the setLogStderr
One more comment can you please add to all the messages the so it will be easy to grep stuff if multiple cni calls or looking at the stderr that gets print in multus container |
63b16aa
to
3d9bd5f
Compare
287ce97
to
780f460
Compare
780f460
to
622649c
Compare
bce91df
to
73c4c4e
Compare
bb375e5
to
3f8d047
Compare
docs/configuration-reference.md
Outdated
@@ -17,6 +17,8 @@ The SR-IOV CNI configures networks through a CNI spec configuration object. In a | |||
* `min_tx_rate` (int, optional): change the allowed minimum transmit bandwidth, in Mbps, for the VF. Setting this to 0 disables rate limiting. The min_tx_rate value should be <= max_tx_rate. Support of this feature depends on NICs and drivers. | |||
* `max_tx_rate` (int, optional): change the allowed maximum transmit bandwidth, in Mbps, for the VF. | |||
Setting this to 0 disables rate limiting. | |||
* `loglevel` (string, optional): either of panic, error, warning, info, debug with a default of error. |
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.
why error and not info for the default value?
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.
Because I originally did not want to print any extra information by default with the introduction of the logging mechanism. That's also the reason why I set logging.Info("Cannot load config file from cache"). Let me switch it to Info
cmd/sriov/main.go
Outdated
@@ -202,6 +235,9 @@ func cmdDel(args *skel.CmdArgs) error { | |||
// Return nil when LoadConfFromCache fails since the rest | |||
// of cmdDel() code relies on netconf as input argument | |||
// and there is no meaning to continue. | |||
logging.Info("Cannot load config file from cache", |
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.
shouldn't it be error level?
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.
Because I originally did not want to print any extra information by default with the introduction of the logging mechanism. Let me change this though
pkg/types/types.go
Outdated
@@ -50,4 +50,6 @@ type NetConf struct { | |||
RuntimeConfig struct { | |||
Mac string `json:"mac,omitempty"` | |||
} `json:"runtimeConfig,omitempty"` | |||
LogLevel string `json:"loglevel,omitempty"` |
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.
let's use logLevel or log_level to be consistent with other parameters
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.
logLevel / logFile it is
cmd/sriov/main.go
Outdated
@@ -43,6 +44,18 @@ func getEnvArgs(envArgsString string) (*envArgs, error) { | |||
} | |||
|
|||
func cmdAdd(args *skel.CmdArgs) error { | |||
// Set logging related info. The default log level is error, hence also do logging.Debug inside the block. | |||
if logLevel, logFile, err := config.LoadLoggingConf(args.StdinData); 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.
I think it's better to create a function to setup the logging. It could be created in config.go. Of course, the debug log should be the only one that remains in cmdAdd and cmdDel.
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.
perhaps, you should only set the logLevel and logFile when these are not ""
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.
I prefer functions be omnipotent though and not rely too much on the defaults of the underlying library
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.
fair
pkg/logging/logging.go
Outdated
|
||
func init() { | ||
SetLogFile("") | ||
SetLogLevel("") |
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.
init of cni-log pkg calls initloger which already sets empty file and enalbe stderr. So, no need to have it here again. If you decide to set error as log level (instead of info as set by cni-log, see comment above). I think this should be the place.
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.
I removed init() altogether
|
||
// SetLogFile sets the log file for logging. If the empty string is provided, it uses stderr. | ||
func SetLogFile(fileName string) { | ||
if fileName == "" { |
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.
no needed if you remove it from init and set in main.go only if it is not empty.
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.
if you set the default level in init, then you can do:
if ll:= cnilog.StringToLevel(l), ll != cnilog.InvalidLevel {
cnilog.SetLogLevel(ll)
}
return | ||
} | ||
cnilog.SetLogFile(fileName) | ||
cnilog.SetLogStderr(false) |
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.
so, is it exclusive? only file or only stderr, but not both?
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.
yeah that was my idea to have an "either log to file or log to stderr". The other model would be: "log to stderr and optionally log to file as well" .. or yet another option would be to expose the stderr switch to users as well and have 3 options. But I find the either/or one most intuitive. That said, I'm open to changing it if you strongly favor something else
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.
No, it's fine like it is. Just wanted to check if it was really intended.
3f8d047
to
940ac44
Compare
@mlguerrero12 I made a few changes, taking into consideration your comments. I know I didn't address all of your comments but I'd prefer not to rely too much on the underlying cni-log defaults. Lmk what you think, I'm happy to revert/address further comments :-) |
pkg/config/config.go
Outdated
@@ -16,6 +17,22 @@ var ( | |||
DefaultCNIDir = "/var/lib/cni/sriov" | |||
) | |||
|
|||
// SetLogging sets global logging parameters. | |||
func SetLogging(stdinData []byte, containerID, netns, ifName string) { | |||
if logLevel, logFile, err := loadLoggingConf(stdinData); 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.
I think that this is a valid error. If we are not able to unmarshall it, the plugin should return an error. What do you think?
Also, no need to have 2 separate functions. You can embed loadLoggingConf here. It's fine if you prefer to it separated.
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.
ok to both
pkg/logging/logging.go
Outdated
|
||
// Init initializes logging with the requested parameters. | ||
func Init(logLevel, logFile, containerID, netns, ifName string) { | ||
SetLogLevel(logLevel) |
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.
Let's not export the setters anymore. They are only used in this package. Also, let's remove the setters for continaerid, netns and ifname.
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.
done
940ac44
to
a989652
Compare
thank you @andreaskaris. LGTM |
@zeeke can you have a look? Thanks! |
@adrianchiris or @Eoghan1232 as well (I was just informed that I need approval from another company, as well) - thanks :) |
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.
Left a minor comment, not blocking the PR for that.
LGTM
a989652
to
63c097b
Compare
Makefile
Outdated
@@ -14,6 +14,7 @@ BASE=$(GOPATH)/src/$(REPO_PATH) | |||
GOFILES = $(shell find . -name *.go | grep -vE "(\/vendor\/)|(_test.go)") | |||
PKGS = $(or $(PKG),$(shell cd $(BASE) && env GOPATH=$(GOPATH) $(GO) list ./... | grep -v "^$(PACKAGE)/vendor/")) | |||
TESTPKGS = $(shell env GOPATH=$(GOPATH) $(GO) list -f '{{ if or .TestGoFiles .XTestGoFiles }}{{ .ImportPath }}{{ end }}' $(PKGS)) | |||
CONTAINER_ENGINE ?= $(shell /bin/bash -c "if command -v podman &>/dev/null; then echo podman; else echo docker; fi") |
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.
IMAGE_BUILDER ?= docker
I would prefer something like this, check if the env var is set, if so, take the value, otherwise default.
I would prefer docker to be the default as well.
WDYT?
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.
done: fdbccf1
Provide a way to choose the container engine with IMAGE_BUILDER var. Signed-off-by: Andreas Karis <ak.karis@gmail.com>
Signed-off-by: Andreas Karis <ak.karis@gmail.com>
Signed-off-by: Andreas Karis <ak.karis@gmail.com>
63c097b
to
f996a66
Compare
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.
LGTM!
@zeeke are we good to merge? |
Adds both configurable debug logging to stderr and optionally to
file as well as error logging for issue 275.
Reported-at: #275
Signed-off-by: Andreas Karis ak.karis@gmail.com