# ArgoCD

> Send deployment markers to Last9 when ArgoCD syncs an application, so you can correlate Kubernetes deployments with service health, error rates, and APDEX shifts.

Source: https://last9.io/docs/integrations/ci-cd/argocd/

The [Last9 ArgoCD Integration](https://github.com/last9/last9-argocd-integration) sends deployment markers to Last9's [Change Events API](/docs/change-events/) whenever ArgoCD syncs an application. Every deployment appears as a vertical overlay on your service dashboards — correlated with latency, error rates, and APDEX.

No operator. No sidecar. No Lambda. ArgoCD's built-in notification controller handles everything.

## Prerequisites

- ArgoCD with the [notifications controller](https://argo-cd.readthedocs.io/en/stable/operator-manual/notifications/) installed
- A Last9 refresh token (write scope). See [Getting Started with API](/docs/getting-started-with-api/) to generate one.
- Your Last9 organization slug (the `{org}` segment in your Last9 dashboard URL).

## Install

1. **Add your credentials**

   ```yaml
   # install/secret.yaml
   apiVersion: v1
   kind: Secret
   metadata:
     name: argocd-notifications-secret
     namespace: argocd
   stringData:
     last9-refresh-token: <YOUR_LAST9_REFRESH_TOKEN>
     last9-org-slug: <YOUR_ORG_SLUG>
     last9-token: ""
   ```

   ```sh
   kubectl apply -f install/secret.yaml
   ```

2. **Apply the integration**

   ```sh
   kubectl apply -f https://raw.githubusercontent.com/last9/last9-argocd-integration/master/install/token-refresher.yaml
   kubectl apply -f https://raw.githubusercontent.com/last9/last9-argocd-integration/master/install/argocd-notifications-cm-patch.yaml
   ```

   The first command installs a CronJob that exchanges your refresh token for an access token immediately and every 48 hours — you never need to rotate credentials manually. The second patches `argocd-notifications-cm` with the Last9 webhook service, notification templates, and triggers. Nothing else in your ArgoCD installation changes.

3. **Subscribe your applications**

   Add two annotations to each ArgoCD Application you want to track:

   ```yaml
   metadata:
     annotations:
       notifications.argoproj.io/subscribe.last9-on-sync-running.last9: ""
       notifications.argoproj.io/subscribe.last9-on-sync-finished.last9: ""
   ```

   Or enable Last9 markers for every application in the cluster at once by adding `defaultTriggers` to `argocd-notifications-cm`:

   ```yaml
   data:
     defaultTriggers: |
       - last9-on-sync-running
       - last9-on-sync-finished
   ```

## What gets captured

Two markers per deployment — one when the sync starts, one when it finishes.

| Attribute      | Value                                                |
| -------------- | ---------------------------------------------------- |
| `service`      | ArgoCD application name                              |
| `revision`     | Git commit SHA                                       |
| `namespace`    | Destination namespace                                |
| `cluster`      | Destination cluster name                             |
| `project`      | ArgoCD project                                       |
| `repo`         | Git repository URL                                   |
| `sync_status`  | `Succeeded`, `Failed`, or `Error` (stop marker only) |
| `health`       | `Healthy` or `Degraded` (stop marker only)           |
| `initiated_by` | Username who triggered the sync                      |
| `automated`    | `true` if triggered by auto-sync                     |

## Dashboard correlation

Filter your Last9 service dashboards by `service=<app-name>` to see deployment markers alongside metrics. The `revision` attribute links each marker to the exact commit that changed behavior.

---

## Troubleshooting

- **No markers appearing**

  Check the notifications controller logs:

  ```sh
  kubectl logs -n argocd deployment/argocd-notifications-controller
  ```

  Look for `last9` in the output. If the webhook is firing but events aren't appearing, check the token-refresher ran successfully:

  ```sh
  kubectl logs -n argocd -l job-name=last9-token-refresher-init
  ```

- **Duplicate markers**

  The triggers use `oncePer: app.status.operationState?.syncResult?.revision` to deduplicate — each commit SHA fires at most once per trigger. If you see duplicates, check that the patch applied cleanly:

  ```sh
  kubectl get cm argocd-notifications-cm -n argocd -o yaml | grep last9
  ```

- **Helm users**

  If you manage ArgoCD with Helm, add the contents of [`install/argocd-notifications-cm-patch.yaml`](https://github.com/last9/last9-argocd-integration/blob/master/install/argocd-notifications-cm-patch.yaml) under `notifications.cm` in your values file instead of applying it directly.

Please get in touch with us on [Discord](https://discord.com/invite/Q3p2EEucx9) or [Email](mailto:support@last9.io) if you have any questions.
