canonical / edgex-snap-hooks Goto Github PK
View Code? Open in Web Editor NEWSnap hooks library for EdgeX snaps.
License: Apache License 2.0
Snap hooks library for EdgeX snaps.
License: Apache License 2.0
Version: 2.0.3
The MessageQueue configuration overrides currently are only supported for core-data and device-virtual. In fact, these should be usable for any device service using edgex-snap-hooks, not just device-virtual.
Several tests in top-level, snapctl, options packages set snap options during the tests. These should removed using snapctl unset
after the tests.
Removing them using snap unset
from outside is not possible because the snap has no configure hook. The current workaround is to re-install the snap or enter the shell environment and use snapctl unset
to remove them.
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
.github/workflows/issues-to-jira.yml
.github/workflows/test.yml
actions/checkout v3
whywaita/setup-lxd v1
ubuntu 20.04
go.mod
github.com/stretchr/testify v1.8.4
go 1.18
The current logging functions take string as input. It would be useful to add corresponding functions (Debugf, Errorf, Infof, Warnf) to accept string formats in a similar fashion to fmt.Printf
.
Example code that can be simplified:
https://github.com/edgexfoundry/edgex-go/blob/3acce916edd26c48cc534c43f5f6a7ed858771e5/snap/local/hooks/cmd/configure/configure.go#L552
Moreover, the existing functions can be changed to accept one or more interfaces, instead of just one string. See fmt.Print
.
This code skips the validation part (lines 113-116) because only the service that is passed to function is read from the map (line 136) and processed:
edgex-snap-hooks/options/options.go
Lines 111 to 149 in 75c92f7
Upstream changes:
Tests:
The following snap options are affected:
The env files created for app options, are not removed after disabling app options. They will get replaced however as soon an an env option is set.
set app, unset apps, does not work:
$ sudo snap set edgex-device-mqtt apps.device-mqtt.config.service.port=1111
$ sudo snap restart edgex-device-mqtt.device-mqtt
$ sudo snap unset edgex-device-mqtt apps.device-mqtt.config.service.port
$ sudo snap restart edgex-device-mqtt.device-mqtt
$ snap get edgex-device-mqtt -d
{
"apps": {
"device-mqtt": {
"config": {
"service": {
"port": 1111
}
}
}
}
}
$ journalctl -f | grep device-mqtt |grep "Web server starting"
msg="Web server starting (localhost:1111)"
set app, unset apps and config, work as expected:
$ sudo snap set edgex-device-mqtt apps.device-mqtt.config.service.port=1111
$ sudo snap restart edgex-device-mqtt.device-mqtt
$ sudo snap unset edgex-device-mqtt apps.device-mqtt.config.service.port
$ sudo snap unset edgex-device-mqtt config.service.port
$ sudo snap restart edgex-device-mqtt.device-mqtt
$ snap get edgex-device-mqtt -d
{}
$ journalctl -f | grep device-mqtt |grep "Web server starting"
msg="Web server starting (localhost:59982)" <----------------------------------------default service port
See more details in this PR
The library creates the env file for environment variables even when no snap options are set that lead to environment variable assignments.
Lines 130 to 133 in e9c2f94
Not all error logs are returned to the caller.
For example, an erroneous config set returns the following only: exit status 1
There may be more information returned in stdout and stderr by snapctl which the functions don't return.
Errors do get written to journals but those are invisible to the caller and need to be queried separately.
This utility functions are used by other other applications for various logging messages. E.g. by device-camera for install hook errors.
Line 184 in 5c9f465
The prefix is misleading in logs. I suggest replacing with e.g. edgex-snap-hooks
to be consistent with other EdgeX journals.
See #81 (comment)
$ snap set edgex-app-service-configurable config.service-startupmsg="testing injection"
$ snap set edgex-app-service-configurable apps.app-service-configurable.config.service-port=11111
$ cat /var/snap/edgex-app-service-configurable/current/config/res/app-service-configurable.env
export SERVICE_STARTUPMSG="testing injection"
export SERVICE_PORT="11111"
$ snap set edgex-app-service-configurable apps.app-service-configurable.config.service.port=11111
error: cannot perform the following tasks:
- Run configure hook of "edgex-app-service-configurable" snap (run hook "configure": edgex-app-service-configurable.configure: could not process options: error converting config key to environment variable key: config key must not contain dots: service.port)
$ cat /var/snap/edgex-app-service-configurable/current/config/res/app-service-configurable.env
export SERVICE_STARTUPMSG="testing injection"
The config keys can include dot or hyphen as separator. The use of dot allow setting complex keys with parent-child relationship. This is sometimes useful, e.g. for service.port, but confusing when mixed with hyphen-separated keys with map to the same underlying environment variable.
The new options package (v2.2.0-beta.2) tries to be backwards compatible by appending to pre-existing env files. This makes it impossible to replace or remove env variables from the env files; See edgexfoundry/edgex-go#3924 (review)
The configure hook writes the temp file in a directory that is created using the install hook when deploying config files to snap data. If the install hook doesn't perform that, the configure hook fails with error:
snap install --dangerous ./edgex-device-usb-camera_0.0.1-dev.5_amd64.snap
error: cannot perform the following tasks:
- Run configure hook of "edgex-device-usb-camera" snap if present (run hook "configure": edgex-device-usb-camera.configure: could not process options: failed to write /var/snap/edgex-device-usb-camera/x2/config/device-usb-camera/res/device-usb-camera.env.tmp - open /var/snap/edgex-device-usb-camera/x2/config/device-usb-camera/res/device-usb-camera.env.tmp: no such file or directory)
The configure hook should add the logic to create the necessary directory structure before attempting to write this file or any other.
Workaround using install hook:
This is useful for copying all profiles or devices in the install hook (example).
We already have CopyFile
. The new function name could be CopyDir
.
The env files created by the edgex-snap-hooks library (see here) use the .env extension which is for the dotenv format. However, they are treated as bash scripts and include export commands. The export is expected by the consumer, because the snaps source the file as a bash script (example). The dotenv format is a de-facto standard and is not bash. The exporting should happen outside when the env file is being loaded.
References:
The env files are currently bash files, e.g.:
service.env
:
export X=1
export Y=2
However, it should be:
X=1
X=2
edgex-snap-hooks/options/options.go
Line 128 in 0013103
Rename to options.ProcessAppConfig
such that it only handles apps.<app>.config.*
and config.*
.
For unset
a non-existing option, snap will set
the option with an empty value instead of clearing the existing value. Here is the detail:
$ snap get edgex-device-mqtt -d
{}
$ sudo snap unset edgex-device-mqtt config.service.port
$ snap get edgex-device-mqtt -d
{
"config": {
"service": {}
}
}
Once released, the module needs to be upgraded for the following:
CHECK THE BOX WHEN MERGED
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.