diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c46058..1ba1c5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,193 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). -## [Unreleased & outstanding issues] -- Non-https repo url and apt fetching +## [2.9] - 2023-02-27 + +### Added +- Datadog agent pinned versions are now `6.43.0` and `7.43.0` +- Redis and Postgres integrations can be now configured setting an environment variable, without using the prerun.sh script. + +### Deprecated +- This is the last buildpack version with Datadog Agent 6.x as default. Upgrade today to Datadog Agent 7.x by setting the environment variable `DD_AGENT_MAJOR_VERSION=7` in your Heroku application and rebuilding the slug. + +## [2.8] - 2023-01-25 + +### Removed +- Installing checks with `agent-wrapper integration install` is no longer supported for Datadog Agent 6.x.\ +Upgrade to Datadog Agent 7.x by setting the environment variable `DD_AGENT_MAJOR_VERSION=7` in your Heroku application and rebuilding the slug. + +### Added +- Datadog agent pinned versions are now `6.42.0` and `7.42.0` + +## [2.7] - 2022-12-22 + +### Added +- Datadog agent pinned versions are now `6.41.1` and `7.41.1` + +## [2.6] - 2022-11-09 + +### Added +- Datadog agent pinned versions are now `6.40.0` and `7.40.0` +- Config files for integrations now can follow the same folder structure used in the Agent + +### Fixed +- Slug size now doesn't increae when apt buildpack is used (Thanks caioariede for the contribution!) + +## [2.5] - 2022-09-13 + +### Added +- Datadog agent pinned versions are now `6.39.0` and `7.39.0` +- Added warning message when removing the APM or process agent + +## [2.4] - 2022-07-27 + +### Added +- Datadog agent pinned versions are now `6.38.0` and `7.38.0` + +### Fixed +- Removed new introduced unneeded binaries that were increasing the footprint + +## [2.3] - 2022-07-15 + +### Added +- Datadog agent pinned versions are now `6.37.1` and `7.37.1` + +## [2.2] - 2022-05-25 + +### Added +- Datadog agent pinned versions are now `6.36.0` and `7.36.0` + +## [2.1] - 2022-04-25 + +### Added +- Datadog agent pinned versions are now `6.35.1` and `7.35.1` + +## [2.0] - 2022-03-02 + +### Added +- Specific Heroku Datadog Agent build (starting with `6.34.0` and `7.34.0`) is now used +- Datadog agent pinned versions are now `6.34.0` and `7.34.0` + +### Fixed +- Community integrations can now be installed properly when the Python versions for the agent and the system are different + +## [1.33] - 2022-01-27 + +### Added +- Datadog agent pinned versions are now `6.33.0` and `7.33.0` +- Custom checks are now easier to set up. (https://docs.datadoghq.com/agent/basic_agent_usage/heroku/#enabling-custom-checks) + +## [1.32] - 2021-12-27 + +### Security +- Agents `6.32.4` and `7.32.4` remove all dependencies on log4j and use java.util.logging instead. + +### Added +- Datadog agent pinned versions are now `6.32.4` and `7.32.4` + +## [1.31] - 2021-12-16 + +### Security + +- Agents `6.32.3` and `7.33.3` upgrade the log4j dependency to 2.12.2 in JMXFetch to fully address [CVE-2021-44228](https://nvd.nist.gov/vuln/detail/CVE-2021-44228) and [CVE-2021-45046](https://nvd.nist.gov/vuln/detail/CVE-2021-45046) + +### Added +- Datadog agent pinned versions are now `6.32.3` and `7.32.3` + +## [1.30] - 2021-12-13 + +### Security +- Agents `6.32.2` and `7.32.2` set `-Dlog4j2.formatMsgNoLookups=True` when starting the JMXfetch process to mitigate the vulnerability described in [CVE-2021-44228](https://nvd.nist.gov/vuln/detail/CVE-2021-44228) + +### Added +- Datadog agent pinned versions are now `6.32.2` and `7.32.2` + +## [1.29] - 2021-09-23 + +### Added +- Datadog agent pinned versions are now `6.31.0` and `7.31.0` + +## [1.28] - 2021-07-01 + +### Fixed +- Fixed memcached integration for Python 3 + +## [1.27] - 2021-06-28 + +### Added +- Datadog agent pinned versions are now `6.29.0` and `7.29.0` +- The Dyno ID is now sent as host alias (requires Agent 6.29.0/7.29.0 or newer) + +## [1.26] - 2021-05-28 + +### Added +- Datadog agent pinned versions are now `6.28.0` and `7.28.0` + +### Changed +- Apt signing keys are now obtained from keys.datadoghq.com + +## [1.25] - 2021-04-19 + +### Added +- Datadog agent pinned versions are now `6.27.0` and `7.27.0` + +### Fixed +- HTTPS repo fetching + +## [1.24] - 2021-03-03 + +### Added +- Datadog agent pinned versions are now `6.26.0` and `7.26.0` +- Datadog configuration path can now be configured with the `DD_HEROKU_CONF_FOLDER` environment variable + +## [1.23] - 2021-01-20 + +### Added +- Datadog agent pinned versions are now `6.25.0` and `7.25.0` +- Heroku APT cache is now cleaned up automatically when DD_AGENT_VERSION changes + +## [1.22] - 2020-12-09 + +### Added +- Datadog agent pinned versions are now `6.24.0` and `7.24.0` +- Heroku APT cache is now cleaned up when changing stacks +- Heroku-20 stack is now supported + +### Removed +- Removed Datadog agent unneeded dependencies + +## [1.21] - 2020-10-09 + +### Added +- Datadog agent pinned versions are now `6.23.0` and `7.23.0` + +### Change +- Buildpack name reported by `bin/detect` is now "Datadog" instead of "Sysstat" + +## [1.20] - 2020-09-09 + +### Changed +- Removed the security-agent and system-probe dependencies to reduce slug size + +### Fixed +- version-history.json is now created successfully, even if DD_LOGS_ENABLED="false" + +## [1.19] - 2020-08-27 + +### Changed +- Agent now reports `datadog.heroku_agent.running` metric instead of `datadog.agent.running` for agent versions `6/7.22` and newer, to help customers identify which agents are reporting from a Heroku dyno. + +### Fixed +- Buildpack now works correctly with agent versions 7.21.x + +### Added +- Datadog agent pinned versions are now `6.22.0` and `7.22.0` +- DD_VERSION can now be set as part of the `prerun.sh` script + +## [1.18] - 2020-06-17 + +### Added +- Datadog agent pinned versions are now `6.20.2` and `7.20.2` ## [1.17] - 2020-05-04 diff --git a/README.md b/README.md index 1774421..879fc6f 100644 --- a/README.md +++ b/README.md @@ -4,46 +4,73 @@ This [Heroku buildpack][1] installs the Datadog Agent in your Heroku dyno to col ## Installation -To add this buildpack to your project, as well as set the required environment variables: +This guide assumes that you already have your application running on Heroku. See the Heroku documentation to learn how to deploy your application to Heroku. + +1. Go to [Datadog API settings][3] and copy your Datadog API key. Export it to an environment variable: + + ```shell + export DD_API_KEY= + ``` + +2. Export your application name to the APPNAME environment variable: + +```shell +export APPNAME= +``` + +3. Add the Datadog buildpack to your project: ```shell cd -# If this is a new Heroku project -heroku create +# Use the latest major Agent version +heroku config:add DD_AGENT_MAJOR_VERSION=7 -# Add the appropriate language-specific buildpack. For example: -heroku buildpacks:add heroku/ruby +# Enable Heroku Labs Dyno Metadata to set HEROKU_APP_NAME env variable automatically +heroku labs:enable runtime-dyno-metadata -a $APPNAME -# Enable Heroku Labs Dyno Metadata -heroku labs:enable runtime-dyno-metadata -a $(heroku apps:info|grep ===|cut -d' ' -f2) +# Set hostname in Datadog as appname.dynotype.dynonumber for metrics continuity +heroku config:add DD_DYNO_HOST=true # Add this buildpack and set your Datadog API key -heroku buildpacks:add https://github.com/DataDog/heroku-buildpack-datadog.git# -heroku config:add DD_API_KEY= +heroku buildpacks:add --index 1 https://github.com/DataDog/heroku-buildpack-datadog.git +heroku config:add DD_API_KEY=$DD_API_KEY -# Deploy to Heroku -git push heroku master +# Deploy to Heroku forcing a rebuild +git commit --allow-empty -m "Rebuild slug" +git push heroku main ``` -**Warning**: Buildpacks that install apt packages (e.g. [apt][3], [puppeteer dependencies][4]) or buildpacks that modify the `/app` folder (e.g. [monorepo][5]) need to be added *before* the Datadog buildpack. For example, if your application uses the `ruby`, `datadog` and `apt` buildpacks, this would be a correct `heroku buildpacks` output: +Once complete, the Datadog Agent is started automatically when each dyno starts. + +The Datadog Agent provides a listening port on `8125` for statsd/dogstatsd metrics and events. Traces are collected on port `8126`. + +### Order of buildpacks +As explained in the Heroku documentation under [Viewing buildpacks][4], the last buildpack in the list is used to determine the process type for the application. + +Buildpacks that install apt packages, such as [heroku-buildpack-apt][5], [puppeteer-heroku-buildpack][6], or buildpacks that modify the `/app` folder, such as [heroku-buildpack-monorepo][7], need to be added **before** the Datadog buildpack. For example, if your application uses the `ruby`, `datadog` and `apt` buildpacks, this would be a correct `heroku buildpacks` output: ```text -1. heroku/ruby -2. https://github.com/heroku/heroku-buildpack-apt.git -3. https://github.com/DataDog/heroku-buildpack-datadog.git +1. https://github.com/heroku/heroku-buildpack-apt.git +2. https://github.com/DataDog/heroku-buildpack-datadog.git +3. heroku/ruby ``` -Replace `` with your [Datadog API key][6]. -Replace `` with the [Buildpack release][7] you want to use. +## Pinning a specific buildpack version and a specific Datadog Agent version -Once complete, the Datadog Agent is started automatically when each dyno starts. +Heroku recommends to always use the latest commit of a buildpack. If you need to pin the buildpack version, you can do so by specifying the buildpack release tag: -The Datadog Agent provides a listening port on `8125` for statsd/dogstatsd metrics and events. Traces are collected on port `8126`. +``` +heroku buildpacks:add --index 1 https://github.com/DataDog/heroku-buildpack-datadog.git# +``` + +Replace `` with the [Buildpack release][8] you want to use. + +By default, the buildpack pins the latest version of the Datadog Agent at the time of release. You can pin the Agent to an earlier version by setting the `DD_AGENT_VERSION` environment variable. ## Upgrading and slug recompilation -Upgrading this buildpack or modifying certain buildpack options requires you to clear your application's build cache and recompile your slug. +Upgrading this buildpack or modifying certain buildpack options requires you to recompile your slug. The following options require a slug recompilation: @@ -56,49 +83,58 @@ The following options require a slug recompilation: To upgrade this buildpack and/or to change any of these options, for example `DD_AGENT_VERSION`, the following steps are required: ```shell -# Install the Heroku Repo plugin -heroku plugins:install heroku-repo - # Set new version of the Agent -heroku config:set DD_AGENT_VERSION= -a appname - -# Clears Heroku's build cache for "appname" application -heroku repo:purge_cache -a appname +heroku config:set DD_AGENT_VERSION= -a # Rebuild your slug with the new Agent version: -git commit --allow-empty -m "Purge cache" -git push heroku master +git commit --allow-empty -m "Rebuild slug" +git push heroku main ``` ## Configuration -In addition to the environment variables shown above, there are a number of others you can set: +In addition to the environment variables shown above, there are several others you can set: | Setting | Description | |----------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `DD_API_KEY` | *Required.* Your API key is available from the [Datadog API Integrations][6] page. Note that this is the *API* key, not the application key. | +| `DD_API_KEY` | *Required.* Your API key is available from the [Organization Settings -> API Keys][3] page. **Note**: This is the *API* key, not the application key. | | `DD_HOSTNAME` | *Optional.* **WARNING**: Setting the hostname manually may result in metrics continuity errors. It is recommended that you do *not* set this variable. Because dyno hosts are ephemeral it is recommended that you monitor based on the tags `dynoname` or `appname`. | -| `DD_DYNO_HOST` | *Optional.* Set to `true` to use the dyno name (e.g. `web.1` or `run.1234`) as the hostname. See the [hostname section](#hostname) below for more information. Defaults to `false` | -| `DD_TAGS` | *Optional.* Sets additional tags provided as a space-separated string (**Note**: comma-separated string in buildpack versions `1.16` and earlier; this is still supported to maintain backward compatibility). For example, `heroku config:set DD_TAGS="simple-tag-0 tag-key-1:tag-value-1"`. The buildpack automatically adds the tags `dyno` which represent the dyno name (e.g. web.1) and `dynotype` (the type of dyno, e.g `run` or `web`). See the ["Guide to tagging"][8] for more information. | -| `DD_HISTOGRAM_PERCENTILES` | *Optional.* Optionally set additional percentiles for your histogram metrics. See [How to graph percentiles][9]. | +| `DD_DYNO_HOST` | *Optional.* Set to `true` to use the dyno name, such as `web.1` or `run.1234`, as the hostname. See the [hostname section](#hostname) below for more information. Defaults to `false` | +| `DD_TAGS` | *Optional.* Sets additional tags provided as a space-separated string (**Note**: comma-separated string in buildpack versions `1.16` and earlier; this is still supported to maintain backward compatibility). For example, `heroku config:set DD_TAGS="simple-tag-0 tag-key-1:tag-value-1"`. The buildpack automatically adds the tags `dyno` which represent the dyno name, such as `web.1`, and `dynotype` (the type of dyno, e.g `run` or `web`). See the [Guide to tagging][10] for more information. | +| `DD_VERSION` | *Optional.* Sets the version of your application, used to organize traces by version. | +| `DD_HISTOGRAM_PERCENTILES` | *Optional.* Optionally set additional percentiles for your histogram metrics. See [How to graph percentiles][11]. | | `DISABLE_DATADOG_AGENT` | *Optional.* When set, the Datadog Agent does not run. | | `DD_APM_ENABLED` | *Optional.* Trace collection is enabled by default. Set this to `false` to disable trace collection. Changing this option requires recompilation of the slug. Check [the upgrading and slug recompilation section](#upgrading-and-slug-recompilation) for details. | | `DD_PROCESS_AGENT` | *Optional.* The Datadog Process Agent is disabled by default. Set this to `true` to enable the Process Agent. Changing this option requires recompilation of the slug. Check [the upgrading and slug recompilation section](#upgrading-and-slug-recompilation) for details. | | `DD_SITE` | *Optional.* If you use the app.datadoghq.eu service, set this to `datadoghq.eu`. Defaults to `datadoghq.com`. | -| `DD_AGENT_VERSION` | *Optional.* By default, the buildpack installs the latest 6.x version of the Datadog Agent available in the package repository. Use this variable to install older versions of the Datadog Agent (note that not all versions of the Agent may be available). This option takes precedence over `DD_AGENT_MAJOR_VERSION`. Changing this option requires recompiling the slug. Check [the upgrading and slug recompilation section](#upgrading-and-slug-recompilation) for details. | -| `DD_AGENT_MAJOR_VERSION` | *Optional.* By default, the buildpack installs the latest 6.x version of the Datadog Agent available in the package repository. Set this variable to `7` to install the latest 7.x version of the Datadog Agent. Check the [Python versions section](#python-and-agent-versions) for more information on the relation of the agent version and Python version. Changing this option requires recompiling the slug. Check [the upgrading and slug recompilation section](#upgrading-and-slug-recompilation) for details. | +| `DD_AGENT_VERSION` | *Optional.* By default, the buildpack installs the latest 6.x version of the Datadog Agent available in the package repository. Use this variable to install older versions of the Datadog Agent. **Note**: Not all versions of the Agent may be available. This option takes precedence over `DD_AGENT_MAJOR_VERSION`. Changing this option requires recompiling the slug. See [upgrading and slug recompilation](#upgrading-and-slug-recompilation) for details. | +| `DD_AGENT_MAJOR_VERSION` | *Optional.* By default, the buildpack installs the latest 6.x version of the Datadog Agent available in the package repository. Set this variable to `7` to install the latest 7.x version of the Datadog Agent. **Setting this variable to `7` is highly recommended**. Check the [Python versions section](#python-and-agent-versions) for more information on the relation of the Agent version and Python version. Changing this option requires recompiling the slug. See [upgrading and slug recompilation](#upgrading-and-slug-recompilation) for details. | | `DD_DISABLE_HOST_METRICS` | *Optional.* By default, the buildpack reports system metrics for the host machine running the dyno. Set this to `true` to disable system metrics collection. See the [system metrics section](#system-metrics) below for more information. | -| `DD_PYTHON_VERSION` | *Optional.* Starting with version `6.14.0`, Datadog Agent ships with Python versions `2` and `3`. The buildpack will only keep one of the versions. Set this to `2` or `3` to select the Python version you want the agent to keep. If not set, the buildpack will keep `2`. Check the [Python versions section](#python-and-agent-versions) for more information. Changing this option requires recompiling the slug. Check [the upgrading and slug recompilation section](#upgrading-and-slug-recompilation) for details. | +| `DD_PYTHON_VERSION` | *Optional.* Starting with version `6.14.0`, Datadog Agent ships with Python versions `2` and `3`. The buildpack only keeps one of the versions. Set this to `2` or `3` to select the Python version you want the Agent to keep. If not set, the buildpack keeps `2`. Check the [Python versions section](#python-and-agent-versions) for more information. Changing this option requires recompiling the slug. Check [the upgrading and slug recompilation section](#upgrading-and-slug-recompilation) for details. | +| `DD_HEROKU_CONF_FOLDER` | *Optional.* By default, the buildpack looks in the root of your application for a folder `/datadog` for any configuration files you wish to include, see [prerun.sh script](#prerun-script). This location can be overridden by setting this to your desired path. | -For additional documentation, refer to the [Datadog Agent documentation][10]. +For additional documentation, see the [Datadog Agent documentation][12]. ## Hostname -Heroku dynos are ephemeral—they can move to different host machines whenever new code is deployed, configuration changes are made, or resouce needs/availability changes. This makes Heroku flexible and responsive, but can potentially lead to a high number of reported hosts in Datadog. Datadog bills on a per-host basis, and the buildpack default is to report actual hosts, which can lead to higher than expected costs. +Heroku dynos are ephemeral—they can move to different host machines whenever new code is deployed, configuration changes are made, or resource needs/availability changes. This makes Heroku flexible and responsive, but can potentially lead to a high number of reported hosts in Datadog. Datadog bills on a per-host basis, and the buildpack default is to report actual hosts, which can lead to higher than expected costs. + +Depending on your use case, you may want to set your hostname so that hosts are aggregated and report a lower number. To do this, Set `DD_DYNO_HOST` to `true`. This causes the Agent to report the hostname as the app and dyno name (for example `appname.web.1` or `appname.run.1234`) and your host count closely matches your dyno usage. One drawback is that you may see some metrics continuity errors whenever a dyno is cycled. -Depending on your use case, you may want to set your hostname so that hosts are aggregated and report a lower number. To do this, Set `DD_DYNO_HOST` to `true`. This will cause the Agent to report the hostname as the app and dyno name (e.g. `appname.web.1` or `appname.run.1234`) and your host count will closely match your dyno usage. One drawback is that you may see some metrics continuity errors whenever a dyno is cycled. +For this to work correctly, `HEROKU_APP_NAME` needs to be set. The easiest way to do this is by [enabling dyno metadata][13]. **Note**: Dyno metadata is not yet available in Private Spaces, in which case you need to set `HEROKU_APP_NAME` manually. -For this to work correctly, `HEROKU_APP_NAME` needs to be set. The easiest way to do this is by [enabling dyno metadata][11] Take into account that dyno metadata is not yet available in Private Spaces, in which case you will need to set `HEROKU_APP_NAME` manually. +## Disabling the Datadog Agent for short-lived dynos + +By default, the Datadog Agent runs on each of the dynos that are part of the application. This includes `scheduler`, `release` or `run` dynos. In many cases the metrics from these dynos are not needed and it makes sense to disable the Datadog Agent for those. + +To disable the Datadog Agent based on dyno type, add the following snippet to your [prerun.sh script](#prerun-script) (adapting it to the type of dynos you don't want to monitor): + +```shell +# Disable the Datadog Agent based on dyno type +if [ "$DYNOTYPE" == "run" ] || [ "$DYNOTYPE" == "scheduler" ] || [ "$DYNOTYPE" == "release" ]; then + DISABLE_DATADOG_AGENT="true" +fi +``` ## System metrics @@ -106,9 +142,9 @@ By default, the buildpack collects system metrics for the host machine running y In order to collect system metrics for your dynos, you must: -1. Enable the [Heroku Labs: log-runtime-metrics][12]. -2. Use the [Datadog log drain][13] to collect metric logs from the Heroku Logplex and forward them to Datadog. -3. Generate [log-based metric][14] over the collected logs. +1. Enable the [Heroku Labs: log-runtime-metrics][14]. +2. Use the [Datadog log drain][15] to collect metric logs from the Heroku Logplex and forward them to Datadog. +3. Generate [log-based metric][16] over the collected logs. ## File locations @@ -118,31 +154,105 @@ In order to collect system metrics for your dynos, you must: ## Enabling integrations -To enable a [Datadog- integration][15], create a file `/datadog/conf.d/.yaml` in the root of your application. During the dyno start up, your YAML files are copied to the appropriate Datadog Agent configuration directories. +### Enabling the Datadog Redis integration + +If you are using a Redis add-on in your Heroku application (for example, Heroku Data for Redis or Redis Enterprise Cloud), you can enable the Datadog Redis integration by setting an environment variable: + +``` +heroku config:set ENABLE_HEROKU_REDIS=true +``` + +By default, this integration assumes the Redis connection URL is defined in an environment variable called `REDIS_URL` (this is the default configuration for Heroku Data for Redis and other Redis add-ons). + +If your connection URL is defined in a different environment variable, set the `REDIS_URL_VAR` environment variable to the variable name. For example, if you're using Redis Enterprise Cloud, set it to `REDISCLOUD_URL`: + +``` +heroku config:set REDIS_URL_VAR=REDISCLOUD_URL +``` + +### Enabling the Datadog Postgres integration + +If you are using a Postgres add-on in your Heroku application (for example, Heroku Postgres), you can enable the Datadog Postgres integration by setting an environment variable: + +``` +heroku config:set ENABLE_HEROKU_POSTGRES=true +``` + +By default, this integration assumes the Postgres connection URL is defined in an environment variable called `DATABASE_URL` (this is the default configuration for Heroku Postgres and other Postgres add-ons). + +If your connection URL is defined in a different environment variable, set the `POSTGRES_URL_VAR` environment variable to the variable name. + +### Enabling other integrations + +To enable any [Datadog- integration][17]: + +* Create a `datadog/conf.d` folder within your application. +* For each integration to enable, create an `.d` folder +* Under that folder, create a `conf.yaml` with the [configuration for the integration][18]. + +During the dyno start up, your YAML files are copied to the appropriate Datadog Agent configuration directories. -For example, to enable the [Datadog-Redis integration][16], create the file `/datadog/conf.d/redisdb.yaml` at the root of your application: +For example, to enable the [Datadog-Memcache integration][19], add the file `/datadog/conf.d/mcache.d/conf.yaml` at the root of your application (or `/$DD_HEROKU_CONF_FOLDER/conf.d/mcache.d/conf.yaml` if you have changed this [configuration option](#configuration)): ```yaml init_config: instances: + ## @param url - string - required + ## url used to connect to the Memcached instance. + # + - url: localhost +``` + +**Note**: See the sample [mcache.d/conf.yaml][20] for all available configuration options. + +### Community Integrations + +If the integration you are enabling is part of the [Community Integrations][21], install the package as part of the [prerun script](#prerun-script). + +``` +agent-wrapper integration install -t datadog-== +``` - ## @param host - string - required - ## Enter the host to connect to. - # - - host: +For example, to install the [ping integration][22], create the configuration file `datadog/conf.d/ping.d/conf.yaml` and add the following line to your prerun script: - ## @param port - integer - required - ## Enter the port of the host to connect to. - # - port: 6379 ``` +agent-wrapper integration install -t datadog-ping==1.0.0 +``` + +### Disabling integrations based on dynos + +As the filesystem in a Heroku application will be shared by all dynos, if you enable an integration, it will be run on every dyno, including `run` or `worker` dynos. If you want to limit the integration runs based on dyno name or type, you can do that adding a small snippet to the [prerun script](#prerun-script). + +For example, if the Gunicorn integration only needs to run on `web` type dynos, add the following to your prerun script: + +``` +if [ "$DYNOTYPE" != "web" ]; then + rm -f "$DD_CONF_DIR/conf.d/gunicorn.d/conf.yaml" +fi +``` + +## Enabling custom checks + +To enable your own [Agent Custom Checks][23], create a `checks.d` folder in the datadog configuration folder within your application. Under it, copy all `.py` and `.yaml` files from your custom checks. During the dyno start up, your files are copied to the appropriate Datadog Agent configuration directories. + +For example, if you have two custom checks, `foo` and `bar`, this would be the right folder tree: -**Note**: See the sample [redisdb.d/conf.yaml][17] for all available configuration options. +``` +. +└── app + └── datadog + └── checks.d + ├── foo.py + ├── foo.yaml + ├── bar.py + └── bar.yaml + +``` ## Prerun script -In addition to all of the configurations above, you can include a prerun script, `/datadog/prerun.sh`, in your application. The prerun script will run after all of the standard configuration actions and immediately before starting the Datadog Agent. This allows you to modify the environment variables, perform additional configurations, or even disable the Datadog Agent programmatically. +In addition to all of the configurations above, you can include a prerun script, `/datadog/prerun.sh`, in your application. The prerun script runs after all of the standard configuration actions and immediately before starting the Datadog Agent. This allows you to modify the environment variables (for example: DD_TAGS or DD_VERSION), perform additional configurations, install community integrations, or even disable the Datadog Agent programmatically. The example below demonstrates a few of the things you can do in the `prerun.sh` script: @@ -154,17 +264,18 @@ if [ "$DYNOTYPE" == "run" ]; then DISABLE_DATADOG_AGENT="true" fi -# Update the Postgres configuration from above using the Heroku application environment variable -if [ -n "$DATABASE_URL" ]; then - POSTGREGEX='^postgres://([^:]+):([^@]+)@([^:]+):([^/]+)/(.*)$' - if [[ $DATABASE_URL =~ $POSTGREGEX ]]; then - sed -i "s//${BASH_REMATCH[3]}/" "$DD_CONF_DIR/conf.d/postgres.d/conf.yaml" - sed -i "s//${BASH_REMATCH[1]}/" "$DD_CONF_DIR/conf.d/postgres.d/conf.yaml" - sed -i "s//${BASH_REMATCH[2]}/" "$DD_CONF_DIR/conf.d/postgres.d/conf.yaml" - sed -i "s//${BASH_REMATCH[4]}/" "$DD_CONF_DIR/conf.d/postgres.d/conf.yaml" - sed -i "s//${BASH_REMATCH[5]}/" "$DD_CONF_DIR/conf.d/postgres.d/conf.yaml" - fi +# Disable integrations based on dyno type +if [ "$DYNOTYPE" != "web" ]; then + rm -f "$DD_CONF_DIR/conf.d/gunicorn.d/conf.yaml" fi + +# Set app version based on HEROKU_SLUG_COMMIT +if [ -n "$HEROKU_SLUG_COMMIT" ]; then + DD_VERSION=$HEROKU_SLUG_COMMIT +fi + +# Install the "ping" community integration +agent-wrapper integration install -t datadog-ping==1.0.0 ``` ## Limiting Datadog's console output @@ -185,7 +296,7 @@ To reduce your slug size, make sure that `DD_APM_ENABLED` is set to `false`, if ## Debugging -To run any of the information/debugging commands listed in the [Agent's documentation][18] use the `agent-wrapper` command. +To run any of the [information or debugging commands][24], use the `agent-wrapper` command. For example, to display the status of your Datadog Agent and enabled integrations, run: @@ -195,30 +306,46 @@ agent-wrapper status ## Python and Agent versions -Prior to version `6.14` the Datadog v6 agent shipped with Python version `2` embedded. Starting with `6.14`, and in preparation for Python version `2` End Of Life, announced for January 2020, the Datadog v6 agent ships with both Python versions `2` and `3`, to give customers enough time to migrate their custom checks to Python version `3`. The Heroku buildpack will only keep one of the versions. Set `DD_PYTHON_VERSION` to `2` or `3` to select the Python version you want the agent to keep. If not set, the buildpack will keep Python version `2`. If you are using custom checks that only work with Python version `2`, we recommend to migrate them to version `3` before its EOL. +Prior to version `6.14` the Datadog v6 Agent shipped with Python version `2` embedded. Starting with `6.14`, and in preparation for Python version `2` End Of Life, announced for January 2020, the Datadog v6 Agent ships with both Python versions `2` and `3`, to give customers enough time to migrate their custom checks to Python version `3`. The Heroku buildpack only keeps one of the versions. Set `DD_PYTHON_VERSION` to `2` or `3` to select the Python version you want the Agent to keep. If not set, the buildpack keeps Python version `2`. If you are using custom checks that only work with Python version `2`, migrate them to version `3` before its EOL. -Agent v7 only ships with Python version `3`. If you are not using custom checks or your custom checks are already migrated to version `3`, we recommend moving to Agent 7 as soon as possible. Starting with `6.15`, v7 releases with the same minor version share the same feature set, making it safe to move between those two. For example, if you are running `6.16` and you don't need Python version `2`, it is safe to jump to `7.16`. +Agent v7 only ships with Python version `3`. If you are not using custom checks or your custom checks are already migrated to version `3`, move to Agent v7 as soon as possible. Starting with `6.15`, v7 releases with the same minor version share the same feature set, making it safe to move between those two. For example, if you are running `6.16` and you don't need Python version `2`, it is safe to jump to `7.16`. ## Heroku log collection -The Datadog buildpack does not collect logs from the Heroku platform. To set up Heroku log collection, see the [dedicated guide][13]. +The Datadog buildpack does not collect logs from the Heroku platform. To set up Heroku log collection, see the [dedicated guide][15]. ## Using Heroku with Docker images -This buildpack only works for Heroku deployments that use [Heroku's Slug Compiler][19]. If you are deploying your application in Heroku using Docker containers you will need to add the Datadog agent as part of your Docker image and start the agent as a different process in your container. +This buildpack only works for Heroku deployments that use [Heroku's Slug Compiler][25]. If you are deploying your application in Heroku using Docker containers: -As an example, if you are building your Docker image using a Debian based OS, you will need to add the following lines to your `Dockerfile`: +1. Add the Datadog Agent as part of your Docker image and start the Agent as a different process in your container. +2. Set the following configuration option in your Heroku application, to ensure that Datadog reports it correctly as a Heroku dyno: +```shell +heroku config:add DD_HEROKU_DYNO=true ``` -# Install GPG dependencies -RUN apt-get update \ - && apt-get install -y gpg apt-transport-https gpg-agent curl ca-certificates -# Add Datadog repository and signing key -RUN sh -c "echo 'deb https://apt.datadoghq.com/ stable 7' > /etc/apt/sources.list.d/datadog.list" -RUN apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 A2923DFF56EDA6E76E55E492D3A80E30382E94DE +As an example, if you are building your Docker image using a Debian based OS, add the following lines to your `Dockerfile`: -# Install the Datadog agent +``` +# Install GPG dependencies +RUN apt-get update \ + && apt-get install -y gnupg apt-transport-https gpg-agent curl ca-certificates + +# Add Datadog repository and signing keys +ENV DATADOG_APT_KEYRING="/usr/share/keyrings/datadog-archive-keyring.gpg" +ENV DATADOG_APT_KEYS_URL="https://keys.datadoghq.com" +RUN sh -c "echo 'deb [signed-by=${DATADOG_APT_KEYRING}] https://apt.datadoghq.com/ stable 7' > /etc/apt/sources.list.d/datadog.list" +RUN touch ${DATADOG_APT_KEYRING} +RUN curl -o /tmp/DATADOG_APT_KEY_CURRENT.public "${DATADOG_APT_KEYS_URL}/DATADOG_APT_KEY_CURRENT.public" && \ + gpg --ignore-time-conflict --no-default-keyring --keyring ${DATADOG_APT_KEYRING} --import /tmp/DATADOG_APT_KEY_CURRENT.public +RUN curl -o /tmp/DATADOG_APT_KEY_F14F620E.public "${DATADOG_APT_KEYS_URL}/DATADOG_APT_KEY_F14F620E.public" && \ + gpg --ignore-time-conflict --no-default-keyring --keyring ${DATADOG_APT_KEYRING} --import /tmp/DATADOG_APT_KEY_F14F620E.public +RUN curl -o /tmp/DATADOG_APT_KEY_382E94DE.public "${DATADOG_APT_KEYS_URL}/DATADOG_APT_KEY_382E94DE.public" && \ + gpg --ignore-time-conflict --no-default-keyring --keyring ${DATADOG_APT_KEYRING} --import /tmp/DATADOG_APT_KEY_382E94DE.public + + +# Install the Datadog Agent RUN apt-get update && apt-get -y --force-yes install --reinstall datadog-agent # Copy entrypoint @@ -233,7 +360,7 @@ COPY datadog-config/ /etc/datadog-agent/ CMD ["/entrypoint.sh"] ``` -In your Docker container entry point you will to start the Datadog Agent, the Datadog APM agent and the Datadog process agent: +In your Docker container entry point, start the Datadog Agent, Datadog APM Agent, and Datadog Process Agent: ``` #!/bin/bash @@ -243,47 +370,162 @@ datadog-agent run & /opt/datadog-agent/embedded/bin/process-agent --config=/etc/datadog-agent/datadog.yaml ``` -For more advanced options in the Docker image, reference the [Datadog Agent Docker files][20]. +For more advanced options in the Docker image, reference the [Datadog Agent Docker files][26]. ## Contributing -See the [contributing documentation][21] to learn how to open an issue or PR to the [Heroku-buildpack-datadog repository][22]. +See the [contributing guidelines][27] to learn how to open an issue or PR to the [Heroku-buildpack-datadog repository][28]. ## History -Earlier versions of this project were forked from the [miketheman heroku-buildpack-datadog project][23]. It was largely rewritten for Datadog's Agent version 6. Changes and more information can be found in the [changelog][24]. +Earlier versions of this project were forked from the [miketheman heroku-buildpack-datadog project][29]. It was largely rewritten for Datadog's Agent version 6. Changes and more information can be found in the [changelog][30]. + +## Troubleshooting + +### Getting the Agent status + +If you have set up the buildpack and you are not getting some of the data you expect in Datadog, you can run the status command for the Datadog Agent to help you find the cause. + +```shell +# Export the name of your Heroku application as an environment variable +export APPNAME=your-application-name + +heroku ps:exec -a $APPNAME + +# Establishing credentials... done +# Connecting to web.1 on ⬢ ruby-heroku-datadog... +# DD_API_KEY environment variable not set. Run: heroku config:add DD_API_KEY= +# The Datadog Agent has been disabled. Unset the DISABLE_DATADOG_AGENT or set missing environment variables. + +~ $ +``` + +You can ignore the warnings about DD_API_KEY not being set. While [Heroku doesn't set configuration variables for the SSH session itself](https://devcenter.heroku.com/articles/exec#environment-variables), the Datadog Agent process is able to access them. + +Once inside the SSH session, execute the Datadog status command. + +```shell +~ $ agent-wrapper status + +Getting the status from the agent. + +=============== +Agent (v7.27.0) +=============== + +[...] + +``` + +### Debugging -## FAQs / Troubleshooting +#### No data in Datadog + +Make sure that the `status` command runs correctly and that this section of the output tells you that your API key is valid: + +``` + API Keys status + =============== + API key ending with 68306: API Key valid +``` + +#### Check integrations + +To check if the integration you have enabled is running correctly, focus on the `Collector` section and verify that your check is running correctly: + +``` +========= +Collector +========= + + Running Checks + ============== + +[...] + postgres (5.4.0) + ---------------- + Instance ID: postgres:e07ef94b907fe733 [OK] + Configuration Source: file:/app/.apt/etc/datadog-agent/conf.d/postgres.d/conf.yaml + Total Runs: 4,282 + Metric Samples: Last Run: 15, Total: 64,230 + Events: Last Run: 0, Total: 0 + Service Checks: Last Run: 1, Total: 4,282 + Average Execution Time : 43ms + Last Execution Date : 2021-05-13 08:15:46 UTC (1620893746000) + Last Successful Execution Date : 2021-05-13 08:15:46 UTC (1620893746000) + metadata: + version.major: 13 + version.minor: 2 + version.patch: 0 + version.raw: 13.2 (Ubuntu 13.2-1.pgdg20.04+1) + version.scheme: semver +``` + +#### Check APM agent + +If you have instrumented your application for APM and are not getting traces in Datadog, you can check that the APM Agent is running correctly and collecting traces: + +``` +[...] +========= +APM Agent +========= + Status: Running + Pid: 63 + Uptime: 64702 seconds + Mem alloc: 10,331,128 bytes + Hostname: ruby-heroku-datadog.web.1 + Receiver: localhost:8126 + Endpoints: + https://trace.agent.datadoghq.com + + Receiver (previous minute) + ========================== + From ruby 2.6.6 (ruby-x86_64-linux), client 0.48.0 + Traces received: 11 (14,181 bytes) + Spans received: 33 + + Default priority sampling rate: 100.0% + Priority sampling rate for 'service:ruby-heroku-datadog,env:': 100.0% + Priority sampling rate for 'service:ruby-heroku-datadog,env:development': 100.0% + +[...] +``` -### Datadog is reporting a higher number of agents than dynos +### Datadog is reporting a higher number of Agents than dynos Make sure you have `DD_DYNO_HOST` set to `true` and that `HEROKU_APP_NAME` has a value set for every Heroku application. See the [Hostname section](#hostname) for details. -### After upgrading the buildpack or the agent, the agent is reporting errors when starting up +### After upgrading the buildpack or the Agent, the Agent is reporting errors when starting up -After an upgrade of the buildpack or agent, you must clear your build cache and recompile your application's slug. Check [the upgrading and slug recompilation section](#upgrading-and-slug-recompilation) for details. +After an upgrade of the buildpack or Agent, you must recompile your application's slug. Check [the upgrading and slug recompilation section](#upgrading-and-slug-recompilation) for details. [1]: https://devcenter.heroku.com/articles/buildpacks [2]: https://docs.datadoghq.com/libraries -[3]: https://github.com/heroku/heroku-buildpack-apt -[4]: https://github.com/jontewks/puppeteer-heroku-buildpack -[5]: https://github.com/lstoll/heroku-buildpack-monorepo -[6]: https://app.datadoghq.com/account/settings#api -[7]: https://github.com/DataDog/heroku-buildpack-datadog/releases -[8]: https://docs.datadoghq.com/tagging/ -[9]: https://docs.datadoghq.com/dashboards/guide/how-to-graph-percentiles-in-datadog/ -[10]: https://docs.datadoghq.com/agent -[11]: https://devcenter.heroku.com/articles/dyno-metadata -[12]: https://devcenter.heroku.com/articles/log-runtime-metrics -[13]: https://docs.datadoghq.com/logs/guide/collect-heroku-logs -[14]: https://docs.datadoghq.com/logs/logs_to_metrics/ -[15]: https://docs.datadoghq.com/integrations/ -[16]: https://docs.datadoghq.com/integrations/redisdb/ -[17]: https://github.com/DataDog/integrations-core/blob/master/redisdb/datadog_checks/redisdb/data/conf.yaml.example -[18]: https://docs.datadoghq.com/agent/guide/agent-commands/#agent-status-and-information -[19]: https://devcenter.heroku.com/articles/slug-compiler -[20]: https://github.com/DataDog/datadog-agent/tree/master/Dockerfiles -[21]: https://github.com/DataDog/heroku-buildpack-datadog/blob/master/CONTRIBUTING.md -[22]: https://github.com/DataDog/heroku-buildpack-datadog -[23]: https://github.com/miketheman/heroku-buildpack-datadog -[24]: https://github.com/DataDog/heroku-buildpack-datadog/blob/master/CHANGELOG.md +[3]: https://app.datadoghq.com/organization-settings/api-keys +[4]: https://devcenter.heroku.com/articles/using-multiple-buildpacks-for-an-app#viewing-buildpacks +[5]: https://github.com/heroku/heroku-buildpack-apt +[6]: https://github.com/jontewks/puppeteer-heroku-buildpack +[7]: https://github.com/lstoll/heroku-buildpack-monorepo +[8]: https://github.com/DataDog/heroku-buildpack-datadog/releases +[10]: https://docs.datadoghq.com/tagging/ +[11]: https://docs.datadoghq.com/dashboards/guide/how-to-graph-percentiles-in-datadog/ +[12]: https://docs.datadoghq.com/agent +[13]: https://devcenter.heroku.com/articles/dyno-metadata +[14]: https://devcenter.heroku.com/articles/log-runtime-metrics +[15]: https://docs.datadoghq.com/logs/guide/collect-heroku-logs +[16]: https://docs.datadoghq.com/logs/logs_to_metrics/ +[17]: https://docs.datadoghq.com/integrations/ +[18]: https://docs.datadoghq.com/getting_started/integrations/#configuring-agent-integrations +[19]: https://docs.datadoghq.com/integrations/mcache/ +[20]: https://github.com/DataDog/integrations-core/blob/master/mcache/datadog_checks/mcache/data/conf.yaml.example +[21]: https://github.com/DataDog/integrations-extras/ +[22]: https://github.com/DataDog/integrations-extras/tree/master/ping +[23]: https://docs.datadoghq.com/developers/custom_checks/ +[24]: https://docs.datadoghq.com/agent/guide/agent-commands/#agent-status-and-information +[25]: https://devcenter.heroku.com/articles/slug-compiler +[26]: https://github.com/DataDog/datadog-agent/tree/master/Dockerfiles +[27]: https://github.com/DataDog/heroku-buildpack-datadog/blob/master/CONTRIBUTING.md +[28]: https://github.com/DataDog/heroku-buildpack-datadog +[29]: https://github.com/miketheman/heroku-buildpack-datadog +[30]: https://github.com/DataDog/heroku-buildpack-datadog/blob/master/CHANGELOG.md diff --git a/bin/compile b/bin/compile index d5474ad..04866cb 100644 --- a/bin/compile +++ b/bin/compile @@ -11,8 +11,8 @@ set -o pipefail # set -x # Set agent pinned version -DD_AGENT_PINNED_VERSION_6="6.19.0-1" -DD_AGENT_PINNED_VERSION_7="7.19.0-1" +DD_AGENT_PINNED_VERSION_6="6.43.0-1" +DD_AGENT_PINNED_VERSION_7="7.43.0-1" # Parse and derive params BUILD_DIR=$1 @@ -20,6 +20,43 @@ CACHE_DIR=$2 ENV_DIR=$3 BUILDPACK_DIR=$(cd "$(dirname "$0")"; cd ..; pwd) +# Store which STACK we are running on in the cache to bust the cache if it changes +if [ -f $CACHE_DIR/.apt/STACK ]; then + CACHED_STACK=$(cat "$CACHE_DIR/.apt/STACK") +else + CACHED_STACK=$STACK +fi + +# Ensure we store the STACK in the cache for next time. +mkdir -p "$CACHE_DIR/.apt" +echo "$STACK" > "$CACHE_DIR/.apt/STACK" + +# If a version hasn't been specified, use the pinned version +if [ -f "$ENV_DIR/DD_AGENT_VERSION" ]; then + DD_AGENT_VERSION=$(cat "$ENV_DIR/DD_AGENT_VERSION") +else + if [ -f "$ENV_DIR/DD_AGENT_MAJOR_VERSION" ]; then + DD_AGENT_MAJOR_VERSION=$(cat "$ENV_DIR/DD_AGENT_MAJOR_VERSION") + if [ "$DD_AGENT_MAJOR_VERSION" == "7" ]; then + DD_AGENT_VERSION="$DD_AGENT_PINNED_VERSION_7" + else + DD_AGENT_VERSION="$DD_AGENT_PINNED_VERSION_6" + fi + else + DD_AGENT_VERSION="$DD_AGENT_PINNED_VERSION_6" + fi +fi + +# Store which Datadog agent we deployed in the previous compile to bust the cache if it changes +if [ -f $CACHE_DIR/.apt/DD_AGENT_VERSION ]; then + CACHED_DD_AGENT_VERSION=$(cat "$CACHE_DIR/.apt/DD_AGENT_VERSION") +else + CACHED_DD_AGENT_VERSION=$DD_AGENT_VERSION +fi + +# Ensure we store the agent version in the cache for next time. +echo "$DD_AGENT_VERSION" > "$CACHE_DIR/.apt/DD_AGENT_VERSION" + # Load formating tools source "$BUILDPACK_DIR/bin/common.sh" @@ -36,62 +73,63 @@ mkdir -p "$APT_CACHE_DIR/archives/partial" mkdir -p "$APT_STATE_DIR/lists/partial" mkdir -p "$APT_DIR" -# Install dependencies -topic "Updating apt caches for dependencies" -apt-get $APT_OPTIONS update | indent - -topic "Installing dependencies" -DEPS="libpci-dev libpci3 libsensors4 libsensors4-dev libsnmp-base libsnmp30" -apt-get $APT_OPTIONS -y --force-yes -d install --reinstall --no-install-recommends $DEPS | indent -IFS=" " read -a DEP_PKGS <<< "$DEPS" -for DEP in ${DEP_PKGS[@]}; do - echo "Installing $DEP" | indent - ls -t "$APT_CACHE_DIR"/archives/"$DEP"\_*.deb | head -1 | xargs -i dpkg -x '{}' "$APT_DIR" -done +if [[ $CACHED_STACK == $STACK ]] && [[ $CACHED_DD_AGENT_VERSION == $DD_AGENT_VERSION ]]; then + # STACK nor DD_AGENT_VERSION have changed, reusing cache + topic "Stack version and agent version haven't changed, reusing cache" +else + # STACK or DD_AGENT_VERSION changed, clean up APT cache + topic "Detected Stack and/or agent version changes, flushing cache" + rm -rf $APT_CACHE_DIR + rm -rf $APT_STATE_DIR + mkdir -p "$APT_CACHE_DIR/archives/partial" + mkdir -p "$APT_STATE_DIR/lists/partial" +fi # Install GPG key topic "Install gpg key for Datadog APT Repository" -APT_KEYRING="$CACHE_DIR/apt/trusted.gpg" -GPG_KEY_FILE="$BUILDPACK_DIR/etc/datadog.gpg" +DATADOG_APT_KEYRING="$BUILDPACK_DIR/datadog-archive-keyring.gpg" +DATADOG_APT_KEYS=("DATADOG_APT_KEY_CURRENT.public" "DATADOG_APT_KEY_F14F620E.public" "DATADOG_APT_KEY_382E94DE.public") +DATADOG_APT_KEYS_URL="https://keys.datadoghq.com" GPG_HOME_DIR="$BUILD_DIR/.gnupg" mkdir -p "$GPG_HOME_DIR" -gpg --ignore-time-conflict --no-options --no-default-keyring --homedir "$GPG_HOME_DIR" --keyring "$APT_KEYRING" --import "$GPG_KEY_FILE" | indent +touch $DATADOG_APT_KEYRING -# If a version hasn't been specified, use the pinned version -if [ -f "$ENV_DIR/DD_AGENT_VERSION" ]; then - DD_AGENT_VERSION=$(cat "$ENV_DIR/DD_AGENT_VERSION") -else - if [ -f "$ENV_DIR/DD_AGENT_MAJOR_VERSION" ]; then - DD_AGENT_MAJOR_VERSION=$(cat "$ENV_DIR/DD_AGENT_MAJOR_VERSION") - if [ "$DD_AGENT_MAJOR_VERSION" == "7" ]; then - DD_AGENT_VERSION="$DD_AGENT_PINNED_VERSION_7" - else - DD_AGENT_VERSION="$DD_AGENT_PINNED_VERSION_6" - fi - else - DD_AGENT_VERSION="$DD_AGENT_PINNED_VERSION_6" - fi -fi +for key in "${DATADOG_APT_KEYS[@]}"; do + curl -o "/tmp/${key}" "${DATADOG_APT_KEYS_URL}/${key}" | indent + gpg --ignore-time-conflict --no-options --no-default-keyring --homedir "$GPG_HOME_DIR" --keyring "$DATADOG_APT_KEYRING" --import "/tmp/${key}" | indent +done # Prior to Agent 6.14 there was only 1 python version DD_AGENT_BASE_VERSION="6.14" if [ "$DD_AGENT_VERSION" == "$(echo -e "$DD_AGENT_BASE_VERSION\n$DD_AGENT_VERSION" | sort -V | head -n1)" ]; then - NUM_PYTHON="1" + DD_PYTHON_VERSION="2" else - NUM_PYTHON="2" + if [ -f "$ENV_DIR/DD_PYTHON_VERSION" ]; then + DD_PYTHON_VERSION=$(cat "$ENV_DIR/DD_PYTHON_VERSION") + if [ "$DD_PYTHON_VERSION" != "2" ] && [ "$DD_PYTHON_VERSION" != "3" ]; then + topic "ERROR: Wrong Python version: \"$DD_PYTHON_VERSION\"." + echo "Set DD_PYTHON_VERSION to either 2 or 3." | indent + exit 1 + fi + else + DD_PYTHON_VERSION="2" # if not specified, we default to Python 2 + fi fi # Agent 7 onwards is Python3 only and repo file is different DD_AGENT_BASE_VERSION="7" if [ "$DD_AGENT_VERSION" != "$(echo -e "$DD_AGENT_BASE_VERSION\n$DD_AGENT_VERSION" | sort -V | head -n1)" ]; then - NUM_PYTHON="1" + DD_PYTHON_VERSION="3" # Modify repo file to point to agent 7 cp "$APT_REPO_FILE_7" "$APT_REPO_FILE" fi +# Replace the placeholder in the source file by the actual path to the constructed keyring +sed -i "s|SIGNED_BY_PLACEHOLDER|${DATADOG_APT_KEYRING}|" $APT_REPO_FILE + # Install Datadog Agent topic "Updating apt caches for Datadog Agent" -APT_OPTIONS="$APT_OPTIONS -o Dir::Etc::Trusted=$APT_KEYRING -o Dir::Etc::SourceList=$APT_REPO_FILE" +APT_OPTIONS="$APT_OPTIONS -o Dir::Etc::SourceList=$APT_REPO_FILE" apt-get $APT_OPTIONS update | indent # Accommodate for earlier pinned versions. Give deprecation warning. @@ -104,22 +142,32 @@ fi AGENT_VERSIONS=$(apt-cache $APT_OPTIONS show datadog-agent | grep "Version: ") AGENT_VERSIONS=$(sed 's/Version: 1://g' <<<"$AGENT_VERSIONS") - -# If specified version doesn't exist, list available versions. -if [ -z $(echo "$AGENT_VERSIONS" | grep -x "$DD_AGENT_VERSION") ]; then - topic "ERROR: Version \"$DD_AGENT_VERSION\" was not found." - echo "Available versions:" | indent - echo "$AGENT_VERSIONS" | indent - exit 1 +AGENT_HEROKU_VERSIONS=$(apt-cache $APT_OPTIONS show datadog-heroku-agent | grep "Version: ") +AGENT_HEROKU_VERSIONS=$(sed 's/Version: 1://g' <<<"$AGENT_HEROKU_VERSIONS") + +PACKAGE_NAME="datadog-heroku-agent" + +# If specified version doesn't exist as heroku build, try regular agent +if [ -z $(echo "$AGENT_HEROKU_VERSIONS" | grep -x "$DD_AGENT_VERSION") ]; then + # If specified version doesn't exist as regular build either, err and quit + if [ -z $(echo "$AGENT_VERSIONS" | grep -x "$DD_AGENT_VERSION") ]; then + topic "ERROR: Version \"$DD_AGENT_VERSION\" was not found." + echo "Available Heroku versions:" | indent + echo "$AGENT_HEROKU_VERSIONS" | indent + echo "Available regular Agent versions:" | indent + echo "$AGENT_VERSIONS" | indent + exit 1 + fi + PACKAGE_NAME="datadog-agent" fi # Set the specified version. -PACKAGE="datadog-agent=1:$DD_AGENT_VERSION" +PACKAGE="$PACKAGE_NAME=1:$DD_AGENT_VERSION" topic "Downloading Datadog Agent $DD_AGENT_VERSION" apt-get $APT_OPTIONS -y --force-yes -d install --reinstall --no-install-recommends "$PACKAGE" | indent -DPKG_STUB="$APT_CACHE_DIR/archives/datadog-agent_1%3a" +DPKG_STUB="$APT_CACHE_DIR/archives/${PACKAGE_NAME}_1%3a" if [ -z $DD_AGENT_VERSION ]; then DEB=$(ls -t "$DPKG_STUB"*.deb | head -n 1) DD_AGENT_VERSION=${DEB:${#DPKG_STUB}:(${#DEB}-${#DPKG_STUB}-10)} @@ -134,11 +182,20 @@ dpkg -x "$DEB" "$APT_DIR" # Removing unneeded content rm -rf "$APT_DIR"/opt/datadog-agent/sources \ "$APT_DIR"/opt/datadog-agent/embedded/share/doc \ - "$APT_DIR"/opt/datadog-agent/embedded/share/man + "$APT_DIR"/opt/datadog-agent/embedded/share/man \ + "$APT_DIR"/opt/datadog-agent/embedded/.installed_by_pkg.txt \ + "$DEB" # Remove Cryptodome Selftest rm -rf "$APT_DIR"/opt/datadog-agent/embedded/lib/python*/site-packages/Cryptodome/SelfTest +# Remove unused botocore data +for i in `ls $APT_DIR/opt/datadog-agent/embedded/lib/python*/site-packages/botocore/data`; do + if [ "$i" != "s3" ]; then + rm -rf "$APT_DIR"/opt/datadog-agent/embedded/lib/python*/site-packages/botocore/data/"$i" + fi +done + # Remove unnedded Python packages for i in "${DELETE_PACKAGES[@]}"; do rm -rf "$APT_DIR"/opt/datadog-agent/embedded/lib/python*/site-packages/"$i" @@ -146,10 +203,22 @@ done # Remove the system-probe binary, only needed for network performance monitoring rm -rf "$APT_DIR/opt/datadog-agent/embedded/bin/system-probe" +rm -rf "$APT_DIR/opt/datadog-agent/embedded/bin/clang-bpf" +rm -rf "$APT_DIR/opt/datadog-agent/embedded/bin/llc-bpf" +rm -rf "$APT_DIR"/opt/datadog-agent/embedded/lib/libbcc* +rm -rf "$APT_DIR"/opt/datadog-agent/embedded/nikos/ + +# Remove static libraries +rm -rf "$APT_DIR"/opt/datadog-agent/embedded/lib/*.a +rm -rf "$APT_DIR"/opt/datadog-agent/embedded/lib/python*/config*/*.a + +# Remove the Security agent +rm -rf "$APT_DIR/opt/datadog-agent/embedded/bin/security-agent" if [ -f "$ENV_DIR/DD_APM_ENABLED" ]; then DD_APM_ENABLED=$(cat "$ENV_DIR/DD_APM_ENABLED") if [ "$DD_APM_ENABLED" == "false" ]; then + topic "DD_APM_ENABLED set to false. Removing the trace agent." rm -rf "$APT_DIR/opt/datadog-agent/embedded/bin/trace-agent" fi fi @@ -158,46 +227,35 @@ fi if [ -f "$ENV_DIR/DD_PROCESS_AGENT" ]; then DD_PROCESS_AGENT=$(cat "$ENV_DIR/DD_PROCESS_AGENT") if [ "$DD_PROCESS_AGENT" == "false" ]; then + topic "DD_PROCESS_AGENT set to false. Removing the process agent." rm -rf "$APT_DIR/opt/datadog-agent/embedded/bin/process-agent" fi else + topic "DD_PROCESS_AGENT not set. Removing the process agent." rm -rf "$APT_DIR/opt/datadog-agent/embedded/bin/process-agent" fi -# If we have 2 python versions, we remove the one that wasn't selected -if [ "$NUM_PYTHON" = "2" ]; then - if [ -f "$ENV_DIR/DD_PYTHON_VERSION" ]; then - DD_PYTHON_VERSION=$(cat "$ENV_DIR/DD_PYTHON_VERSION") - if [ "$DD_PYTHON_VERSION" != "2" ] && [ "$DD_PYTHON_VERSION" != "3" ]; then - topic "ERROR: Wrong Python version: \"$DD_PYTHON_VERSION\"." - echo "Set DD_PYTHON_VERSION to either 2 or 3." | indent - exit 1 - fi - else - DD_PYTHON_VERSION="2" # if not specified, we default to Python 2 - fi - - # We remove the unneeded version of Python - if [ "$DD_PYTHON_VERSION" = "2" ]; then - topic "*********************************** WARNING ************************************" - echo "Python 2 will be deprecated soon. Agent 7.x ships with Python 3 only." | indent - echo "If you don't run custom checks or those are Python 3 ready, you can" | indent - echo "move to Python 3 now by setting DD_PYTHON_VERSION to 3 and compiling your slug." | indent - echo "********************************************************************************" | indent - rm -rf "$APT_DIR"/opt/datadog-agent/embedded/lib/python3.* - rm -rf "$APT_DIR"/opt/datadog-agent/embedded/lib/libpython3* - rm "$APT_DIR"/opt/datadog-agent/embedded/bin/pip3* - rm "$APT_DIR"/opt/datadog-agent/embedded/bin/python3* - rm "$APT_DIR"/opt/datadog-agent/embedded/bin/pydoc3* - fi - if [ "$DD_PYTHON_VERSION" = "3" ]; then - rm -rf "$APT_DIR"/opt/datadog-agent/embedded/lib/python2.* - rm -rf "$APT_DIR"/opt/datadog-agent/embedded/lib/libpython2* - rm "$APT_DIR"/opt/datadog-agent/embedded/bin/pip2* - rm "$APT_DIR"/opt/datadog-agent/embedded/bin/python2* - rm "$APT_DIR"/opt/datadog-agent/embedded/bin/pydoc* - fi +# We remove the unneeded version of Python +if [ "$DD_PYTHON_VERSION" = "2" ]; then + topic "*********************************** WARNING ************************************" + echo "Python 2 will be deprecated soon. Agent 7.x ships with Python 3 only." | indent + echo "If you don't run custom checks or those are Python 3 ready, you can" | indent + echo "move to Python 3 now by setting DD_PYTHON_VERSION to 3 and compiling your slug." | indent + echo "********************************************************************************" | indent + rm -rf "$APT_DIR"/opt/datadog-agent/embedded/lib/python3.* || true + rm -rf "$APT_DIR"/opt/datadog-agent/embedded/lib/libpython3* || true + rm -f "$APT_DIR"/opt/datadog-agent/embedded/bin/pip3* || true + rm -f "$APT_DIR"/opt/datadog-agent/embedded/bin/python3* || true + rm -f "$APT_DIR"/opt/datadog-agent/embedded/bin/pydoc3* || true fi +if [ "$DD_PYTHON_VERSION" = "3" ]; then + rm -rf "$APT_DIR"/opt/datadog-agent/embedded/lib/python2.* || true + rm -rf "$APT_DIR"/opt/datadog-agent/embedded/lib/libpython2* || true + rm -f "$APT_DIR"/opt/datadog-agent/embedded/bin/pip2* || true + rm -f "$APT_DIR"/opt/datadog-agent/embedded/bin/python2* || true + rm -f "$APT_DIR"/opt/datadog-agent/embedded/bin/pydoc* || true +fi + # Rewrite package-config files find "$APT_DIR" -type f -ipath '*/pkgconfig/*.pc' | xargs --no-run-if-empty -n 1 sed -i -e 's!^prefix=\(.*\)$!prefix='"$APT_DIR"'\1!g' diff --git a/bin/detect b/bin/detect index 343199d..183373a 100644 --- a/bin/detect +++ b/bin/detect @@ -1,4 +1,4 @@ #!/usr/bin/env bash # bin/detect -echo "Sysstat" && exit 0 +echo "Datadog" && exit 0 diff --git a/etc/datadog.gpg b/etc/datadog.gpg deleted file mode 100644 index c47b876..0000000 --- a/etc/datadog.gpg +++ /dev/null @@ -1,127 +0,0 @@ ------BEGIN PGP PUBLIC KEY BLOCK----- -Version: SKS 1.1.6 - -mQINBFd0KRUBEACr4s2I9/iXtRYQas0ux+OmQ6PUuPVxYT8nBTnqQV8HTlpigUUZVRXDKH6/ -XEl5gIU3vjh8i0GTZ+F4bB0pE+nwOjuM4F7SDE5JvYd75EfKvyqJs7PKTgVaSGLs6b8t95ma -jWw6Svmh/IbP7TiDe/hxdcucQ3VeF/ufdySuPsUI+EAamNy+IqBGRTlmxk1vGcW8vHh1TNZV -hoA98HQbqTqXqEq051r2AENX/kR/5xowhc0s2JN3zbXSXpSN5rulqHzJ41kaL7DVQJmRmvn9 -t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M+8ZHCYJ -=VSVF ------END PGP PUBLIC KEY BLOCK----- diff --git a/etc/datadog.list b/etc/datadog.list index 40bb38b..fab8e6f 100644 --- a/etc/datadog.list +++ b/etc/datadog.list @@ -1,3 +1 @@ -# We're using insecure http here. Eventually we should fix -# the apt-transport-https issue. -deb [trusted=yes] http://apt.datadoghq.com/ stable 6 +deb [signed-by=SIGNED_BY_PLACEHOLDER] https://apt.datadoghq.com/ stable 6 diff --git a/etc/datadog7.list b/etc/datadog7.list index 809d13d..ce8b852 100644 --- a/etc/datadog7.list +++ b/etc/datadog7.list @@ -1,3 +1 @@ -# We're using insecure http here. Eventually we should fix -# the apt-transport-https issue. -deb [trusted=yes] http://apt.datadoghq.com/ stable 7 +deb [signed-by=SIGNED_BY_PLACEHOLDER] https://apt.datadoghq.com/ stable 7 diff --git a/extra/agent-wrapper b/extra/agent-wrapper index 35b649f..4787971 100644 --- a/extra/agent-wrapper +++ b/extra/agent-wrapper @@ -1,4 +1,6 @@ #!/usr/bin/env bash -# Run the Datadog Agent with the selected command -bash -c "PYTHONPATH=\"$DD_PYTHONPATH\" LD_LIBRARY_PATH=\"$DD_LD_LIBRARY_PATH\" $DD_BIN_DIR/agent -c $DATADOG_CONF "$@" " +# Run the Datadog Agent with the selected command +export PYTHONPATH="$DD_PYTHONPATH" +export LD_LIBRARY_PATH="$DD_LD_LIBRARY_PATH" +exec "$DD_BIN_DIR"/agent -c "$DATADOG_CONF" $* diff --git a/extra/datadog.sh b/extra/datadog.sh index 7e48212..b5bd1be 100644 --- a/extra/datadog.sh +++ b/extra/datadog.sh @@ -8,7 +8,11 @@ DD_RUN_DIR="$DD_DIR/run" export DD_BIN_DIR="$DD_DIR/bin/agent" DD_LOG_DIR="$APT_DIR/var/log/datadog" DD_CONF_DIR="$APT_DIR/etc/datadog-agent" +DD_INSTALL_INFO="$DD_CONF_DIR/install_info" export DATADOG_CONF="$DD_CONF_DIR/datadog.yaml" +export INTEGRATIONS_CONF="$DD_CONF_DIR/conf.d" +export POSTGRES_CONF="$INTEGRATIONS_CONF/postgres.d" +export REDIS_CONF="$INTEGRATIONS_CONF/redisdb.d" # Update Env Vars with new paths for apt packages export PATH="$APT_DIR/usr/bin:$DD_BIN_DIR:$PATH" @@ -26,28 +30,62 @@ DD_PROC_LOG="$DD_LOG_DIR/datadog-proc.log" # Move Datadog config files into place cp "$DATADOG_CONF.example" "$DATADOG_CONF" -# Update the Datadog conf yaml with the correct conf.d and checks.d +# Update the Datadog conf yaml with the correct conf.d and checks.d and the correct run path sed -i -e"s|^.*confd_path:.*$|confd_path: $DD_CONF_DIR/conf.d|" "$DATADOG_CONF" -sed -i -e"s|^.*additional_checksd:.*$|additional_checksd: $DD_CONF_DIR/checks.d|" "$DATADOG_CONF" +sed -i -e"s|^.*additional_checksd:.*$|additional_checksd: $DD_CONF_DIR/checks.d\nrun_path: $DD_RUN_DIR|" "$DATADOG_CONF" + +# Update the Datadog conf yaml to disable cloud provider metadata +sed -i -e"s|^.*cloud_provider_metadata:.*$|cloud_provider_metadata: []|" "$DATADOG_CONF" # Include application's datadog configs -APP_DATADOG="/app/datadog" +APP_DATADOG_DEFAULT="/app/datadog" +APP_DATADOG="${DD_HEROKU_CONF_FOLDER:=$APP_DATADOG_DEFAULT}" APP_DATADOG_CONF_DIR="$APP_DATADOG/conf.d" +APP_DATADOG_CHECKS_DIR="$APP_DATADOG/checks.d" + +# Agent integrations configuration +for dir in "$APP_DATADOG_CONF_DIR"/*; do + test -d "$dir" || continue # only match directories + cp -R "$dir" "$DD_CONF_DIR/conf.d/" +done + +# Agent integrations configuration - Deprecated + +# Datadog.conf yaml addition (use sparingly, since parsing YAML is difficult) +APP_DATADOG_CONF_YAML_ADDON="/app/datadog/datadog-append.yaml" for file in "$APP_DATADOG_CONF_DIR"/*.yaml; do - test -e "$file" || continue # avoid errors when glob doesn't match anything + test -f "$file" || continue # avoid errors when glob doesn't match anything filename="$(basename -- "$file")" filename="${filename%.*}" mkdir -p "$DD_CONF_DIR/conf.d/${filename}.d" cp "$file" "$DD_CONF_DIR/conf.d/${filename}.d/conf.yaml" done +# Custom checks configuration +for file in "$APP_DATADOG_CHECKS_DIR"/*.yaml; do + test -e "$file" || continue # avoid errors when glob doesn't match anything + cp "$file" "$DD_CONF_DIR/conf.d/" +done + +# Custom checks code +for file in "$APP_DATADOG_CHECKS_DIR"/*.py; do + test -e "$file" || continue # avoid errors when glob doesn't match anything + cp "$file" "$DD_CONF_DIR/checks.d/" +done + # Add tags to the config file DYNOHOST="$(hostname )" DYNOTYPE=${DYNO%%.*} -BUILDPACKVERSION="dev" +BUILDPACKVERSION="2.9" DYNO_TAGS="dyno:$DYNO dynotype:$DYNOTYPE buildpackversion:$BUILDPACKVERSION" +# We want always to have the Dyno ID as a host alias to improve correlation +export DD_HOST_ALIASES="$DYNOHOST" + +# Include install method +echo -e "install_method:\n tool: heroku\n tool_version: heroku\n installer_version: heroku-$BUILDPACKVERSION" > "$DD_INSTALL_INFO" + if [ -n "$HEROKU_APP_NAME" ]; then DYNO_TAGS="$DYNO_TAGS appname:$HEROKU_APP_NAME" fi @@ -64,14 +102,18 @@ if [ "$DD_PROCESS_AGENT" == "true" ]; then fi # Set the right path for the log collector -if [ "$DD_LOGS_ENABLED" == "true" ]; then - sed -i -e"s|^# logs_config:$|logs_config:|" "$DATADOG_CONF" - sed -i -e"s|^logs_config:$|logs_config:\n run_path: $DD_RUN_DIR|" "$DATADOG_CONF" -fi +sed -i -e"s|^# logs_config:$|logs_config:|" "$DATADOG_CONF" +sed -i -e"s|^logs_config:$|logs_config:\n run_path: $DD_RUN_DIR|" "$DATADOG_CONF" # For a list of env vars to override datadog.yaml, see: # https://github.com/DataDog/datadog-agent/blob/master/pkg/config/config.go#L145 + +# Read in files and extend $DATADOG_CONF with them if necessary +if [ -f ${APP_DATADOG_CONF_YAML_ADDON} ]; then + cat ${APP_DATADOG_CONF_YAML_ADDON} >> ${DATADOG_CONF} +fi + if [ -z "$DD_API_KEY" ]; then echo "DD_API_KEY environment variable not set. Run: heroku config:add DD_API_KEY=" DISABLE_DATADOG_AGENT=1 @@ -101,6 +143,12 @@ else fi fi +# Allow Apps to extend functionality, like disabling the Agent or changing +# environmental variables +if [ -f $APP_DATADOG_EXTENSION ]; then + . ${APP_DATADOG_EXTENSION} +fi + # Disable core checks (these read the host, not the dyno). if [ "$DD_DISABLE_HOST_METRICS" == "true" ]; then find "$DD_CONF_DIR"/conf.d -name "conf.yaml.default" -exec mv {} {}_disabled \; @@ -116,12 +164,12 @@ if [ "$DD_PYTHON_VERSION" = "3" ]; then if [ "$DD_AGENT_VERSION" != "$(echo -e "$DD_AGENT_BASE_VERSION\n$DD_AGENT_VERSION" | sort -V | head -n1)" ]; then # If Python version is 3, it has to be specified in the configuration file echo 'python_version: 3' >> $DATADOG_CONF + fi # Update symlinks to Python binaries ln -sfn "$DD_DIR"/embedded/bin/python3 "$DD_DIR"/embedded/bin/python ln -sfn "$DD_DIR"/embedded/bin/python3-config "$DD_DIR"/embedded/bin/python-config ln -sfn "$DD_DIR"/embedded/bin/pip3 "$DD_DIR"/embedded/bin/pip ln -sfn "$DD_DIR"/embedded/bin/pydoc3 "$DD_DIR"/embedded/bin/pydoc - fi fi # Ensure all check and library locations are findable in the Python path. @@ -133,16 +181,68 @@ DD_PYTHONPATH="$DD_DIR/embedded/lib/$PYTHON_DIR/lib-tk:$DD_PYTHONPATH" DD_PYTHONPATH="$DD_DIR/embedded/lib/$PYTHON_DIR/lib-dynload:$DD_PYTHONPATH" DD_PYTHONPATH="$DD_DIR/bin/agent/dist:$DD_PYTHONPATH" -# For Python2 we need to add explicitely pip and setuptools dependencies -if [ "$DD_PYTHON_VERSION" = "2" ]; then - PIP_PATH=$(find "$DD_DIR/embedded/lib/$PYTHON_DIR/site-packages" -maxdepth 1 -name "pip*egg") - SETUPTOOLS_PATH=$(find "$DD_DIR/embedded/lib/$PYTHON_DIR/site-packages" -maxdepth 1 -name "setuptools*egg") - DD_PYTHONPATH="$DD_PYTHONPATH:$SETUPTOOLS_PATH:$PIP_PATH" -fi +# We need to add explicitely pip and setuptools dependencies +PIP_PATH=$(find "$DD_DIR/embedded/lib/$PYTHON_DIR/site-packages" -maxdepth 1 -name "pip*egg") +SETUPTOOLS_PATH=$(find "$DD_DIR/embedded/lib/$PYTHON_DIR/site-packages" -maxdepth 1 -name "setuptools*egg") +DD_PYTHONPATH="$DD_PYTHONPATH:$SETUPTOOLS_PATH:$PIP_PATH" # Export agent's PYTHONPATH be used by the agent-wrapper export DD_PYTHONPATH="$DD_DIR/embedded/lib:$DD_PYTHONPATH" +## Default integrations configuration + +# Update the Postgres configuration from above using the Heroku application environment variable +if [ "$ENABLE_HEROKU_POSTGRES" == "true" ]; then + # The default connection URL is set in DATABASE_URL, but can be configured by the user + if [[ -z ${POSTGRES_URL_VAR} ]]; then + POSTGRES_URL_VAR="DATABASE_URL" + fi + + cp "$POSTGRES_CONF/conf.yaml.example" "$POSTGRES_CONF/conf.yaml" + + if [ -n "${!POSTGRES_URL_VAR}" ]; then + POSTGREGEX='^postgres://([^:]+):([^@]+)@([^:]+):([^/]+)/(.*)$' + if [[ ${!POSTGRES_URL_VAR} =~ $POSTGREGEX ]]; then + sed -i "s/^ - host:.*/ - host: ${BASH_REMATCH[3]}/" "$POSTGRES_CONF/conf.yaml" + sed -i "s/^ username:.*/ username: ${BASH_REMATCH[1]}/" "$POSTGRES_CONF/conf.yaml" + sed -i "s/^ # password:.*/ password: ${BASH_REMATCH[2]}/" "$POSTGRES_CONF/conf.yaml" + sed -i "s/^ # port:.*/ port: ${BASH_REMATCH[4]}/" "$POSTGRES_CONF/conf.yaml" + sed -i "s/^ # dbname:.*/ dbname: ${BASH_REMATCH[5]}/" "$POSTGRES_CONF/conf.yaml" + sed -i "s/^ # ssl:.*/ ssl: True/" "$POSTGRES_CONF/conf.yaml" + sed -i "s/^ disable_generic_tags:.*/ disable_generic_tags: false/" "$POSTGRES_CONF/conf.yaml" + fi + fi +fi + +# Update the Redis configuration from above using the Heroku application environment variable +if [ "$ENABLE_HEROKU_REDIS" == "true" ]; then + # The default connection URL is set in REDIS_URL, but can be configured by the user + if [[ -z ${REDIS_URL_VAR} ]]; then + REDIS_URL_VAR="REDIS_URL" + fi + + cp "$REDIS_CONF/conf.yaml.example" "$REDIS_CONF/conf.yaml" + + if [ -n "${!REDIS_URL_VAR}" ]; then + REDISREGEX='^redis(s?)://([^:]*):([^@]+)@([^:]+):([^/]+)/?(.*)$' + if [[ ${!REDIS_URL_VAR} =~ $REDISREGEX ]]; then + sed -i "s/^ - host:.*/ - host: ${BASH_REMATCH[4]}/" "$REDIS_CONF/conf.yaml" + sed -i "s/^ # password:.*/ password: ${BASH_REMATCH[3]}/" "$REDIS_CONF/conf.yaml" + sed -i "s/^ port:.*/ port: ${BASH_REMATCH[5]}/" "$REDIS_CONF/conf.yaml" + if [[ ! -z ${BASH_REMATCH[1]} ]]; then + sed -i "s/^ # ssl:.*/ ssl: True/" "$REDIS_CONF/conf.yaml" + sed -i "s/^ # ssl_cert_reqs:.*/ ssl_cert_reqs: 0/" "$REDIS_CONF/conf.yaml" + fi + if [[ ! -z ${BASH_REMATCH[2]} ]]; then + sed -i "s/^ # username:.*/ username: ${BASH_REMATCH[2]}/" "$REDIS_CONF/conf.yaml" + fi + if [[ ! -z ${BASH_REMATCH[6]} ]]; then + sed -i "s/^ # db:.*/ db: ${BASH_REMATCH[6]}/" "$REDIS_CONF/conf.yaml" + fi + fi + fi +fi + # Give applications a chance to modify env vars prior to running. # Note that this can modify existing env vars or perform other actions (e.g. modify the conf file). # For more information on variables and other things you may wish to modify, reference this script @@ -160,6 +260,7 @@ else DD_TAGS="$DYNO_TAGS" fi +export DD_VERSION="$DD_VERSION" export DD_TAGS="$DD_TAGS" if [ "$DD_LOG_LEVEL_LOWER" == "debug" ]; then echo "[DEBUG] Buildpack normalized tags: $DD_TAGS_NORMALIZED" @@ -173,16 +274,19 @@ sed -i "s/^# - role:database$/# - role:database\n$DD_TAGS_YAML/" "$DATADOG_C # Agent versions 6.12 and later: sed -i "s/^\(## @param tags\)/$DD_TAGS_YAML\n\1/" "$DATADOG_CONF" +# Export host type as dyno +export DD_HEROKU_DYNO="true" + # Execute the final run logic. if [ -n "$DISABLE_DATADOG_AGENT" ]; then echo "The Datadog Agent has been disabled. Unset the DISABLE_DATADOG_AGENT or set missing environment variables." else # Get the Agent version number - DD_VERSION="$(expr "$(bash -c "LD_LIBRARY_PATH=\"$DD_LD_LIBRARY_PATH\" $DD_BIN_DIR/agent version")" : 'Agent \([0-9]\+\.[0-9]\+.[0-9]\+\)')" + DATADOG_VERSION="$(expr "$(bash -c "LD_LIBRARY_PATH=\"$DD_LD_LIBRARY_PATH\" $DD_BIN_DIR/agent version")" : 'Agent \([0-9]\+\.[0-9]\+.[0-9]\+\)')" # Prior to Agent 6.4.1, the command is "start" RUN_VERSION="6.4.1" - if [ "$DD_VERSION" == "$(echo -e "$RUN_VERSION\n$DD_VERSION" | sort -V | head -n1)" ]; then + if [ "$DATADOG_VERSION" == "$(echo -e "$RUN_VERSION\n$DATADOG_VERSION" | sort -V | head -n1)" ]; then RUN_COMMAND="start" else RUN_COMMAND="run" diff --git a/test/compile_and_run_test.sh b/test/compile_and_run_test.sh index c6ddfbb..daa51cb 100644 --- a/test/compile_and_run_test.sh +++ b/test/compile_and_run_test.sh @@ -21,9 +21,9 @@ compileAndRunVersion() { echo $1 > "${ENV_DIR}/DD_AGENT_VERSION" + echo "true" > "${ENV_DIR}/DD_PROCESS_AGENT" echo "Testing Datadog Agent version $1" compile - assertCaptured "Installing dependencies" assertCaptured "Downloading Datadog Agent $1" assertCaptured "Installing Datadog Agent" assertCaptured "Installing Datadog runner" @@ -38,24 +38,52 @@ compileAndRunVersion() assertCaptured "Starting Datadog Trace Agent" assertNotCaptured "The Datadog Agent has been disabled" assertCaptured "[DEBUG] Buildpack normalized tags: sampletag1:sample sametag2:sample sampletag3 sampletag4" + assertNotCaptured "ModuleNotFoundError" + assertNotCaptured "Fatal Python error" + + SIZE_BIN=$(du -s $HOME/.apt/opt/datadog-agent/bin | cut -f1) + SIZE_LIB=$(du -s $HOME/.apt/opt/datadog-agent/embedded/lib | cut -f1) + SIZE_EMB_BIN=$(du -s $HOME/.apt/opt/datadog-agent/embedded/bin | cut -f1) + + if $2; then + assertTrue "Binary folder is too big: ${SIZE_BIN}" "[ $SIZE_BIN -lt 80000 ]" + assertTrue "Embedded library folder is too big: ${SIZE_LIB}" "[ $SIZE_LIB -lt 180000 ]" + assertTrue "Embedded binary folder is too big: ${SIZE_EMB_BIN}" "[ $SIZE_EMB_BIN -lt 80000 ]" + fi + + rm -rf $HOME/.apt/ } testReleased6Versions() { + echo "deb [trusted=yes] https://apt.datadoghq.com/ stable 6" > "${BUILDPACK_HOME}/etc/datadog.list" getAvailableVersions "datadog.list" + echo "deb [signed-by=SIGNED_BY_PLACEHOLDER] https://apt.datadoghq.com/ stable 6" > "${BUILDPACK_HOME}/etc/datadog.list" for VERSION in ${AGENT_VERSIONS}; do - compileAndRunVersion $VERSION - done + # Only test for size from 6.34 onwards + if test "6.34.0-1" = "$(echo "6.34.0-1\n$VERSION" | sort -V | head -n1)" ; then + compileAndRunVersion $VERSION true + else + compileAndRunVersion $VERSION false + fi + done } testReleased7Versions() { + echo "deb [trusted=yes] https://apt.datadoghq.com/ stable 7" > "${BUILDPACK_HOME}/etc/datadog7.list" getAvailableVersions "datadog7.list" + echo "deb [signed-by=SIGNED_BY_PLACEHOLDER] https://apt.datadoghq.com/ stable 7" > "${BUILDPACK_HOME}/etc/datadog7.list" for VERSION in ${AGENT_VERSIONS}; do - compileAndRunVersion $VERSION + # Only test for size from 7.34 onwards + if test "7.34.0-1" = "$(echo "7.34.0-1\n$VERSION" | sort -V | head -n1)" ; then + compileAndRunVersion $VERSION true + else + compileAndRunVersion $VERSION false + fi done }