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

tedge command for updating the service type #1798

Merged

Conversation

PradeepKiruvale
Copy link
Contributor

Proposed changes

This PR adds a feature to configure the service_type that is required for the service monitoring feature.

Set service type :

sudo tedge config set service.type <service-type> 
sudo tedge config unset service.type

The default value is service.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Improvement (general improvements like code refactoring that doesn't explicitly fix a bug or add any new functionality)
  • Documentation Update (if none of the other choices apply)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Paste Link to the issue

(#1769)

Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the CLA (in all commits with git commit -s)
  • I ran cargo fmt as mentioned in CODING_GUIDELINES
  • I used cargo clippy as mentioned in CODING_GUIDELINES
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Further comments

@reubenmiller
Copy link
Contributor

@PradeepKiruvale Can you please add a robot test to validate this functionality?

@reubenmiller reubenmiller added the theme:monitoring Theme: Service monitoring and watchdogs label Mar 9, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Mar 9, 2023

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass %
152 0 5 152 100

Passed Tests

Name ⏱️ Duration Suite
Define Child device 1 ID 0.047 s C8Y Child Alarms Rpi
Normal case when the child device does not exist on c8y cloud 2.569 s C8Y Child Alarms Rpi
Normal case when the child device already exists 1.114 s C8Y Child Alarms Rpi
Reconciliation when the new alarm message arrives, restart the mapper 1.6600000000000001 s C8Y Child Alarms Rpi
Reconciliation when the alarm that is cleared 6.314 s C8Y Child Alarms Rpi
Prerequisite Parent 17.731 s Child Conf Mgmt Plugin
Prerequisite Child 0.363 s Child Conf Mgmt Plugin
Child device bootstrapping 15.547 s Child Conf Mgmt Plugin
Snapshot from device 21.796 s Child Conf Mgmt Plugin
Child device config update 17.603 s Child Conf Mgmt Plugin
Configuration types should be detected on file change (without restarting service) 48.169 s Inotify Crate
Child devices support sending simple measurements 50.719 s Child Device Telemetry
Child devices support sending custom measurements 50.26 s Child Device Telemetry
Child devices support sending custom events 39.935 s Child Device Telemetry
Child devices support sending custom events overriding the type 46.209 s Child Device Telemetry
Child devices support sending custom alarms #1699 45.636 s Child Device Telemetry
Child devices support sending inventory data via c8y topic 24.676 s Child Device Telemetry
Main device support sending inventory data via c8y topic 23.939 s Child Device Telemetry
Successful firmware operation 66.089 s Firmware Operation
Install with empty firmware name 54.558 s Firmware Operation
Prerequisite Parent 19.864 s Firmware Operation Child Device
Prerequisite Child 8.01 s Firmware Operation Child Device
Child device firmware update 6.784 s Firmware Operation Child Device
Child device firmware update with cache 6.086 s Firmware Operation Child Device
Retrieve a JWT tokens 48.617 s Jwt Request
Supports restarting the device 75.964 s Restart Device
Update tedge version from previous using Cumulocity 95.619 s Tedge Self Update
Test if all c8y services are up 63.971 s Service Monitoring
Test if all c8y services are down 49.994 s Service Monitoring
Test if all c8y services are using configured service type 47.223 s Service Monitoring
Test if all c8y services using default service type when service type configured as empty 44.757 s Service Monitoring
Check health status of tedge-mapper-c8y service on broker restart 29.517 s Service Monitoring
Check health status of child device service 24.823 s Service Monitoring
Successful shell command with output 4.014 s Shell Operation
Check Successful shell command with literal double quotes output 3.384 s Shell Operation
Execute multiline shell command 3.291 s Shell Operation
Failed shell command 3.223 s Shell Operation
Software list should be populated during startup 54.319 s Software
Install software via Cumulocity 57.502 s Software
Software list should only show currently installed software and not candidates 39.577 s Software
Stop tedge-agent service 0.482 s Log Path Config
Customize the log path 0.309 s Log Path Config
Initialize tedge-agent 0.137 s Log Path Config
Check created folders 0.212 s Log Path Config
Remove created custom folders 0.203 s Log Path Config
Install thin-edge via apt 32.916 s Install Apt
Install latest via script (from current branch) 27.215 s Install Tedge
Install specific version via script (from current branch) 18.569 s Install Tedge
Install latest tedge via script (from main branch) 22.88 s Install Tedge
Support starting and stopping services 33.666 s Service-Control
Supports a reconnect 48.531 s Test-Commands
Supports disconnect then connect 38.256 s Test-Commands
Update unknown setting 36.185 s Test-Commands
Update known setting 26.958 s Test-Commands
Stop c8y-configuration-plugin 0.472 s Health C8Y-Configuration-Plugin
Update the service file 0.256 s Health C8Y-Configuration-Plugin
Reload systemd files 0.584 s Health C8Y-Configuration-Plugin
Start c8y-configuration-plugin 0.211 s Health C8Y-Configuration-Plugin
Start watchdog service 10.319 s Health C8Y-Configuration-Plugin
Check PID of c8y-configuration-plugin 0.126 s Health C8Y-Configuration-Plugin
Kill the PID 0.123 s Health C8Y-Configuration-Plugin
Recheck PID of c8y-configuration-plugin 2.143 s Health C8Y-Configuration-Plugin
Compare PID change 0.001 s Health C8Y-Configuration-Plugin
Stop watchdog service 0.071 s Health C8Y-Configuration-Plugin
Remove entry from service file 0.077 s Health C8Y-Configuration-Plugin
Stop c8y-log-plugin 0.21 s Health C8Y-Log-Plugin
Update the service file 0.154 s Health C8Y-Log-Plugin
Reload systemd files 0.485 s Health C8Y-Log-Plugin
Start c8y-log-plugin 0.132 s Health C8Y-Log-Plugin
Start watchdog service 10.178 s Health C8Y-Log-Plugin
Check PID of c8y-log-plugin 0.092 s Health C8Y-Log-Plugin
Kill the PID 0.095 s Health C8Y-Log-Plugin
Recheck PID of c8y-log-plugin 2.155 s Health C8Y-Log-Plugin
Compare PID change 0.001 s Health C8Y-Log-Plugin
Stop watchdog service 0.08 s Health C8Y-Log-Plugin
Remove entry from service file 0.086 s Health C8Y-Log-Plugin
Stop tedge-mapper 0.112 s Health Tedge Mapper C8Y
Update the service file 0.1 s Health Tedge Mapper C8Y
Reload systemd files 0.551 s Health Tedge Mapper C8Y
Start tedge-mapper 0.112 s Health Tedge Mapper C8Y
Start watchdog service 10.14 s Health Tedge Mapper C8Y
Check PID of tedge-mapper 0.077 s Health Tedge Mapper C8Y
Kill the PID 0.069 s Health Tedge Mapper C8Y
Recheck PID of tedge-mapper 2.169 s Health Tedge Mapper C8Y
Compare PID change 0 s Health Tedge Mapper C8Y
Stop watchdog service 0.093 s Health Tedge Mapper C8Y
Remove entry from service file 0.111 s Health Tedge Mapper C8Y
Stop tedge-agent 0.137 s Health Tedge-Agent
Update the service file 0.077 s Health Tedge-Agent
Reload systemd files 0.152 s Health Tedge-Agent
Start tedge-agent 0.081 s Health Tedge-Agent
Start watchdog service 10.153 s Health Tedge-Agent
Check PID of tedge-mapper 0.132 s Health Tedge-Agent
Kill the PID 0.099 s Health Tedge-Agent
Recheck PID of tedge-agent 2.155 s Health Tedge-Agent
Compare PID change 0.001 s Health Tedge-Agent
Stop watchdog service 0.133 s Health Tedge-Agent
Remove entry from service file 0.1 s Health Tedge-Agent
Stop tedge-mapper-az 0.134 s Health Tedge-Mapper-Az
Update the service file 0.129 s Health Tedge-Mapper-Az
Reload systemd files 0.356 s Health Tedge-Mapper-Az
Start tedge-mapper-az 0.092 s Health Tedge-Mapper-Az
Start watchdog service 10.091 s Health Tedge-Mapper-Az
Check PID of tedge-mapper-az 0.104 s Health Tedge-Mapper-Az
Kill the PID 0.12 s Health Tedge-Mapper-Az
Recheck PID of tedge-agent 2.299 s Health Tedge-Mapper-Az
Compare PID change 0.001 s Health Tedge-Mapper-Az
Stop watchdog service 0.142 s Health Tedge-Mapper-Az
Remove entry from service file 0.108 s Health Tedge-Mapper-Az
Stop tedge-mapper-collectd 0.178 s Health Tedge-Mapper-Collectd
Update the service file 0.155 s Health Tedge-Mapper-Collectd
Reload systemd files 0.505 s Health Tedge-Mapper-Collectd
Start tedge-mapper-collectd 0.215 s Health Tedge-Mapper-Collectd
Start watchdog service 10.3 s Health Tedge-Mapper-Collectd
Check PID of tedge-mapper-collectd 0.139 s Health Tedge-Mapper-Collectd
Kill the PID 0.106 s Health Tedge-Mapper-Collectd
Recheck PID of tedge-mapper-collectd 2.239 s Health Tedge-Mapper-Collectd
Compare PID change 0.001 s Health Tedge-Mapper-Collectd
Stop watchdog service 0.095 s Health Tedge-Mapper-Collectd
Remove entry from service file 0.071 s Health Tedge-Mapper-Collectd
c8y-log-plugin health status 5.459 s MQTT health endpoints
c8y-configuration-plugin health status 5.393 s MQTT health endpoints
Wrong package name 0.196 s Improve Tedge Apt Plugin Error Messages
Wrong version 0.206 s Improve Tedge Apt Plugin Error Messages
Wrong type 0.412 s Improve Tedge Apt Plugin Error Messages
tedge_connect_test_positive 0.695 s Tedge Connect Test
tedge_connect_test_negative 1.031 s Tedge Connect Test
tedge_connect_test_sm_services 7.994 s Tedge Connect Test
tedge_disconnect_test_sm_services 1.33 s Tedge Connect Test
Install thin-edge.io 11.128 s Call Tedge
call tedge -V 0.064 s Call Tedge
call tedge -h 0.054 s Call Tedge
call tedge -h -V 0.051 s Call Tedge
call tedge help 0.054 s Call Tedge
tedge config list 0.053 s Call Tedge Config List
tedge config list --all 0.076 s Call Tedge Config List
set/unset device.type 0.312 s Call Tedge Config List
set/unset device.key.path 0.246 s Call Tedge Config List
set/unset device.cert.path 0.267 s Call Tedge Config List
set/unset c8y.root.cert.path 0.262 s Call Tedge Config List
set/unset c8y.smartrest.templates 0.268 s Call Tedge Config List
set/unset az.root.cert.path 0.255 s Call Tedge Config List
set/unset az.mapper.timestamp 0.229 s Call Tedge Config List
set/unset mqtt.bind_address 0.253 s Call Tedge Config List
set/unset mqtt.port 0.238 s Call Tedge Config List
set/unset tmp.path 0.385 s Call Tedge Config List
set/unset logs.path 0.261 s Call Tedge Config List
set/unset run.path 0.232 s Call Tedge Config List
Get Put Delete 3.589 s Http File Transfer Api
Set keys should return value on stdout 0.155 s Tedge Config Get
Unset keys should not return anything on stdout and warnings on stderr 0.227 s Tedge Config Get
Invalid keys should not return anything on stdout and warnings on stderr 0.314 s Tedge Config Get

@reubenmiller
Copy link
Contributor

@PradeepKiruvale I looked into the test failures and it seems that the setting that was added is mandatory (when it should be optional). It is important that if we add new configuration settings (sections or keys), it must be optional, as we don't want to break any existing configuration files out there (e.g. the classic upgrade scenario).

I came to this conclusion based on the following log entries found in the last test run (pulled from the mapper logs)

Mar 09 13:56:46 3382816a725e tedge-mapper[956]: Error: A value for `service.type` is missing.
Mar 09 13:56:46 3382816a725e tedge-mapper[956]:     A value can be set with `tedge config set service.type <value>`

@@ -469,3 +469,16 @@ impl ConfigSetting for FirmwareChildUpdateTimeoutSetting {

type Value = Seconds;
}

pub struct ServiceSetting;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
pub struct ServiceSetting;
pub struct ServiceTypeSetting;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -118,6 +121,7 @@ impl From<&TEdgeConfigLocation> for TEdgeConfigDefaults {
default_firmware_child_update_timeout: Seconds(
DEFAULT_FIRMWARE_CHILD_UPDATE_TIMEOUT_SEC,
),
default_service_type: "service".into(),
Copy link
Contributor

Choose a reason for hiding this comment

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

You could just define this as a constant and reuse it here and in all tests.

pub fn convert_health_status_message(
message: &Message,
device_name: String,
service_type: String,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
service_type: String,
default_service_type: String,

Just to be clearer as I was really struggling to follow the code below with the combination of service_type, health_status.service_type and s_type in the same context ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -908,6 +908,7 @@ fn dummy_tedge_config_defaults() -> TEdgeConfigDefaults {
default_http_bind_address: IpAddress(IpAddr::V4(Ipv4Addr::LOCALHOST)),
default_c8y_smartrest_templates: TemplatesSet::default(),
default_firmware_child_update_timeout: Seconds(3600),
default_service_type: String::from("service"),
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Update some existing tests like test_parse_config_empty_file, test_parse_config_with_all_values and test_store_config_with_all_values to verify the effects of this new setting.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

@PradeepKiruvale
Copy link
Contributor Author

@PradeepKiruvale I looked into the test failures and it seems that the setting that was added is mandatory (when it should be optional). It is important that if we add new configuration settings (sections or keys), it must be optional, as we don't want to break any existing configuration files out there (e.g. the classic upgrade scenario).

I came to this conclusion based on the following log entries found in the last test run (pulled from the mapper logs)

Mar 09 13:56:46 3382816a725e tedge-mapper[956]: Error: A value for `service.type` is missing.
Mar 09 13:56:46 3382816a725e tedge-mapper[956]:     A value can be set with `tedge config set service.type <value>`

Fixed by adding a default value.

@PradeepKiruvale PradeepKiruvale temporarily deployed to Test Pull Request March 10, 2023 16:28 — with GitHub Actions Inactive
@@ -573,7 +581,7 @@ fn test_parse_config_empty_file() -> Result<(), TEdgeConfigError> {
default_azure_root_cert_path: FilePath::from("/etc/ssl/certs"),
..dummy_tedge_config_defaults()
};

dbg!(&config_defaults);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
dbg!(&config_defaults);

@@ -146,3 +149,9 @@ pub(crate) struct PathConfigDto {
pub(crate) struct FirmwareConfigDto {
pub(crate) child_update_timeout: Option<u64>,
}

#[derive(Debug, Default, Deserialize, Serialize)]
pub(crate) struct ServiceConfigDto {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
pub(crate) struct ServiceConfigDto {
pub(crate) struct ServiceTypeConfigDto {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@PradeepKiruvale PradeepKiruvale temporarily deployed to Test Pull Request March 13, 2023 11:45 — with GitHub Actions Inactive
@didier-wenzek
Copy link
Contributor

Yet another PR that convince me that something is terribly wrong with tegde_config. So many code changes to add a single setting!

Copy link
Contributor

@albinsuresh albinsuresh left a comment

Choose a reason for hiding this comment

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

The rust code looks good. But I'm not fully convinced with the test structure. Can @reubenmiller or @gligorisaev review the integration test and confirm if it's fine?

@@ -31,6 +31,15 @@ Test if all c8y services are down
c8y-configuration-plugin
c8y-log-plugin


Test if all c8y services are using configured service type
[Template] Check if a service using configured service type
Copy link
Contributor

Choose a reason for hiding this comment

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

This test is probably okay but structure of this test looks problematic. This Check if a service using configured service type performs the tedge config set and tedge reconnect as part of this keyword and those commands will be called repeatedly for each service name argument that is passed to it(tedge-mapper-c8y, tedge-agent etc). That would unnecessarily call tedge reconnect for each service which is completely unnecessary, right? Why not do the tedge config set and tedge reconnect once as part of the test itself and then call the template that validates the service type for each input?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The tedge reconnect is not needed here, just restarting the tedge-mapper-c8y is enough to pick up the service type config that is configured. I have updated the test.

Since the template pattern is used here, there is a restriction to call the custom test settings before starting these tests at once.

tedge-mapper-c8y
tedge-agent
c8y-configuration-plugin
c8y-log-plugin
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
c8y-log-plugin
c8y-log-plugin
c8y-firmware-plugin

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@PradeepKiruvale PradeepKiruvale temporarily deployed to Test Pull Request March 14, 2023 14:13 — with GitHub Actions Inactive
Copy link
Member

@rina23q rina23q left a comment

Choose a reason for hiding this comment

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

Having a couple of questions.

@PradeepKiruvale PradeepKiruvale temporarily deployed to Test Pull Request March 15, 2023 12:03 — with GitHub Actions Inactive
@PradeepKiruvale PradeepKiruvale temporarily deployed to Test Pull Request March 15, 2023 15:09 — with GitHub Actions Inactive
c8y-log-plugin
c8y-firmware-plugin

Test if all c8y services when service type configured as empty
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Test if all c8y services when service type configured as empty
Test if all c8y services using default service type when service type configured as empty

fn default_status() -> String {
"unknown".to_string()
}

fn default_type() -> String {
"".to_string()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"".to_string()
DEFAULT_SERVICE_TYPE.to_string()

This seems more appropriate even though I understand that the parsing logic below will convert this empty string to the default type anyway.

Some(_) => {}
if health_status.service_type.is_empty() {
health_status.service_type = if default_service_type.is_empty() {
"service".to_owned()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"service".to_owned()
DEFAULT_SERVICE_TYPE.to_string()

Copy link
Member

@rina23q rina23q left a comment

Choose a reason for hiding this comment

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

Only minor things left.

crates/core/tedge_mapper/src/c8y/service_monitor.rs Outdated Show resolved Hide resolved
crates/core/tedge_mapper/src/c8y/service_monitor.rs Outdated Show resolved Hide resolved
crates/core/tedge_mapper/src/c8y/service_monitor.rs Outdated Show resolved Hide resolved
@PradeepKiruvale PradeepKiruvale temporarily deployed to Test Pull Request March 16, 2023 14:09 — with GitHub Actions Inactive

The `default service type` can be configured using the `tedge` cli.

Below example shows how one can set the `service-type` to `systemd`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Below example shows how one can set the `service-type` to `systemd`.
The example below shows how one can set the default service type to `systemd`.

> Note: When the `service type` was not sent with the `health status` message, then the configured default value will be used by
the mapper while translating the `health status` message to `service status` message.

To clear the configured default service type one can use the below command.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
To clear the configured default service type one can use the below command.
To clear the configured default service type one can use the command below.

Signed-off-by: Pradeep Kumar K J <pradeepkumar.kj@softwareag.com>
@PradeepKiruvale PradeepKiruvale temporarily deployed to Test Pull Request March 16, 2023 14:45 — with GitHub Actions Inactive
@PradeepKiruvale PradeepKiruvale merged commit 56f1045 into thin-edge:main Mar 16, 2023
didier-wenzek pushed a commit to didier-wenzek/thin-edge.io that referenced this pull request Mar 21, 2023
Signed-off-by: Pradeep Kumar K J <pradeepkumar.kj@softwareag.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme:monitoring Theme: Service monitoring and watchdogs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants