@@ -19,8 +19,8 @@ use omicron_common::address::CLICKHOUSE_TCP_PORT;
19
19
use omicron_common:: api:: external:: Generation ;
20
20
use oximeter_db:: Client as OximeterClient ;
21
21
use oximeter_db:: OXIMETER_VERSION ;
22
- use slog:: { info, error} ;
23
22
use slog:: Logger ;
23
+ use slog:: { error, info} ;
24
24
use std:: fs:: File ;
25
25
use std:: io:: { BufRead , BufReader } ;
26
26
use std:: net:: SocketAddrV6 ;
@@ -76,6 +76,7 @@ impl KeeperServerContext {
76
76
pub struct ServerContext {
77
77
clickhouse_cli : ClickhouseCli ,
78
78
clickward : Clickward ,
79
+
79
80
oximeter_client : OximeterClient ,
80
81
log : Logger ,
81
82
pub generation : Mutex < Option < Generation > > ,
@@ -93,6 +94,8 @@ impl ServerContext {
93
94
94
95
let ip = listen_address. ip ( ) ;
95
96
let address = SocketAddrV6 :: new ( * ip, CLICKHOUSE_TCP_PORT , 0 , 0 ) ;
97
+ // TODO: Instead of creating OximeterClient here, pass along the `address` and create the client
98
+ // in self.oximeter_client. This client is not cloneable, copyable by design.
96
99
let oximeter_client = OximeterClient :: new ( address. into ( ) , log) ;
97
100
let clickward = Clickward :: new ( ) ;
98
101
let log = log. new ( slog:: o!( "component" => "ServerContext" ) ) ;
@@ -125,16 +128,16 @@ impl ServerContext {
125
128
& self . clickhouse_cli
126
129
}
127
130
128
- pub fn clickward ( & self ) -> & Clickward {
129
- & self . clickward
131
+ pub fn clickward ( & self ) -> Clickward {
132
+ self . clickward
130
133
}
131
134
132
135
pub fn oximeter_client ( & self ) -> & OximeterClient {
133
136
& self . oximeter_client
134
137
}
135
138
136
- pub fn log ( & self ) -> & Logger {
137
- & self . log
139
+ pub fn log ( & self ) -> Logger {
140
+ self . log . clone ( )
138
141
}
139
142
140
143
pub fn generation ( & self ) -> Option < Generation > {
@@ -145,14 +148,22 @@ impl ServerContext {
145
148
pub enum ClickhouseAdminServerRequest {
146
149
/// Generates configuration files for a replicated cluster
147
150
GenerateConfig {
151
+ // TODO: Remove ctx once the generation number is handled
152
+ // via a watcher channel
148
153
ctx : Arc < ServerContext > ,
154
+ clickward : Clickward ,
155
+ log : Logger ,
149
156
replica_settings : ServerConfigurableSettings ,
150
157
response : oneshot:: Sender < Result < ReplicaConfig , HttpError > > ,
151
158
} ,
152
159
/// Initiliases the oximeter database on either a single node
153
160
/// ClickHouse installation or a replicated cluster.
154
161
DbInit {
162
+ // TODO: Create oximeter client in a different way
163
+ // meanwhile use ctx
164
+ // oximeter_client: OximeterClient,
155
165
ctx : Arc < ServerContext > ,
166
+ log : Logger ,
156
167
replicated : bool ,
157
168
response : oneshot:: Sender < Result < ( ) , HttpError > > ,
158
169
} ,
@@ -165,28 +176,35 @@ async fn long_running_ch_admin_server_task(
165
176
match request {
166
177
ClickhouseAdminServerRequest :: GenerateConfig {
167
178
ctx,
179
+ clickward,
180
+ log,
168
181
replica_settings,
169
182
response,
170
183
} => {
171
184
// TODO: Remove clone
172
- let result =
173
- generate_config_and_enable_svc ( ctx. clone ( ) , replica_settings) ;
185
+ let result = generate_config_and_enable_svc (
186
+ ctx. clone ( ) ,
187
+ clickward,
188
+ replica_settings,
189
+ ) ;
174
190
if let Err ( e) = response. send ( result) {
175
191
error ! (
176
- & ctx . log,
192
+ & log,
177
193
"failed to send value from configuration generation to channel: {e:?}"
178
194
) ;
179
195
} ;
180
196
}
181
197
ClickhouseAdminServerRequest :: DbInit {
198
+ // oximeter_client,
182
199
ctx,
200
+ log,
183
201
replicated,
184
202
response,
185
203
} => {
186
- let result = init_db ( ctx. clone ( ) , replicated) . await ;
204
+ let result = init_db ( ctx, log . clone ( ) , replicated) . await ;
187
205
if let Err ( e) = response. send ( result) {
188
206
error ! (
189
- & ctx . log,
207
+ log,
190
208
"failed to send value from database initialization to channel: {e:?}"
191
209
) ;
192
210
} ;
@@ -197,7 +215,10 @@ async fn long_running_ch_admin_server_task(
197
215
198
216
pub fn generate_config_and_enable_svc (
199
217
// TODO: Expand ctx into separate items
218
+ // TODO: Send the generation number via the watcher channel first before
219
+ // removing ctx entirely
200
220
ctx : Arc < ServerContext > ,
221
+ clickward : Clickward ,
201
222
replica_settings : ServerConfigurableSettings ,
202
223
) -> Result < ReplicaConfig , HttpError > {
203
224
let mut current_generation = ctx. generation . lock ( ) . unwrap ( ) ;
@@ -220,7 +241,7 @@ pub fn generate_config_and_enable_svc(
220
241
}
221
242
} ;
222
243
223
- let output = ctx . clickward ( ) . generate_server_config ( replica_settings) ?;
244
+ let output = clickward. generate_server_config ( replica_settings) ?;
224
245
225
246
// We want to update the generation number only if the config file has been
226
247
// generated successfully.
@@ -234,11 +255,12 @@ pub fn generate_config_and_enable_svc(
234
255
}
235
256
236
257
pub async fn init_db (
237
- // TODO: Expand ctx into separate items
258
+ // TODO: Create oximeter client in a different way
259
+ // meanwhile use ctx
238
260
ctx : Arc < ServerContext > ,
261
+ log : Logger ,
239
262
replicated : bool ,
240
263
) -> Result < ( ) , HttpError > {
241
- let log = ctx. log ( ) ;
242
264
// Initialize the database only if it was not previously initialized.
243
265
// TODO: Migrate schema to newer version without wiping data.
244
266
let client = ctx. oximeter_client ( ) ;
0 commit comments