TimeSeriesPrediction

Introduction for TimeSeriesPrediction

Knowing the future makes things easier for us.


Many businesses are naturally cyclical in time series, especially for those that directly or indirectly serve “people”. This periodicity is determined by the regularity of people’s daily activities. For example, people are accustomed to ordering take-out at noon and in the evenings; there are always traffic peaks in the morning and evening; even for services that don’t have such obvious patterns, such as searching, the amount of requests at night is much lower than that during business hours. For applications related to this kind of business, it is a natural idea to infer the next day’s metrics from the historical data of the past few days, or to infer the coming Monday’s access traffic from the data of last Monday. With predicted metrics or traffic patterns in the next 24 hours, we can better manage our application instances, stabilize our system, and meanwhile, reduce the cost.

TimeSeriesPrediction is used to forecast the kubernetes object metric. It is based on PredictionCore to do forecast.

Features

A TimeSeriesPrediction sample yaml looks like below:

  1. apiVersion: prediction.crane.io/v1alpha1
  2. kind: TimeSeriesPrediction
  3. metadata:
  4. name: node-resource-percentile
  5. namespace: default
  6. spec:
  7. targetRef:
  8. kind: Node
  9. name: 192.168.56.166
  10. predictionWindowSeconds: 600
  11. predictionMetrics:
  12. - resourceIdentifier: node-cpu
  13. type: ResourceQuery
  14. resourceQuery: cpu
  15. algorithm:
  16. algorithmType: "percentile"
  17. percentile:
  18. sampleInterval: "1m"
  19. minSampleWeight: "1.0"
  20. histogram:
  21. maxValue: "10000.0"
  22. epsilon: "1e-10"
  23. halfLife: "12h"
  24. bucketSize: "10"
  25. firstBucketSize: "40"
  26. bucketSizeGrowthRatio: "1.5"
  27. - resourceIdentifier: node-mem
  28. type: ResourceQuery
  29. resourceQuery: memory
  30. algorithm:
  31. algorithmType: "percentile"
  32. percentile:
  33. sampleInterval: "1m"
  34. minSampleWeight: "1.0"
  35. histogram:
  36. maxValue: "1000000.0"
  37. epsilon: "1e-10"
  38. halfLife: "12h"
  39. bucketSize: "10"
  40. firstBucketSize: "40"
  41. bucketSizeGrowthRatio: "1.5"
  • spec.targetRef defines the reference to the kubernetes object including Node or other workload such as Deployment.
  • spec.predictionMetrics defines the metrics about the spec.targetRef.
  • spec.predictionWindowSeconds is a prediction time series duration. the TimeSeriesPredictionController will rotate the predicted data in spec.Status for consumer to consume the predicted time series data.

PredictionMetrics

  1. apiVersion: prediction.crane.io/v1alpha1
  2. kind: TimeSeriesPrediction
  3. metadata:
  4. name: node-resource-percentile
  5. namespace: default
  6. spec:
  7. predictionMetrics:
  8. - resourceIdentifier: node-cpu
  9. type: ResourceQuery
  10. resourceQuery: cpu
  11. algorithm:
  12. algorithmType: "percentile"
  13. percentile:
  14. sampleInterval: "1m"
  15. minSampleWeight: "1.0"
  16. histogram:
  17. maxValue: "10000.0"
  18. epsilon: "1e-10"
  19. halfLife: "12h"
  20. bucketSize: "10"
  21. firstBucketSize: "40"
  22. bucketSizeGrowthRatio: "1.5"

MetricType

There are three types of the metric query:

  • ResourceQuery is a kubernetes built-in resource metric such as cpu or memory. crane supports only cpu and memory now.
  • RawQuery is a query by DSL, such as prometheus query language. now support prometheus.
  • ExpressionQuery is a query by Expression selector.

Now we only support prometheus as data source. We define the MetricType to orthogonal with the datasource. but now maybe some datasources do not support the metricType.

Algorithm

Algorithm define the algorithm type and params to do predict for the metric. Now there are two kinds of algorithms:

  • dsp is an algorithm to forcasting a time series, it is based on FFT(Fast Fourier Transform), it is good at predicting some time series with seasonality and periods.
  • percentile is an algorithm to estimate a time series, and find a recommended value to represent the past time series, it is based on exponentially-decaying weights historgram statistics. it is used to estimate a time series, it is not good at to predict a time sequences, although the percentile can output a time series predicted data, but it is all the same value. so if you want to predict a time sequences, dsp is a better choice.

dsp params

percentile params