How to run Predictive Analytics In DevOps

Predictive analytics can help DevOps teams improve their workflow efficiency, reliability, and quality. In this article, we will cover gathering predictive analytics data, selecting and training predictive models, operationalizing the models, and how to continuously improve predictive models.

According to a CloudBees report, the mean time to repair operational issues remains high - at 220 minutes on average. Not only does this hurt user and business outcomes through service disruptions, but 44% of enterprises say hourly downtime costs top $1 million, according to ITIC Survey

As DevOps processes continue to mature, implementing a strategic approach to predictive analytics can help teams shift from reactive firefighting to proactive issue prevention. 

In this article, we will explore how to set up a predictive analytics pipeline in a real-world DevOps environment, covering data preparation, model selection, and prediction model deployment.

Limitations of reactive monitoring 

While the traditional monitoring-centric model provides visibility, it is insufficient because it only surfaces problems after they've occurred.

That’s not all, it also comes with the following limitations:

  • Too much noise. Teams receive numerous alerts that may not all require attention. With limited bandwidth, prioritizing what's truly actionable becomes difficult.
  • Costly and inefficient firefighting. Teams waste resources and time on solving issues that could have been avoided through proactive measures. 
  • Risks to quality and stability. When left to persist, certain types of bugs or anomalies can escalate, negatively impacting services, users, and business metrics. The longer it takes to repair, the greater the potential damage.

To help address these limitations, DevOps teams are increasingly turning to predictive analytics for a more foresighted approach. With predictive modeling, you can anticipate potential problems and make adjustments to prevent their occurrence. 

Preparing Predictive Analytics Data

To start, identify all relevant data sources within your existing monitoring tooling, for instance, deployment logs, CI/CD workflow records, configuration management systems, and application metrics. Some key attributes to extract include:

  • Deployment characteristics (duration, branch, commits, pull request info)
  • Infrastructure metrics (CPU, memory, network, response times) 
  • Test outcomes (unit, integration, acceptance results)
  • Error/exception details 

It is also important to clean and preprocess the data before using it for predictive analytics. This may involve:

  • Removing anomalies and outliers that may skew the analysis or cause errors
  • Handling missing values or imputing them with reasonable estimates
  • Normalizing or scaling the data to make it comparable and consistent
  • Encoding categorical or textual data into numerical or binary values

Depending on the volume and velocity of the data, different data storage options may be suitable. For example, many organizations use InfluxDB - a database optimized for time-stamped or time-series data - to store chronologically ordered data.  

For batch modeling, data can be exported periodically to files in CSV or JSON formats for easy access. For streaming modeling, data can be ingested continuously using tools like Kafka or Spark.

Verify the quality of the data before using it for predictive analytics. Poor data quality can negatively impact the predictive outcomes, as it can introduce noise, bias, or errors in the analysis. 

Once the relevant data has been identified and extracted, the next important step is to create and transform features that can improve the performance of a predictive model through feature engineering. 

For instance, assume you want to predict the service quality of a cloud provider based on the deployment duration and the number of requests. To get a realistic prediction, you can assign different weights to different applications based on their importance. A slowdown in a non-essential container shouldn’t be given the same weight and attention as a slowdown in critical workload containers. By adding a number to represent the importance of the container, you add a feature to the predictive model.

Selecting Predictive Models

After establishing a data repository, evaluate candidate algorithms based on your objectives. For instance, in deployment failure prediction, where you want to reach a single result, random forest classifiers will perform well. Whereas unsupervised techniques like K-means clustering could help detect anomalous behavior in metrics. 

Once top models are selected, implement them in your preferred language/framework like Python sklearn. Establish reproducible training/evaluation pipelines with tools like MLflow for tuning hyperparameters like learning rate, depth, etc. 

To train and evaluate the models, the following steps are recommended:

  • Split the data into training, validation, and test sets. 
  • Use tools like MLflow to establish reproducible training and evaluation pipelines. MLflow can help track the model experiments, parameters, metrics, and artifacts. 
  • Find the optimal hyperparameters for the model, such as the learning rate, the number of trees, the number of clusters, the number of hidden units, etc. The preferred tool for this is cross-validation or grid search.
  • Use appropriate evaluation metrics to measure the model’s performance. 

