better logging and metrics

This commit is contained in:
Hossein Shafagh 2020-10-30 18:17:02 -07:00
parent c5769378cf
commit ba8eb7a3f5
1 changed files with 21 additions and 6 deletions

View File

@ -33,6 +33,7 @@
.. moduleauthor:: Harm Weites <harm@weites.com>
"""
import sys
from acme.errors import ClientError
from flask import current_app
@ -420,6 +421,8 @@ class S3DestinationPlugin(ExportDestinationPlugin):
"""
current_app.logger.debug("S3 destination plugin is started for HTTP-01 challenge")
function = f"{__name__}.{sys._getframe().f_code.co_name}"
account_number = self.get_option("accountNumber", options)
bucket_name = self.get_option("bucket", options)
prefix = self.get_option("prefix", options)
@ -428,12 +431,24 @@ class S3DestinationPlugin(ExportDestinationPlugin):
if not prefix.endswith("/"):
prefix + "/"
s3.put(bucket_name=bucket_name,
res = s3.put(bucket_name=bucket_name,
region_name=region,
prefix=prefix + filename,
data=token,
encrypt=False,
account_number=account_number)
res = "Success" if res else "Failure"
log_data = {
"function": function,
"message": "check if any valid certificate is revoked",
"result": res,
"bucket_name": bucket_name,
"filename": filename
}
current_app.logger.info(log_data)
metrics.send(f"{function}", "counter", 1, metric_tags={"result": res,
"bucket_name": bucket_name,
"filename": filename})
class SNSNotificationPlugin(ExpirationNotificationPlugin):