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 logging to sriov-cni #276

Merged
merged 3 commits into from
Oct 11, 2023
Merged

Conversation

andreaskaris
Copy link
Contributor

@andreaskaris andreaskaris commented Jul 11, 2023

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 [email protected]

@andreaskaris andreaskaris force-pushed the add-logging branch 6 times, most recently from 8ba3960 to f2ea5fe Compare July 11, 2023 05:06
@andreaskaris
Copy link
Contributor Author

@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

@adrianchiris
Copy link
Contributor

@andreaskaris maybe use : https://github.com/k8snetworkplumbingwg/cni-log

generally im +1 with adding logs to sriov-cni

@andreaskaris
Copy link
Contributor Author

Will do, have a couple of improvements for k8snetworkplumbingwg/cni-log though

@andreaskaris
Copy link
Contributor Author

andreaskaris commented Jul 15, 2023

@adrianchiris I submitted a few improvements for https://github.com/k8snetworkplumbingwg/cni-log
It'd be great if you could have a look before I continue work on this one here! Thanks!

k8snetworkplumbingwg/cni-log#13

@coveralls
Copy link

Pull Request Test Coverage Report for Build 5516021612

  • 65 of 100 (65.0%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+1.9%) to 40.78%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pkg/config/config.go 5 11 45.45%
pkg/logging/logging.go 12 41 29.27%
Totals Coverage Status
Change from base Build 5442888333: 1.9%
Covered Lines: 502
Relevant Lines: 1231

💛 - Coveralls

@adrianchiris
Copy link
Contributor

@adrianchiris I submitted a few improvements for https://github.com/k8snetworkplumbingwg/cni-log
It'd be great if you could have a look before I continue work on this one here! Thanks!

Done! lets get cni-log changes in first

pkg/logging/logging.go Outdated Show resolved Hide resolved
@SchSeba
Copy link
Collaborator

SchSeba commented Aug 1, 2023

@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.
because I try one time to use fmt.print and that mess with the return to crio

@andreaskaris andreaskaris marked this pull request as ready for review August 24, 2023 13:11
@andreaskaris
Copy link
Contributor Author

@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. because I try one time to use fmt.print and that mess with the return to crio

@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?

cnilog.SetLogStderr(true)
return
}
cnilog.SetLogStderr(false)
Copy link
Collaborator

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

@SchSeba
Copy link
Collaborator

SchSeba commented Sep 12, 2023

One more comment can you please add to all the messages the cni name or something like that and also ContainerID, Netns

so it will be easy to grep stuff if multiple cni calls or looking at the stderr that gets print in multus container

@andreaskaris andreaskaris force-pushed the add-logging branch 4 times, most recently from bb375e5 to 3f8d047 Compare September 26, 2023 14:55
@@ -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.
Copy link
Contributor

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?

Copy link
Contributor Author

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

@@ -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",
Copy link
Contributor

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?

Copy link
Contributor Author

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

@@ -50,4 +50,6 @@ type NetConf struct {
RuntimeConfig struct {
Mac string `json:"mac,omitempty"`
} `json:"runtimeConfig,omitempty"`
LogLevel string `json:"loglevel,omitempty"`
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logLevel / logFile it is

@@ -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 {
Copy link
Contributor

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.

Copy link
Contributor

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 ""

Copy link
Contributor Author

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair


func init() {
SetLogFile("")
SetLogLevel("")
Copy link
Contributor

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.

Copy link
Contributor Author

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 == "" {
Copy link
Contributor

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.

Copy link
Contributor

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)
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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.

@andreaskaris
Copy link
Contributor Author

@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 :-)

@@ -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 {
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok to both


// Init initializes logging with the requested parameters.
func Init(logLevel, logFile, containerID, netns, ifName string) {
SetLogLevel(logLevel)
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@mlguerrero12
Copy link
Contributor

thank you @andreaskaris.

LGTM

@andreaskaris
Copy link
Contributor Author

@zeeke can you have a look? Thanks!

@andreaskaris
Copy link
Contributor Author

@adrianchiris or @Eoghan1232 as well (I was just informed that I need approval from another company, as well) - thanks :)

Copy link
Member

@zeeke zeeke left a 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

pkg/logging/logging.go Outdated Show resolved Hide resolved
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")
Copy link
Collaborator

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?

Copy link
Contributor Author

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 <[email protected]>
Signed-off-by: Andreas Karis <[email protected]>
Copy link
Collaborator

@Eoghan1232 Eoghan1232 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@Eoghan1232
Copy link
Collaborator

@zeeke are we good to merge?

@zeeke zeeke merged commit 1bf2f23 into k8snetworkplumbingwg:master Oct 11, 2023
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants