Skip to content

Commit 48e813f

Browse files
authored
Merge pull request #4 from ustudio/do-not-use-app-key
Removed use of datadog-app-key secret
2 parents 7b57cde + cfe046f commit 48e813f

File tree

4 files changed

+15
-21
lines changed

4 files changed

+15
-21
lines changed

README.md

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@ pip install ustack-logging
1111
## Usage ##
1212

1313
```python
14-
import os
1514
from ustack_logging.logging_configuration import configure_logging
1615

1716

1817
def main():
19-
configure_logging(os.environ)
18+
configure_logging()
2019

2120
# Run your application
2221

@@ -32,11 +31,9 @@ applications log and report errors when running inside Kubernetes. It
3231
takes no configuration because its intent is to enforce a
3332
configuration.
3433

35-
However, it is built on separate libraries that *are* configurable:
36-
[datadog-logger](https://github.com/ustudio/datadog-logger) and
37-
[kubernetes-downward-api](https://github.com/ustudio/kubernetes-downward-api). If
38-
you need a different configuration, it should be trivial to implement
39-
it using those libraries.
34+
However, it is built on [datadog-logger](https://github.com/ustudio/datadog-logger),
35+
which is configurable. If you need a different configuration, it
36+
should be trivial to implement it using that library directly.
4037

4138
## Configuration ##
4239

@@ -46,18 +43,17 @@ It sets up the logging library to log the time, log level, module name
4643
and log message for every message, and it sets the current log level
4744
to `INFO`.
4845

49-
It connects to Datadog using the environment variables
50-
`DATADOG_API_KEY` and `DATADOG_APP_KEY`, and parses the Kubernetes
51-
namespace and labels out of a Kubernetes Downward API VolumeMount at
52-
`/etc/podinfo`.
46+
In order to function, it uses a secret named `environment-info` in the
47+
`ustudio-system` namespace. The secret must contain the keys
48+
`environment` and `datadog-api-key`, and the pod must contain a label
49+
named `role`.
5350

54-
If the environment variables are not set (or are incorrect) or the
55-
Downward API VolumeMount isn't available it logs a warning and does
56-
not error.
51+
If any information is missing or any connections fail it logs a
52+
warning and does not error.
5753

5854
It configures the `datadog-logger` library to send `ERROR` and above
5955
log messages to Datadog as events, with the following tag mapping:
6056

61-
* K8s Namespace -> Datadog tag `environment`
62-
* K8s Pod Label `app` -> Datadog tag `service`
57+
* `environment-info.environment` -> Datadog tag `environment`
58+
* K8s Pod Namespace -> Datadog tag `service`
6359
* K8s Pod Label `role` -> Datadog tag `role`

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
]
1212

1313
setup(name="ustack-logging",
14-
version="0.2.0",
14+
version="0.2.1",
1515
description="Default logging configuration for uStack style Python applications.",
1616
url="https://github.com/ustudio/ustack-logging",
1717
packages=["ustack_logging"],

tests/test_ustack_logging.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ def test_configures_logging_format_and_logs_errors_to_datadog(
3131
data={
3232
"environment": base64.b64encode("dev".encode("utf8")),
3333
"datadog-api-key": base64.b64encode("dd-api-key".encode("utf8")),
34-
"datadog-app-key": base64.b64encode("dd-app-key".encode("utf8"))
3534
})
3635
mock_k8s_api.read_namespaced_pod.return_value = V1Pod(
3736
metadata=V1ObjectMeta(labels={
@@ -53,7 +52,7 @@ def test_configures_logging_format_and_logs_errors_to_datadog(
5352
mock_k8s_api.read_namespaced_secret.assert_called_once_with(
5453
"environment-info", "ustudio-system")
5554

56-
mock_dd_init.assert_called_once_with(api_key="dd-api-key", app_key="dd-app-key")
55+
mock_dd_init.assert_called_once_with(api_key="dd-api-key")
5756

5857
mock_open.assert_called_once_with("/var/run/secrets/kubernetes.io/serviceaccount/namespace")
5958

ustack_logging/logging_configuration.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ def configure_logging():
1818
environment_info = core_api.read_namespaced_secret("environment-info", "ustudio-system")
1919

2020
datadog.initialize(
21-
api_key=base64.b64decode(environment_info.data["datadog-api-key"]).decode("utf8"),
22-
app_key=base64.b64decode(environment_info.data["datadog-app-key"]).decode("utf8"))
21+
api_key=base64.b64decode(environment_info.data["datadog-api-key"]).decode("utf8"))
2322

2423
with open("/var/run/secrets/kubernetes.io/serviceaccount/namespace") as f:
2524
namespace = f.read()

0 commit comments

Comments
 (0)