Skip to content

feat: Add predictive maintenance example using DMI and edge AI#168

Open
darshankerkar wants to merge 4 commits into
kubeedge:masterfrom
darshankerkar:feat/predictive-maintenance-example
Open

feat: Add predictive maintenance example using DMI and edge AI#168
darshankerkar wants to merge 4 commits into
kubeedge:masterfrom
darshankerkar:feat/predictive-maintenance-example

Conversation

@darshankerkar
Copy link
Copy Markdown

What type of PR is this?
/kind feature

What this PR does / why we need it:
Hello everyone! This PR introduces a complete, end to end example of Predictive Maintenance at the edge to showcase Embodied Intelligence use cases using KubeEdge.

While working with the framework, I realized it would be highly beneficial to have a comprehensive demo showing how edge AI can operate autonomously. This example covers:

  • Collecting data via a virtual sensor Mapper (handling vibration and temperature)
  • Performing offline Edge AI inference using a lightweight Z score anomaly detector
  • Reporting inference results back to the cloud using DMI ReportDeviceStatus gRPC calls
  • Demonstrating edge autonomy where the mapper continues detecting anomalies during network disconnects, and EdgeCore flawlessly syncs the state once the connection is restored.

Everything is self contained with CRDs, deployment manifests, unit tests, and a detailed README to help new users and contributors get started easily.

Which issue(s) this PR fixes:
None directly (standalone example).

Special notes for your reviewer:
I have verified that the module path is correctly scoped to the examples repository and the API dependency points to a valid pseudo version so it builds successfully standalone without interfering with the main project directory. Looking forward to any feedback!

@kubeedge-bot kubeedge-bot added the kind/feature Categorizes issue or PR as related to a new feature. label May 10, 2026
@kubeedge-bot
Copy link
Copy Markdown
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: darshankerkar
To complete the pull request process, please assign kevin-wangzefeng after the PR has been reviewed.
You can assign the PR to them by writing /assign @kevin-wangzefeng in a comment when ready.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubeedge-bot
Copy link
Copy Markdown
Collaborator

Welcome @darshankerkar! It looks like this is your first PR to kubeedge/examples 🎉

@kubeedge-bot kubeedge-bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label May 10, 2026
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a comprehensive Predictive Maintenance example for KubeEdge, featuring a Go-based mapper that performs real-time Z-score anomaly detection on simulated sensor data. The feedback focuses on improving the robustness of the mapper's lifecycle management, specifically by implementing proper synchronization during shutdown and validating configuration parameters to prevent runtime panics. Additionally, improvements were suggested for the device configurations and DMI reporting logic to correctly handle read-only properties by removing unnecessary desired state fields.

Comment thread predictive-maintenance/mapper/main.go Outdated
}

func runLoop(ctx context.Context, sensor *driver.VirtualSensor, detector *inference.Detector, client *dmi.Client, interval int) {
ticker := time.NewTicker(time.Duration(interval) * time.Second)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

time.NewTicker will panic if the duration is 0 or negative. It is safer to validate the interval value (which comes from configuration) before creating the ticker to ensure robustness.

	if interval <= 0 {
		interval = 5
	}
	ticker := time.NewTicker(time.Duration(interval) * time.Second)

Comment thread predictive-maintenance/configs/device.yaml Outdated
Comment thread predictive-maintenance/mapper/pkg/dmi/client.go Outdated
Signed-off-by: darshankerkar <darshankerkar09@gmail.com>
@darshankerkar darshankerkar force-pushed the feat/predictive-maintenance-example branch from 33ffbcb to 9ddf1e1 Compare May 10, 2026 05:58
Signed-off-by: darshankerkar <darshankerkar09@gmail.com>
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new Predictive Maintenance example for KubeEdge, featuring a Go-based mapper that simulates industrial equipment sensors and performs offline anomaly detection using a Z-score algorithm. The implementation includes device models, deployment manifests, and scripts for verifying edge autonomy. Feedback focuses on optimizing memory management in the rolling window, removing unused sensor code, and improving the security and portability of the Kubernetes manifests by avoiding host networking and hardcoded node names. It was also suggested to make gRPC timeouts configurable for better production readiness.

Comment thread predictive-maintenance/mapper/pkg/inference/detector.go Outdated
Comment thread predictive-maintenance/mapper/pkg/driver/sensor.go Outdated
Comment thread predictive-maintenance/manifests/mapper-deployment.yaml Outdated
Comment thread predictive-maintenance/manifests/mapper-deployment.yaml Outdated
Comment thread predictive-maintenance/mapper/pkg/dmi/client.go Outdated
Signed-off-by: darshankerkar <darshankerkar09@gmail.com>
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a comprehensive 'Predictive Maintenance @edge' example for KubeEdge, featuring a Go-based mapper that simulates industrial sensors and performs offline anomaly detection using a Z-score algorithm. The implementation includes KubeEdge CRD configurations, deployment manifests, and scripts for testing edge autonomy. Feedback on the code focuses on improving the statistical robustness and performance of the inference engine. Key recommendations include updating the data window after analysis to prevent outliers from masking themselves, optimizing mean and standard deviation calculations into a single pass for better edge performance, and implementing a noise floor to handle zero-variance scenarios.

Comment thread predictive-maintenance/mapper/pkg/inference/detector.go Outdated
Comment thread predictive-maintenance/mapper/pkg/inference/detector.go Outdated
Comment on lines +135 to +140
func zScore(value, mean, std float64) float64 {
if std < 1e-10 {
return 0
}
return (value - mean) / std
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Returning 0 when std is near zero prevents division by zero, but it also means that any deviation from a perfectly constant signal will not be detected as an anomaly until the window accumulates enough variance. Consider adding a small 'noise floor' or epsilon to the standard deviation to allow detection of spikes in very stable data.

@kubeedge-bot kubeedge-bot added the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label May 10, 2026
Signed-off-by: darshankerkar <darshankerkar09@gmail.com>
@darshankerkar darshankerkar force-pushed the feat/predictive-maintenance-example branch from 86793b5 to 8edbadb Compare May 10, 2026 06:31
@kubeedge-bot kubeedge-bot removed the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label May 10, 2026
@darshankerkar
Copy link
Copy Markdown
Author

Fixed the code and resolved the outdated suggestions by @gemini-code-assist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/feature Categorizes issue or PR as related to a new feature. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants