This repository has been archived by the owner on Jul 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.py
115 lines (105 loc) · 4.22 KB
/
settings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
##################################################
# s3_step Settings File
##################################################
import os
CONSUMER_CONFIG = {
"PARAMS": {
"bootstrap.servers": os.environ["CONSUMER_SERVER"],
"group.id": os.environ["CONSUMER_GROUP_ID"],
"auto.offset.reset": "beginning",
"enable.partition.eof": os.getenv("ENABLE_PARTITION_EOF", False),
"max.poll.interval.ms": 3600000,
},
}
if os.getenv("TOPIC_STRATEGY_FORMAT"):
CONSUMER_CONFIG["TOPIC_STRATEGY"] = {
"CLASS": "apf.core.topic_management.DailyTopicStrategy",
"PARAMS": {
"topic_format": os.environ["TOPIC_STRATEGY_FORMAT"].strip().split(","),
"date_format": "%Y%m%d",
"change_hour": 23,
},
}
elif os.getenv("CONSUMER_TOPICS"):
CONSUMER_CONFIG["TOPICS"] = os.environ["CONSUMER_TOPICS"].strip().split(",")
else:
raise Exception("Add TOPIC_STRATEGY or CONSUMER_TOPICS")
METRICS_CONFIG = {
"CLASS": "apf.metrics.KafkaMetricsProducer",
"EXTRA_METRICS": [
{"key": "candid", "format": lambda x: str(x)},
{"key": "objectId", "alias": "oid"},
],
"PARAMS": {
"PARAMS": {
"bootstrap.servers": os.environ["METRICS_HOST"],
"auto.offset.reset": "smallest",
},
"TOPIC": os.environ["METRICS_TOPIC"],
"SCHEMA": {
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "http://example.com/example.json",
"type": "object",
"title": "The root schema",
"description": "The root schema comprises the entire JSON document.",
"default": {},
"examples": [
{"timestamp_sent": "2020-09-01", "timestamp_received": "2020-09-01"}
],
"required": ["timestamp_sent", "timestamp_received"],
"properties": {
"timestamp_sent": {
"$id": "#/properties/timestamp_sent",
"type": "string",
"title": "The timestamp_sent schema",
"description": "Timestamp sent refers to the time at which a message is sent.",
"default": "",
"examples": ["2020-09-01"],
},
"timestamp_received": {
"$id": "#/properties/timestamp_received",
"type": "string",
"title": "The timestamp_received schema",
"description": "Timestamp received refers to the time at which a message is received.",
"default": "",
"examples": ["2020-09-01"],
},
},
"additionalProperties": True,
},
},
}
if os.getenv("CONSUMER_KAFKA_USERNAME") and os.getenv("CONSUMER_KAFKA_PASSWORD"):
CONSUMER_CONFIG["PARAMS"]["security.protocol"] = "SASL_SSL"
CONSUMER_CONFIG["PARAMS"]["sasl.mechanism"] = "SCRAM-SHA-512"
CONSUMER_CONFIG["PARAMS"]["sasl.username"] = os.getenv("CONSUMER_KAFKA_USERNAME")
CONSUMER_CONFIG["PARAMS"]["sasl.password"] = os.getenv("CONSUMER_KAFKA_PASSWORD")
if os.getenv("METRICS_KAFKA_USERNAME") and os.getenv("METRICS_KAFKA_PASSWORD"):
METRICS_CONFIG["PARAMS"]["PARAMS"]["security.protocol"] = "SASL_SSL"
METRICS_CONFIG["PARAMS"]["PARAMS"]["sasl.mechanism"] = "SCRAM-SHA-512"
METRICS_CONFIG["PARAMS"]["PARAMS"]["sasl.username"] = os.getenv(
"METRICS_KAFKA_USERNAME"
)
METRICS_CONFIG["PARAMS"]["PARAMS"]["sasl.password"] = os.getenv(
"METRICS_KAFKA_PASSWORD"
)
STEP_METADATA = {
"STEP_VERSION": os.getenv("STEP_VERSION", "dev"),
"STEP_ID": os.getenv("STEP_ID", "features"),
"STEP_NAME": os.getenv("STEP_NAME", "features"),
"STEP_COMMENTS": os.getenv("STEP_COMMENTS", ""),
}
STORAGE_CONFIG = {
# BUCKET_NAME is mapping from topic prefix to s3 bucket name
"BUCKET_NAME": dict(
[pair.split(":")[::-1] for pair in os.environ["BUCKET_NAME"].split(",")]
),
"REGION_NAME": os.environ["REGION_NAME"],
}
LOGGING_DEBUG = os.getenv("LOGGING_DEBUG", False)
STEP_CONFIG = {
"STORAGE": STORAGE_CONFIG,
"CONSUMER_CONFIG": CONSUMER_CONFIG,
"METRICS_CONFIG": METRICS_CONFIG,
"STEP_METADATA": STEP_METADATA,
}