Merge ~troyanov/maas:temporal-use-maasdb into maas:master

Proposed by Anton Troyanov
Status: Merged
Approved by: Anton Troyanov
Approved revision: 5168de642931a82f8333f218dab0fb348c39632e
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~troyanov/maas:temporal-use-maasdb
Merge into: maas:master
Diff against target: 162 lines (+63/-49)
2 files modified
src/maasserver/regiondservices/temporal.py (+34/-12)
src/maasserver/templates/temporal/production.yaml.template (+29/-37)
Reviewer Review Type Date Requested Status
Alberto Donato (community) Approve
MAAS Lander Approve
Review via email: mp+449961@code.launchpad.net

Commit message

feat(temporal): use postgresql database

Description of the change

numHistoryShards is set to 4 and connection related params (maxConns, maxIdleConns) are taken from Temporal defaults [0] for PostgreSQL

[0]: https://github.com/temporalio/temporal/blob/main/config/development-postgres12.yaml

To post a comment you must log in.
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b temporal-use-maasdb lp:~troyanov/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 5168de642931a82f8333f218dab0fb348c39632e

review: Approve
Revision history for this message
Alberto Donato (ack) wrote :

+1

Not for this branch, but given that the config template is getting some logic, I would consider dropping it and just dumping the config struct from python to YAML, so that all the logic is in one place.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/regiondservices/temporal.py b/src/maasserver/regiondservices/temporal.py
2index 5db857b..3e30a77 100644
3--- a/src/maasserver/regiondservices/temporal.py
4+++ b/src/maasserver/regiondservices/temporal.py
5@@ -10,11 +10,13 @@ import sys
6 from twisted.application.service import Service
7 from twisted.internet.defer import inlineCallbacks
8
9+from maasserver.config import RegionConfiguration
10+from maasserver.djangosettings.settings import _get_default_db_config
11 from maasserver.service_monitor import service_monitor
12 from maasserver.utils import load_template
13-from maasserver.utils.threads import deferToDatabase
14 from provisioningserver.logger import LegacyLogger
15 from provisioningserver.path import get_tentative_data_path
16+from provisioningserver.utils.env import MAAS_ID
17 from provisioningserver.utils.fs import atomic_write, snap
18
19 log = LegacyLogger()
20@@ -24,24 +26,44 @@ class RegionTemporalService(Service):
21 def __init__(self):
22 super().__init__()
23
24- @inlineCallbacks
25 def startService(self):
26- config = yield deferToDatabase(self._getConfiguration)
27- self._configure(config)
28- yield self._reload_service()
29+ self._configure()
30 super().startService()
31
32 def stopService(self):
33- return super().stopService()
34-
35- def _getConfiguration(self):
36- return None
37+ super().stopService()
38
39- def _configure(self, configuration):
40- """Update the HTTP configuration for the region proxy service."""
41+ def _configure(self):
42+ """Update the Temporal configuration for the Temporal service."""
43 template = load_template("temporal", "production.yaml.template")
44- environ = {}
45+
46+ with RegionConfiguration.open() as config:
47+ dbconf = _get_default_db_config(config)
48+
49+ connection_attributes = {}
50+ host = dbconf["HOST"]
51+ if host.startswith("/"):
52+ connection_attributes["host"] = host
53+
54+ # If the host name starts with @, it is taken as a Unix-domain socket
55+ # in the abstract namespace (currently supported on Linux and Windows).
56+ # https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PARAMKEYWORDS
57+ host = "@"
58+
59+ maas_id = MAAS_ID.get() or "NO_ID"
60+ application_name = f"maas-temporal-{maas_id}"
61+ connection_attributes["application_name"] = application_name
62+
63+ environ = {
64+ "database": dbconf["NAME"],
65+ "user": dbconf.get("USER", ""),
66+ "password": dbconf.get("PASSWORD", ""),
67+ "address": f"{host}:{dbconf['PORT']}",
68+ "connect_attributes": connection_attributes,
69+ }
70+
71 rendered = template.substitute(environ).encode()
72+
73 target_path = Path(
74 os.path.join(get_temporal_config_dir(), "production.yaml")
75 )
76diff --git a/src/maasserver/templates/temporal/production.yaml.template b/src/maasserver/templates/temporal/production.yaml.template
77index 03a542a..41bb15b 100644
78--- a/src/maasserver/templates/temporal/production.yaml.template
79+++ b/src/maasserver/templates/temporal/production.yaml.template
80@@ -3,53 +3,45 @@ log:
81 level: info
82
83 persistence:
84- defaultStore: sqlite-default
85- visibilityStore: sqlite-visibility
86- numHistoryShards: 1
87+ defaultStore: default
88+ visibilityStore: visibility
89+ numHistoryShards: 4
90 datastores:
91- sqlite-default:
92+ default:
93 sql:
94- user: ""
95- password: ""
96- pluginName: "sqlite"
97- databaseName: "default"
98- connectAddr: "localhost"
99+ user: {{ user }}
100+ password: {{ password }}
101+ pluginName: "postgres12"
102+ databaseName: {{ database }}
103+ connectAddr: {{ address | repr }}
104 connectProtocol: "tcp"
105 connectAttributes:
106- mode: "memory"
107- cache: "private"
108- maxConns: 1
109- maxIdleConns: 1
110+ search_path: "temporal"
111+ {{ for k, v in connect_attributes.items() }}
112+ {{ k }}: {{ v | repr }}
113+ {{ endfor }}
114+ maxConns: 20
115+ maxIdleConns: 20
116 maxConnLifetime: "1h"
117- tls:
118- enabled: false
119- caFile: ""
120- certFile: ""
121- keyFile: ""
122- enableHostVerification: false
123- serverName: ""
124
125- sqlite-visibility:
126+ visibility:
127 sql:
128- user: ""
129- password: ""
130- pluginName: "sqlite"
131- databaseName: "default"
132- connectAddr: "localhost"
133+ user: {{ user }}
134+ password: {{ password }}
135+ pluginName: "postgres12"
136+ databaseName: {{ database }}
137+ connectAddr: {{ address | repr }}
138 connectProtocol: "tcp"
139 connectAttributes:
140- mode: "memory"
141- cache: "private"
142- maxConns: 1
143- maxIdleConns: 1
144+ search_path: "temporal_visibility"
145+ {{ for k, v in connect_attributes.items() }}
146+ {{ k }}: {{ v | repr }}
147+ {{ endfor }}
148+
149+ maxConns: 2
150+ maxIdleConns: 2
151 maxConnLifetime: "1h"
152- tls:
153- enabled: false
154- caFile: ""
155- certFile: ""
156- keyFile: ""
157- enableHostVerification: false
158- serverName: ""
159+
160 global:
161 membership:
162 maxJoinDuration: 30s

Subscribers

People subscribed via source and target branches