Operationalizing Predictions

To begin deriving value, integrate trained models into your existing workflows. Some options include:

  • Writing predictions to a time-series database like InfluxDB for consumption by dashboards/alerts. This can be done by using the InfluxDB Python client to write the prediction results along with the timestamp and other metadata to the database. The predictions can then be queried and displayed on Grafana dashboards or Prometheus alerts.
  • Building endpoints to query predictions via a REST API. Using Flask or FastAPI, you can create a web service that can handle requests and deliver predictions. The endpoints can be made available over the internet or within the network using NGINX or Kubernetes. The predictions can be accessed by any client that can make HTTP requests to the web service that provides the predictions.
  • Executing models periodically as jobs on Kubernetes via CronJobs. Create a Docker image that contains the model code and dependencies, and push it to a container registry. Then, you can use a CronJob resource to pull and run the image on a Kubernetes cluster at a specified frequency. The predictions can then be written to a database or a file system for further processing or consumption. Learn more about CronJobs from this blog: What Are Objects Used for in Kubernetes? 11 Types of Objects Explained.
  • Rendering insights and anomalies on Grafana through plug-ins. This can be done by using Grafana plug-ins that can enhance the visualization and analysis of the data and the predictions. For example, the Grafana Machine Learning plug-in can help train and deploy models directly from Grafana, and the Grafana Anomaly Detection plug-in can help detect and highlight anomalies in the data and the predictions.
  • Configuring alert rules in Prometheus to trigger on high-risk predictions. Define risk thresholds and alert configurations clearly. Integrate alerts into on-call rotations to ensure timely handling. 

Over time, more advanced deployment techniques like model serving with Kafka/Redis could be explored too. The key is balancing accuracy vs. latency based on your specific ML and monitoring architectures.

If you want to learn more about Grafana and Prometheus, check out our article on Monitoring Infrastructure with the Grafana Prometheus Stack.

Real-Time vs. Batch Processing

When you integrate predictive models with DevOps, you need to decide whether to use real-time or batch processing depending on the data characteristics and the business requirements. Real-time processing involves processing data as soon as it arrives, while batch processing involves processing data in groups at regular intervals. 

Another difference between the two is that real-time processing handles high-volume, complex data streams with low latency for immediate decisions. Batch processing, on the other hand, analyzes lower volumes of cleaned data periodically for in-depth analysis. 

Continuous Improvement  

No predictive system is static; concepts and systems evolve over time. To ensure model quality, schedule regular retraining using automated workflows. Monitor drift in key metrics and re-evaluate feature importance. 

To ensure model quality, regular retraining and monitoring are required. This involves:

  • Scheduling periodic retraining using automated workflows. To leverage newer data, retrain the models periodically in an MLOps manner, especially for anomaly detection algorithms that need to adapt to the changing definitions of “normal”. The pipelines can be activated by time, events, or dependencies and can manage failures and retries. The retrained models can then be launched into production using Kubernetes. 
  • Monitoring drift in key metrics and features. Collect and visualize the model performance and feature distribution metrics over time. The metrics can help identify if the model is degrading or if the data is changing. The features can help identify if the model is losing relevance or if new features are needed.
  • Addressing concept drift over time. This can be done using techniques like online learning or active learning to update the model with new data as it arrives. Online learning can help the model adapt to the changing data distribution by adjusting the model parameters incrementally. Active learning can help the model select the most informative data points to learn from by querying the user or an oracle for feedback.

Always test improved versions against validation data before swapping production models. Look to gradually retire outdated model components responsibly. 

To learn more about DevOps and CI/CD, check out the following learning paths:

DevOps Engineer Learning Path

CI/CD Learning Path

Conclusion

To help address the limitations of reactive monitoring, teams are increasingly turning to predictive analytics for a more proactive approach. Embracing a predictive analytics approach supports the key DevOps goals of improving stability, optimizing change management processes, and enhancing overall system reliability. To maximize the benefits of predictive modeling, ensure you regularly monitor and improve your models because systems evolve over time. 

Are you ready for hands-on learning? Become a subscriber by visiting our plan and pricing page to access 70+ top DevOps courses. Start your journey today!

Please share your feedback, questions, or suggestions in the comment box below.