github.com/muhammadn/cortex@v1.9.1-0.20220510110439-46bb7000d03d/docs/guides/ha-pair-handling.md (about)

     1  ---
     2  title: "Config for sending HA Pairs data to Cortex"
     3  linkTitle: "Config for sending HA Pairs data to Cortex"
     4  weight: 10
     5  slug: ha-pair-handling
     6  ---
     7  
     8  ## Context
     9  
    10  You can have more than a single Prometheus monitoring and ingesting the same metrics for redundancy. Cortex already does replication for redundancy and it doesn't make sense to ingest the same data twice. So in Cortex, we made sure we can dedupe the data we receive from HA Pairs of Prometheus. We do this via the following:
    11  
    12  Assume that there are two teams, each running their own Prometheus, monitoring different services. Let's call the Prometheis T1 and T2. Now, if the teams are running HA pairs, let's call the individual Prometheis, T1.a, T1.b and T2.a and T2.b.
    13  
    14  In Cortex we make sure we only ingest from one of T1.a and T1.b, and only from one of T2.a and T2.b. We do this by electing a leader replica for each cluster of Prometheus. For example, in the case of T1, let it be T1.a. As long as T1.a is the leader, we drop the samples sent by T1.b. And if Cortex sees no new samples from T1.a for a short period (30s by default), it'll switch the leader to be T1.b.
    15  
    16  This means if T1.a goes down for a few minutes Cortex's HA sample handling will have switched and elected T1.b as the leader. This failover timeout is what enables us to only accept samples from a single replica at a time, but ensure we don't drop too much data in case of issues. Note that with the default scrape period of 15s, and the default timeouts in Cortex, in most cases you'll only lose a single scrape of data in the case of a leader election failover. For any rate queries the rate window should be at least 4x the scrape period to account for any of these failover scenarios, for example with the default scrape period of 15s then you should calculate rates over at least 1m periods.
    17  
    18  Now we do the same leader election process T2.
    19  
    20  ## Config
    21  
    22  ### Client Side
    23  
    24  So for Cortex to achieve this, we need 2 identifiers for each process, one identifier for the cluster (T1 or T2, etc) and one identifier to identify the replica in the cluster (a or b). The easiest way to do with is by setting external labels, the default labels are `cluster` and `__replica__`. For example:
    25  
    26  ```
    27  cluster: prom-team1
    28  __replica__: replica1 (or pod-name)
    29  ```
    30  
    31  and
    32  
    33  ```
    34  cluster: prom-team1
    35  __replica__: replica2
    36  ```
    37  
    38  Note: These are external labels and have nothing to do with remote_write config.
    39  
    40  These two label names are configurable per-tenant within Cortex, and should be set to something sensible. For example, cluster label is already used by some workloads, and you should set the label to be something else but uniquely identifies the cluster. Good examples for this label-name would be `team`, `cluster`, `prometheus`, etc.
    41  
    42  The replica label should be set so that the value for each prometheus is unique in that cluster. Note: Cortex drops this label when ingesting data, but preserves the cluster label. This way, your timeseries won't change when replicas change.
    43  
    44  ### Server Side
    45  
    46  The minimal configuration requires:
    47  
    48  * Enabling the HA tracker via `-distributor.ha-tracker.enable=true` CLI flag (or its YAML config option)
    49  * Configuring the KV store for the ring (See: [Ring/HA Tracker Store](../configuration/arguments.md#ringha-tracker-store)). Only Consul and etcd are currently supported. Multi should be used for migration purposes only.
    50  * Setting the limits configuration to accept samples via `-distributor.ha-tracker.enable-for-all-users` (or its YAML config option)
    51  
    52  
    53  The following configuration snippet shows an example of the HA tracker config via YAML config file:
    54  
    55  ```yaml
    56  limits:
    57    ...
    58    accept_ha_samples: true
    59    ...
    60  distributor:
    61    ...
    62    ha_tracker:
    63      enable_ha_tracker: true
    64      ...
    65      kvstore:
    66        [store: <string> | default = "consul"]
    67        [consul | etcd: <config>]
    68        ...
    69    ...
    70  ```
    71  
    72  For further configuration file documentation, see the [distributor section](../configuration/config-file-reference.md#distributor_config) and [Ring/HA Tracker Store](../configuration/arguments.md#ringha-tracker-store).
    73  
    74  For flag configuration, see the [distributor flags](../configuration/arguments.md#ha-tracker) having `ha-tracker` in them.