-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from ustudio/update-for-new-cluster-style
updated to get information from kubernetes API instead of downward API and support one namespace per application.
- Loading branch information
Showing
5 changed files
with
74 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,38 @@ | ||
import base64 | ||
import datadog | ||
from datadog_logger import log_error_events | ||
import kubernetes_downward_api | ||
import kubernetes.client | ||
import logging | ||
import socket | ||
|
||
|
||
def configure_logging(environ): | ||
def configure_logging(): | ||
logging.basicConfig( | ||
format="%(asctime)s %(levelname)s:%(module)s:%(message)s", | ||
datefmt="%Y-%m-%d %H:%M:%S%z", level=logging.INFO) | ||
|
||
try: | ||
datadog.initialize(api_key=environ["DATADOG_API_KEY"], app_key=environ["DATADOG_APP_KEY"]) | ||
kubernetes.config.load_incluster_config() | ||
|
||
podinfo = kubernetes_downward_api.parse(["/etc/podinfo"]) | ||
core_api = kubernetes.client.CoreV1Api() | ||
environment_info = core_api.read_namespaced_secret("environment-info", "ustudio-system") | ||
|
||
datadog.initialize( | ||
api_key=base64.b64decode(environment_info.data["datadog-api-key"]).decode("utf8"), | ||
app_key=base64.b64decode(environment_info.data["datadog-app-key"]).decode("utf8")) | ||
|
||
with open("/var/run/secrets/kubernetes.io/serviceaccount/namespace") as f: | ||
namespace = f.read() | ||
|
||
pod_name = socket.gethostname().split(".")[0] | ||
|
||
pod_info = core_api.read_namespaced_pod(pod_name, namespace) | ||
|
||
log_error_events(tags=[ | ||
"environment:{0}".format(podinfo["namespace"]), | ||
"service:{0}".format(podinfo["labels"]["app"]), | ||
"role:{0}".format(podinfo["labels"]["role"]) | ||
"environment:{0}".format( | ||
base64.b64decode(environment_info.data["environment"]).decode("utf8")), | ||
"service:{0}".format(namespace), | ||
"role:{0}".format(pod_info.metadata.labels["role"]) | ||
]) | ||
except: | ||
logging.warning("Could not initialize DataDog error logging, with error:", exc_info=True) |