# Data Health Agent Lamdbda

Data Health Agent Lamdbda executes queries from [data-health-config.json](https://github.com/filtr/delphi-data-health-configs/tree/master) with corresponding params from event.


## Lambda Environment variables
To execute the Apps Manager Lambda he following environment variables must be configured:

| Variable                        | Description                                                  |
|---------------------------------|--------------------------------------------------------------|
| `ENVIRONMENT`                   | Environment name (`prod`, `dev`)                             |
| `CONFIG_PATH`                   | Path to config (`s3://delphi-configs/data-health/cfg.json`)  |
| `SENTRY_SECRET_KEY`             | Sentry secret key                                            |


## Lambda Input
As an input lambda receives a data type and required params for each query related to it.

### ads_data payload examples

# Default CW event payload:

```json
{
  "data_type": "ads_data",
  "dsp": "google"
}
```

# Backfill payload with params:
We can manually invoke a lambda with a params cointaining both dates for each query in payload for backfill:

```json
{
  "data_type": "ads_data",
  "dsp":  "google",
  "params": [
    {
      "start_date": "2021-06-02",
      "end_date": "2021-08-19"
    },
    {
      "start_date": "2021-06-02",
      "end_date": "2021-08-19"
    }
  ]
}
```

### Default CW event payload:

```json
{
  "data_type": "data_completeness",
  "dsp": "amazon"
}
```

# Backfill payload with params:

```json
{
  "data_type": "data_completeness",
  "dsp": "amazon",
  "params": [
    {
     "start_date": "2021-06-02",
      "end_date": "2021-08-19"
    }
  ]
}
```


## Lambda Output
In case of successful lambda execution the following output will be provided:
```json
{
    "meta": {
        "status": "OK"
    }
}
```

If any kind of exception occurred, the response will look like the following:
```json
{
    "meta": {
        "status": "FAILURE",
        "message": <exception message>
    }
}
```

## Developers guide

Use `pre-commit` for git hooks managing (https://pre-commit.com/#installation). Hook configuration
can be found at .pre-commit-config.yaml. `isort` and `yapf` tools are included to run as a part
of precommit hook.

To register a new hook run:
```shell script
pre-commit install
```

To run hooks without code committing:
```shell script
pre-commit run
```

Don’t forget to run formatter check, `pylint` and `mypy` before code committing manually.
It will save you from wasting time at reading CI logs for failed build.
```shell script
make fmtcheck && make lint && make typecheck
```