Skip to content

Capture run time of plugins; Allow overriding default log values via env#27

Merged
abhijithda merged 1 commit intov1from
abhijithda-patch-1
Nov 1, 2024
Merged

Capture run time of plugins; Allow overriding default log values via env#27
abhijithda merged 1 commit intov1from
abhijithda-patch-1

Conversation

@abhijithda
Copy link
Member

@abhijithda abhijithda commented Oct 23, 2024

Support specifying log dir and log file values via env in case if pm doesn't have permissions to write on /var/log dir.
Capture run time of plugins
List file names in case of gofmt errors

Testing

Support env vars PM_LOG_DIR and PM_LOG_FILE to set log location

Support env vars PM_LOG_DIR and PM_LOG_FILE to set log location so that running tests where pm doesn't have permissions to write log into /var/log/ dir doesn't fail.

Before

No permissions

Failed to initialize file logger [&errors.errorString{s:"os.MkdirAll(/var/log/asum) failed"}].
FAIL	github.com/VeritasOS/plugin-manager/cmd/pm	0.010s

With permissions

If permissions were present, it used to write to default log first before switching to specified log.

bash-5.1$ $GOBIN/pm run -type postreboot -library=sample/library/ -log-dir=testlogs/ -log-file=test.log
Log: /var/log/asum/pm.2024-10-28T17:58:34.873372791-05:00.log
Failed to read "/opt/veritas/appliance/asum/pm.config.yaml" file.
Failed to load config file. Using default values and proceeding with the operation
Log: testlogs/test.2024-10-28T17:58:34.873827-05:00.log
Validating "A's" configuration: Starting
Validating "A's" configuration: Succeeded
Running postreboot plugins: Succeeded
bash-5.1$ 

Setting log path via ENV

With ENV variable support, the default log dir and file can be overridden as well.

bash-5.1$ export PM_LOG_DIR=testlogs
bash-5.1$ export PM_LOG_FILE=test.log
bash-5.1$ $GOBIN/pm run -type postreboot -library=sample/library/ -log-dir=testlogs/ -log-file=test.log -output-format yaml -output-file ./tmp/ab.yaml
Log: testlogs/test.2024-10-28T18:05:05.943450532-05:00.log
Failed to read "/opt/veritas/appliance/asum/pm.config.yaml" file.
Failed to load config file. Using default values and proceeding with the operation
Validating "A's" configuration: Starting
Validating "A's" configuration: Succeeded
Running postreboot plugins: Succeeded
bash-5.1$

Run time is now captured in the json/yaml files specified

# cat ./tmp/ab.yaml 
name: postreboot
description: ""
requiredby: []
requires: []
execstart: ""
plugins:
    - name: A/a.postreboot
      description: Validating "A's" configuration
      requiredby: []
      requires: []
      execstart: /bin/echo "Validating A's configuration..."
      plugins: []
      library: ""
      runtime:
        starttime: 2024-10-28T18:05:05.966080557-05:00
        endtime: 2024-10-28T18:05:06.018026239-05:00
        duration: 51.945647ms
      status: Succeeded
      stdouterr:
        - '"Validating A''s configuration..."'
library: ""
runtime:
    starttime: 2024-10-28T18:05:05.943925584-05:00
    endtime: 2024-10-28T18:05:06.018055306-05:00
    duration: 74.129739ms
status: Succeeded
stdouterr: []
bash-5.1$ 

List file names in case of gofmt errors

[abhijith@vraadarh92691 asum]$ make analyze
$C_SECURITY_FLAGS is [-s -w -fpie -pie -O2 -D_FORTIFY_SOURCE=2 -fstack-protector-all -Wl,-z,relro,-z,now]
Checking Go code for format errors...
gofmt must be run on the following files:
software-update-manager/repo/add.go
software-update-manager/repo/remove.go
software-update-manager/repo/remove_test.go
software-update-manager/repo/repo.go
software-update-manager/utils/rpm/rpm.go
software-update-manager/utils/rpm/rpm_test.go
software-update-manager/validate/version/version.go
make: *** [Makefile:159: gofmt] Error 1
[abhijith@vraadarh92691 asum]$ 

@abhijithda abhijithda changed the title Create default log dir Capture run time of plugins; Allow overriding default log values via env Nov 1, 2024
@abhijithda abhijithda merged commit f5a3a79 into v1 Nov 1, 2024
@abhijithda abhijithda deleted the abhijithda-patch-1 branch November 1, 2024 19:26
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.

1 participant