# DevOps Platform Services Common Chart
This Helm chart manages common Custom Resource Definitions (CRDs) like ScaledObject and ServiceMonitor, providing an easy way for developers to include these in their Helm charts.

## Table of Contents

- [Introduction](#introduction)
- [Installation](#installation)
- [Usage](#usage)
- [Configuration](#configuration)

## Introduction

The **devops-platform-services-common** chart simplifies the management of common CRDs such as ScaledObject and ServiceMonitor. This allows for effortless integration and customization in various deployments.

## Supported Objects
- Scaledobject
- Servicemonitor

## Installation


To add this chart as a dependency in your Helm chart, update your `Chart.yaml` as follows:

```yaml
dependencies:
- name: devops-platform-services-common
  version: "0.1.23"
  condition: devops-platform-services-common.enabled
  repository: "@repo21edgesaliasingress-helm"
```

After updating your Chart.yaml, run the following command to build the dependencies:
```yaml
helm dep build path/to/your/chart
```

## Usage

### Enabling dependency chart
By default, dependency chart is disabled. To enable them, set `devops-platform-services-common` to `true` in your `values.yaml`:

```yaml
devops-platform-services-common:
  enabled: true      
```

### Enabling ScaledObjects

By default, ScaledObjects are disabled. To enable and configure it, set `scaledobjectsEnabled` to `true` in your `values.yaml` under `devops-platform-services-common`:

```yaml
scaledobjects:
  - enabled: true
    scaleTargetRef:
      name: yourWorkloadName
    triggers:
      - type: prometheus
        metadata:
          query: "sum(rate(http_requests_total{job='your-job-name'}[1m]))"
          threshold: "10"
      - type: new-relic
        metadata:
          nrql: SELECT latest(durationConnect) FROM SyntheticRequest WHERE monitorId = 'xyz'
          threshold: "100"        
```

### Enabling ServiceMonitor

By default, ServiceMonitor is disabled. To enable and configure it, set `serviceMonitor.enabled` to `true` in your `values.yaml`:

**NOTE - the namespace needs to be generated with the region of the deployment , in here an example of how to use it from jinja values yaml fiels** 

```yaml
serviceMonitor:
  enabled: true
  labels: { "app": "my-app" }
  # interval: "30s"
  # scrapeTimeout: "10s"
  # name: "my-app-service-monitor" Optional: If you want to overwrite the default value
  path: /metrics #put the path of the metrics export
  # port: http (uncomment if you want to use port name - if you have it in the service of the chart)
  # targetPort: 3000 (uncomment if you want to use targetPort- if you dont have a port name)
  scheme: http #or https
  selector:
    matchLabels:
      app: "my-app"
```

## Configuration

The following table lists the configurable parameters of the chart and their default values.

| Parameter                                                | Description                                                              | Default                                     |
|----------------------------------------------------------|--------------------------------------------------------------------------|---------------------------------------------|
| `scaledobjects`                                          | Array of ScaledObject configurations                                     | `[{}]`                                      |
| `scaledobjects[].enabled`                                | Enable or disable the ScaledObject                                       | `false`                                     |
| `scaledobjects[].scaleTargetRef.name`                    | Name of the workload to scale                                            | ``                                          |
| `scaledobjects[].scaleTargetRef.kind`                    | Kind of the workload to scale (e.g., Deployment)                         | `Deployment`                                |
| `scaledobjects[].minReplicaCount`                        | Minimum number of replicas                                               | `1`                                         |
| `scaledobjects[].maxReplicaCount`                        | Maximum number of replicas                                               | `5`                                         |
| `scaledobjects[].pollingInterval`                        | Polling interval for scaling                                             | ``                                          |
| `scaledobjects[].annotations`                            | Annotations for the ScaledObject                                         | `{}`                                        |
| `scaledobjects[].labels`                                 | Labels for the ScaledObject                                              | `{}`                                        |
| `scaledobjects[].advanced.restoreToOriginalReplicaCount` | Restore replicas to the original count after scaling action              | `false`                                     |
| `scaledobjects[].advanced.horizontalPodAutoscalerConfig` | Configuration for the Horizontal Pod Autoscaler                          | `{}`                                        |
| `scaledobjects[].triggers`                               | Array of scaling triggers                                                | `[]`                                        |
| `scaledobjects[].triggers[].type`                        | Type of the trigger (e.g., prometheus, new-relic)                        | ``                                          |
| `scaledobjects[].triggers[].metadata.query`              | Query to fetch the metric for Prometheus triggers                        | ``                                          |
| `scaledobjects[].triggers[].metadata.threshold`          | Threshold value to trigger scaling                                       | ``                                          |
| `scaledobjects[].triggers[].metadata.ignoreNullValues`   | Specify whether to ignore null values for specific triggers              | `true`                                      |
| `scaledobjects[].triggers[].metadata.nrql`               | NRQL query for New Relic triggers                                        | ``                                          |
| `scaledobjects[].triggers[].metadata.noDataError`        | Handle no data error for New Relic triggers                              | `false`                                     |
| `scaledobjects[].triggers[].metricType`                  | Type of the metric (Value, AverageValue)                                 | `Value`                                     |
| `scaledobjects[].fallback.failureThreshold`              | Number of failures before falling back to a fixed replica count          | `3`                                         |
| `scaledobjects[].fallback.replicas`                      | Number of replicas to fall back to                                       | ``                                          |
| `serviceMonitor.enabled`                                 | Enable the ServiceMonitor                                                | `false`                                     |
| `serviceMonitor.bearerTokenFile`                         | A file containing a bearer token for authentication the scraped target   | `"/etc/prometheus/secrets/kube-prom-services-store-token-gen/token"`|
| `serviceMonitor.labels`                                  | Labels for the ServiceMonitor                                            | `{}`                                        |
| `serviceMonitor.name`                                    | Name for ServiceMonitor                                                  | `""`                                        |
| `serviceMonitor.interval`                                | Scrape interval for ServiceMonitor                                       | `"30s"`                                     |
| `serviceMonitor.scrapeTimeout`                           | Scrape timeout for the ServiceMonitor                                    | `"10s"`                                     |
| `serviceMonitor.path`                                    | Path to scrape for metrics -                                             | `"/metrics"`                                |
| `serviceMonitor.params`                                  | optional HTTP parameters that should be appended to the scrape URL.    | `{}` |                  
| `serviceMonitor.port`                                    | Port to scrape for metrics (string name of the port name in the service) | ``                                          |
| `serviceMonitor.targetPort`                              | Port to scrape for metrics (the container port itself)                   | ``                                          |
| `serviceMonitor.scheme`                                  | Scheme to use for scraping (http or https)                               | `"http"`                                    |
| `serviceMonitor.namespaceSelector`                       | Namespace selector for ServiceMonitor                                    | `{ "any": true }`                           |
| `serviceMonitor.selector`                                | Selector for ServiceMonitor                                              | `{ "matchLabels": { "app": "<appname>" } }` |
| `serviceMonitor.tlsConfig.insecureSkipVerify`            | Skip TLS certificate verification when scraping (true/false)             | `false`                                     |
| `serviceMonitor.relabelings`                             | Custom relabeling configuration for ServiceMonitor                       | `[]`                                        |
| `commonLabels`                                           | Labels for all the chart templates                                       | `{}`                                        |

## Chart Details

- This chart includes templates for ScaledObject and ServiceMonitor.
- It is maintained by the DevOps Platform Services team.

For more detailed configuration options, please refer to the `values.yaml` file.

---

Maintained by [DevOps Platform Services](mailto:devops-platform-services@jfrog.com).

