Configure delegate metrics and auto scale
Learn how to configure delegate metrics collection with Prometheus and Grafana, and set up auto scaling using replicas.
Harness Delegates are responsible for executing various types of workloads, and the amount of resources consumed depends on the specific type of workload being performed. Harness cannot predict the specific resource requirements for a particular workload in advance.
This topic explains how to:
Configure the Prometheus monitoring tool for the metrics collection.
Configure the Grafana analytics tool to display metrics.
Configure the delegate resource threshold.
Auto scale using replicas.
Delegate metrics
Harness captures delegate agent metrics for delegates with an immutable image type. This process requires a delegate an immutable image. For more information, go to Delegate image types.
The delegate is instrumented for the collection of the following delegate agent metrics.
Metric name
Description
io_harness_custom_metric_task_execution_time
The amount of time it took to complete a task (in seconds).
io_harness_custom_metric_tasks_currently_executing
The number of tasks currently in an executing state.
io_harness_custom_metric_task_timeout_total #
The total number of tasks that timed out before completion.
io_harness_custom_metric_task_completed_total #
The total number of tasks completed.
io_harness_custom_metric_task_failed_total #
The total number of failed tasks.
io_harness_custom_metric_task_rejected_total * #
The number of tasks rejected because of a high load on the delegate.
io_harness_custom_metric_delegate_connected
Indicates whether the delegate is connected. Values are 0 (disconnected) and 1 (connected).
io_harness_custom_metric_delegate_reconnected_total #
The number of times delegate websocket got reconnected. Note that this is only for WebSocket mode delegates.
io_harness_custom_metric_resource_consumption_above_threshold*
Delegate CPU is above a threshold. Provide DELEGATE_CPU_THRESHOLD as the env variable in the delegate YAML to configure the CPU threshold. For more information, go to Configure delegate resource threshold.
ldap_sync_group_flush_total
Publishes the total count for a user group when the LDAP group sync returns 0 users for that group. The metric publishes the accountIdentifier, GroupDN, and the count.
This topic includes example YAML files you can use to create application manifests for your Prometheus and Grafana configurations.
General recommended metrics configuration
Below are the metrics settings recommended by Harness. Tailor these settings according to your organization's specific needs.
CPU/Memory
Configuring HPA based on CPU/Memory can be a bit complex for some use cases. However, if the calculations are possible, we believe 70-80% usage is the most effective HPA indicator. Ideally, this percentage should be slightly lower than DELEGATE_CPU_THRESHOLD, so that HPA is triggered before the delegate starts rejecting tasks to avoid task execution failures or slowdown.
io_harness_custom_metric_task_execution_time
Utilize the P99 metric to establish a baseline after initiating pipeline runs and set an appropriate threshold.
Set a low severity alarm for significant deviations.
A significant change can indicate pipeline performance issues or the addition of a slow pipeline. While an alarm doesn't necessarily signify an issue, it's worth investigating.
HPA isn't suitable for this metric.
io_harness_custom_metric_tasks_currently_executing
HPA based on CPU/Memory provides better indicators. Utilize a count metric.
Create a low severity alarm for significant deviations (for example, a 30-50% change).
Set a high severity alarm for zero over a prolonged period (for example, 30 minutes) if delegates are consistently expected to perform tasks.
If the change is unexpected, the alarm could indicate a need to plan for scaling the delegate fleet due to increased usage. A sudden burst might cause downtime or indicate a problem with pipeline executions or downstream services.
io_harness_custom_metric_task_timeout_total
HPA isn't necessary. Ideally, this should be close to zero. Create a high severity alarm for a sufficiently low number.
An alarm might indicate misconfigured pipelines or disruptions in downstream services, but also overloaded delegate.
io_harness_custom_metric_task_completed_total
While possibly not highly informative, it can be added to the dashboard for insight into processed volume.
Plot count per delegate; all delegates should be similarly utilized.
io_harness_custom_metric_task_failed_total
HPA isn't necessary. Ideally, this should be close to zero, but intermittent failures occur and shouldn't trigger alarms.
Establish a baseline and set a high severity alarm for significant deviations. This would signify a serious issue such as a service outage or misconfiguration.
io_harness_custom_metric_task_rejected_total
HPA isn't necessary (as this indicates that CPU/Memory thresholds are already reached), but it provides an alternate observation of delegate utilization.
Create a low severity alarm for total unique task rejections. This alarm can indicate a need to scale up the delegate fleet.
io_harness_custom_metric_resource_consumption_above_threshold
While this can serve as a simpler HPA metric, we advise to use CPU/Memory for HPA instead if possible. By the time this metric is triggered, rejection has likely already begun, making it too late for HPA adjustments. Fine-tuning CPU/Memory metrics provides a better HPA indicator, allowing scaling before task rejection occurs.
Configure the Prometheus monitoring tool for the metrics collection
Apply the prometheus.yml file
The configuration of Prometheus requires the installation of a Prometheus workload and service in your Kubernetes cluster. Use the following example configuration file to install the harness-delegate-prometheus-deployment workload and a service named harness-delegate-prometheus-service. The configuration includes a load balancer with an IP address you can use to access the Prometheus UI.
Expand the section below to view a sample prometheus.yml file.
Use the following command to deploy the configuration file.
Configure the Grafana analytics tool to display metrics
To set up Grafana, use the following example grafana.yml file.
Copy the
grafana.ymlfile.If you're not using the default
harness-delegate-ngnamespace, replace it with the namespace into which you deployed your delegate.Use the following command to apply the Grafana configuration file to your deployment:
Select the exposed URL to access Grafana.
Configure delegate resource threshold
You can set the delegate to reject new tasks when the configured resource threshold is reached. You can then spin up new delegates when resources are above the threshold.
CONFIGURATION DEPRECATION NOTICE
Delegate configuration to control the task rejections DYNAMIC_REQUEST_HANDLING and DELEGATE_RESOURCE_THRESHOLD are now deprecated and will be removed in a future version of the delegate. The preferred method to configure a resource threshold is by using DELEGATE_CPU_THRESHOLD as described below.
To configure the delegate resource threshold, set the DELEGATE_CPU_THRESHOLD env variable to the CPU threshold in percentages. When the threshold is exceeded, the delegate rejects new tasks.
Auto scale using replicas
Autoscaling Harness Delegate using replicas is a useful feature that can help ensure your deployments are executed efficiently, without downtime or resource overload.
Enable the usage threshold for delegate resources
You can set the delegate to reject new tasks when the configured resource threshold is reached. You can then spin up new delegates when resources are above the threshold. For more information, go to Configure delegate resource threshold.
Configure Harness Delegate autoscaling using replicas for Helm chart deployments
To access the default Helm chart for the values.yaml file, go to Harness Delegate Helm chart.
To auto scale the delegate, do the following:
In your
values.yamlfile, go toautoscalingparameters.Set
enabledtotrue.Specify the minimum and maximum number of replicas you want to use in the
minReplicasandmaxReplicasparameters.To fine-tune your autoscaling, you can set the
targetMemoryUtilizationPercentageto add a new replica when memory utilization exceeds this percentage.(Optional) Set the
targetCPUUtilizationPercentageto add a new replica when CPU utilization exceeds this percentage.Save the file, and upgrade your deployment.
Configure Harness Delegate autoscaling using replicas for Kubernetes 1.23 and later
The HPA configuration setting is included in the default Kubernetes delegate YAML file. Harness updated the default HPA in the Harness Delegate YAML versions 24.02.82302 and later to use autoscaling/v2 instead of autoscaling/v1, which was used in earlier delegate versions.
Since autoscaling/v2 has been GA with Kubernetes 1.23 and higher, if you have a Kubernetes version lower than 1.23 and a delegate version 24.02.82302 or later, you must manually change the apiVersion in the HorizontalPodAutoscaler section of your delegate YAML to autoscaling/v1. For more information, go to Configure Harness Delegate autoscaling using replicas for Kubernetes versions lower than 1.23.
To auto scale the delegate for Kubernetes 1.23 and higher, do the following:
In your
harness-delegate.ymlfile, go toautoscalingparameters.Specify the minimum and maximum number of replicas you want to use in the
minReplicasandmaxReplicasparameters.To fine-tune your autoscaling, you can set the
memoryaverageUtilizationto add a new replica if memory utilization exceeds this percentage. Below is an example of autoscaling the delegate if the memory usage of delegates goes above 70% (the default YAML setting).
(Optional) Set the
cpuaverageUtilizationto add a new replica if CPU utilization exceeds this percentage.Save the file, and deploy it to your Kubernetes cluster.
Configure Harness Delegate autoscaling using replicas for Kubernetes versions earlier than 1.23
The HPA configuration setting is included in the default Kubernetes delegate YAML file.
IMPORTANT VERSION INFO
Harness updated the default HPA in the Harness Delegate YAML to use autoscaling/v2 instead of autoscaling/v1 which was used in earlier delegate versions.
Since autoscaling/v2 has been GA with Kubernetes 1.23 and higher, if you have a Kubernetes version earlier than 1.23 and a delegate version 24.02.82302 or later, you must manually change the apiVersion in the HorizontalPodAutoscaler section of your delegate YAML to autoscaling/v1.
To auto scale the delegate for Kubernetes versions lower than 1.23, do the following:
In your
harness-delegate.ymlfile, go toautoscalingparameters.Replace the
apiVersionin theHorizontalPodAutoscalersection of your delegate YAML toautoscaling/v1.Specify the minimum and maximum number of replicas you want to use in the
minReplicasandmaxReplicasparameters.To fine-tune your autoscaling, you can set the
targetMemoryUtilizationPercentageto add a new replica if Memory utilization exceeds this percentage. Below is an example of autoscaling the delegate if the Memory usage of delegates goes above 70%.(Optional) Set the
targetCPUUtilizationPercentageto add a new replica if CPU utilization exceeds this percentage.Save the file, and restart your pods.
When you create a deployment, Harness automatically spins up new replicas of your delegate as needed to ensure the deployment is completed.
Example delegate YAML
Here's an example YAML file that configures delegates to have a minimum of 2 replicas. New tasks won't be accepted if the Memory usage goes above 80%. Once the Memory usage hits 70%, a new pod will be created to handle the load, up to a maximum of 10 replicas. When the Memory usage goes down below 70%, the number of replicas will be scaled back down to a minimum of 2.
Scale down delegate pods
You can use terminationGracePeriodSeconds or preStopHook to scale down your delegate pods.
terminationGracePeriodSeconds: This is used to allow the delegate to delay the shutdown so that this process can perform some cleanup. The container shutdown is delayed the specified duration.If there are no tasks running on the delegate pod, it terminates immediately. If the delegate pod is running one or more tasks, it will stop accepting new tasks and terminate as soon as all running tasks complete.
For example, if
terminationGracePeriodSecondsis set to 7200 (two hours), there are three possible scenarios:No tasks: The delegate container terminates immediately.
Short tasks: For example, if tasks require 10 minutes to complete, the delegate will delay shutdown until tasks are complete (10 minutes), and then shutdown. In this example, the total delay is 10 minutes, not two hours.
Long tasks: For example, if tasks require five hours to complete, the delegate will delay the shutdown, up to the maximum grace period configured (two hours), then Kubernetes sends SIGKILL signal, force killing the delegate and tasks. Tasks will show up as timed out/failed in the UI.
preStopHook: This is used to allow any other kind of cleanup outside of the main process, for example, if you want to save files. This hook runs in parallel to theterminationGracePeriodSeconds, but before the delegate process shutdown is triggered (before the delegate process receives SIGTERM). If the hook's grace period ends, it is terminated. The delegate enters draining mode and only runs tasks already in progress. It will try doing this until all tasks are completed or until it is interrupted by Kubernetes with the SIGKILL signal when the grace period expires.
Last updated
Was this helpful?