Skip to content

Commit 18908e6

Browse files
authored
[UI] include load balancer in the monthly cost calculation (zalando#1977)
1 parent 529cdfc commit 18908e6

File tree

5 files changed

+132
-82
lines changed

5 files changed

+132
-82
lines changed

ui/app/src/edit.tag.pug

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ edit
139139
o.spec.enableMasterLoadBalancer = i.spec.enableMasterLoadBalancer || false
140140
o.spec.enableReplicaLoadBalancer = i.spec.enableReplicaLoadBalancer || false
141141
o.spec.enableConnectionPooler = i.spec.enableConnectionPooler || false
142+
o.spec.enableReplicaConnectionPooler = i.spec.enableReplicaConnectionPooler || false
143+
o.spec.enableMasterPoolerLoadBalancer = i.spec.enableMasterPoolerLoadBalancer || false
144+
o.spec.enableReplicaPoolerLoadBalancer = i.spec.enableReplicaPoolerLoadBalancer || false
142145

143146
o.spec.volume = {
144147
size: i.spec.volume.size,

ui/app/src/new.tag.pug

Lines changed: 95 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -216,40 +216,73 @@ new
216216
)
217217

218218
tr(if='{ [undefined, true].includes(config.master_load_balancer_visible) }')
219-
td Master load balancer
219+
td Enable load balancer
220220
td
221-
label
222-
input(
223-
type='checkbox'
224-
value='{ enableMasterLoadBalancer }'
225-
onchange='{ toggleEnableMasterLoadBalancer }'
226-
)
227-
|
228-
| Enable master ELB
221+
ul.ips
222+
li
223+
label
224+
input(
225+
type='checkbox'
226+
value='{ enableMasterLoadBalancer }'
227+
onchange='{ toggleEnableMasterLoadBalancer }'
228+
)
229+
|
230+
| Master
231+
li(if='{ [undefined, true].includes(config.replica_load_balancer_visible) && instanceCount > 1 }')
232+
label
233+
input(
234+
type='checkbox'
235+
value='{ enableReplicaLoadBalancer }'
236+
onchange='{ toggleEnableReplicaLoadBalancer }'
237+
)
238+
|
239+
| Replica
229240

230-
tr(if='{ [undefined, true].includes(config.replica_load_balancer_visible) }')
231-
td Replica load balancer
241+
tr(if='{ [undefined, true].includes(config.connection_pooler_visible) }')
242+
td Enable connection pooler
232243
td
233-
label
234-
input(
235-
type='checkbox'
236-
value='{ enableReplicaLoadBalancer }'
237-
onchange='{ toggleEnableReplicaLoadBalancer }'
238-
)
239-
|
240-
| Enable replica ELB
244+
ul.ips
245+
li
246+
label
247+
input(
248+
type='checkbox'
249+
value='{ enableConnectionPooler }'
250+
onchange='{ toggleEnableConnectionPooler }'
251+
)
252+
|
253+
| Master
254+
li(if='{ [undefined, true].includes(config.replica_connection_pooler_visible) && instanceCount > 1 }')
255+
label
256+
input(
257+
type='checkbox'
258+
value='{ enableReplicaConnectionPooler }'
259+
onchange='{ toggleEnableReplicaConnectionPooler }'
260+
)
261+
|
262+
| Replica
241263

242-
tr
243-
td Enable Connection Pool
264+
tr(if='{ [undefined, true].includes(config.master_pooler_load_balancer_visible) }')
265+
td Enable connection pooler load balancer
244266
td
245-
label
246-
input(
247-
type='checkbox'
248-
value='{ enableConnectionPooler }'
249-
onchange='{ toggleEnableConnectionPooler }'
250-
)
251-
|
252-
| Enable Connection Pool (using PGBouncer)
267+
ul.ips
268+
li
269+
label
270+
input(
271+
type='checkbox'
272+
value='{ enableMasterPoolerLoadBalancer }'
273+
onchange='{ toggleEnableMasterPoolerLoadBalancer }'
274+
)
275+
|
276+
| Master
277+
li(if='{ [undefined, true].includes(config.replica_pooler_load_balancer_visible) && instanceCount > 1 }')
278+
label
279+
input(
280+
type='checkbox'
281+
value='{ enableReplicaPoolerLoadBalancer }'
282+
onchange='{ toggleEnableReplicaPoolerLoadBalancer }'
283+
)
284+
|
285+
| Replica
253286

254287
tr
255288
td Volume size
@@ -267,7 +300,7 @@ new
267300
.input-group-addon
268301
.input-units Gi
269302
tr
270-
td
303+
td
271304
td Specify Iops and Throughput only if you need more than the default 3000 Iops and 125Mb/s EBS provides.
272305

273306
tr
@@ -539,6 +572,15 @@ new
539572
{{#if enableConnectionPooler}}
540573
enableConnectionPooler: true
541574
{{/if}}
575+
{{#if enableReplicaConnectionPooler}}
576+
enableReplicaConnectionPooler: true
577+
{{/if}}
578+
{{#if enableMasterPoolerLoadBalancer}}
579+
enableMasterPoolerLoadBalancer: true
580+
{{/if}}
581+
{{#if enableReplicaPoolerLoadBalancer}}
582+
enableReplicaPoolerLoadBalancer: true
583+
{{/if}}
542584
volume:
543585
size: "{{ volumeSize }}Gi"{{#if iops}}
544586
iops: {{ iops }}{{/if}}{{#if throughput}}
@@ -592,6 +634,9 @@ new
592634
enableMasterLoadBalancer: this.enableMasterLoadBalancer,
593635
enableReplicaLoadBalancer: this.enableReplicaLoadBalancer,
594636
enableConnectionPooler: this.enableConnectionPooler,
637+
enableReplicaConnectionPooler: this.enableReplicaConnectionPooler,
638+
enableMasterPoolerLoadBalancer: this.enableMasterPoolerLoadBalancer,
639+
enableReplicaPoolerLoadBalancer: this.enableReplicaPoolerLoadBalancer,
595640
volumeSize: this.volumeSize,
596641
iops: this.iops,
597642
throughput: this.throughput,
@@ -655,6 +700,18 @@ new
655700
this.enableConnectionPooler = !this.enableConnectionPooler
656701
}
657702

703+
this.toggleEnableReplicaConnectionPooler = e => {
704+
this.enableReplicaConnectionPooler = !this.enableReplicaConnectionPooler
705+
}
706+
707+
this.toggleEnableMasterPoolerLoadBalancer = e => {
708+
this.enableMasterPoolerLoadBalancer = !this.enableMasterPoolerLoadBalancer
709+
}
710+
711+
this.toggleEnableReplicaPoolerLoadBalancer = e => {
712+
this.enableReplicaPoolerLoadBalancer = !this.enableReplicaPoolerLoadBalancer
713+
}
714+
658715
this.volumeChange = e => {
659716
this.volumeSize = +e.target.value
660717
}
@@ -692,6 +749,11 @@ new
692749

693750
this.instanceCountChange = e => {
694751
this.instanceCount = +e.target.value
752+
if (this.instanceCount < 2) {
753+
this.enableReplicaLoadBalancer = false
754+
this.enableReplicaConnectionPooler = false
755+
this.enableReplicaPoolerLoadBalancer = false
756+
}
695757
}
696758

697759
this.checkClusterExists = () => (
@@ -957,6 +1019,9 @@ new
9571019
this.enableMasterLoadBalancer = false
9581020
this.enableReplicaLoadBalancer = false
9591021
this.enableConnectionPooler = false
1022+
this.enableReplicaConnectionPooler = false
1023+
this.enableMasterPoolerLoadBalancer = false
1024+
this.enableReplicaPoolerLoadBalancer = false
9601025

9611026
this.postgresqlVersion = this.postgresqlVersion = (
9621027
this.config.postgresql_versions[0]

ui/app/src/postgresql.tag.pug

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,13 @@ postgresql
168168
this.progress.dnsName = data.metadata.name + '.' + data.metadata.namespace
169169
}
170170

171-
jQuery.get('/pooler/' + this.cluster_path).done(data => {
172-
this.progress.pooler = {"url": ""}
173-
this.update()
174-
})
175-
171+
if (this.progress.poolerEnabled == true) {
172+
jQuery.get('/pooler/' + this.cluster_path).done(data => {
173+
this.progress.pooler = {"url": ""}
174+
this.update()
175+
})
176+
}
177+
176178
this.update()
177179
})
178180
})

ui/app/src/postgresqls.tag.pug

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ postgresqls
6868
| IOPS (-3000 baseline): 0.006$
6969
br
7070
| Throughput (-125 baseline): 0.0476$
71+
br
72+
| 1 ELB: 21.96$
7173
th(stlye='width: 120px')
7274

7375
tbody
@@ -87,7 +89,7 @@ postgresqls
8789
td { volume_size }
8890
td { iops }
8991
td { throughput }
90-
td { calcCosts(nodes, cpu, memory, volume_size, iops, throughput) }$
92+
td { calcCosts(nodes, cpu, memory, volume_size, iops, throughput, num_elb) }$
9193

9294
td
9395

@@ -167,7 +169,9 @@ postgresqls
167169
| IOPS (-3000 baseline): 0.006$
168170
br
169171
| Throughput (-125 baseline): 0.0476$
170-
th(stlye='width: 120px')
172+
br
173+
| 1 ELB: 21.96$
174+
th(style='width: 120px')
171175

172176
tbody
173177
tr(
@@ -188,7 +192,7 @@ postgresqls
188192
td { volume_size }
189193
td { iops }
190194
td { throughput }
191-
td { calcCosts(nodes, cpu, memory, volume_size, iops, throughput) }$
195+
td { calcCosts(nodes, cpu, memory, volume_size, iops, throughput, num_elb) }$
192196

193197
td
194198

@@ -263,10 +267,11 @@ postgresqls
263267
+ '/' + encodeURI(cluster.name)
264268
)
265269

266-
const calcCosts = this.calcCosts = (nodes, cpu, memory, disk, iops, throughput) => {
270+
const calcCosts = this.calcCosts = (nodes, cpu, memory, disk, iops, throughput, num_elb) => {
267271
podcount = Math.max(nodes, opts.config.min_pods)
268272
corecost = toCores(cpu) * opts.config.cost_core * 30.5 * 24
269273
memorycost = toMemory(memory) * opts.config.cost_memory * 30.5 * 24
274+
elbcost = num_elb * opts.config.cost_elb * 30.5 * 24
270275
diskcost = toDisk(disk) * opts.config.cost_ebs
271276
iopscost = 0
272277
if (iops !== undefined && iops > opts.config.free_iops) {
@@ -283,7 +288,7 @@ postgresqls
283288
throughputcost = (throughput - opts.config.free_throughput) * opts.config.cost_throughput
284289
}
285290

286-
costs = podcount * (Math.max(corecost, memorycost) + diskcost + iopscost + throughputcost)
291+
costs = podcount * (Math.max(corecost, memorycost) + diskcost + iopscost + throughputcost) + elbcost
287292
return costs.toFixed(2)
288293
}
289294

ui/operator_ui/main.py

Lines changed: 17 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
# compute costs, i.e. https://www.ec2instances.info/?region=eu-central-1&selected=m5.2xlarge
102102
COST_CORE = float(getenv('COST_CORE', 0.0575)) # Core per hour m5.2xlarge / 8.
103103
COST_MEMORY = float(getenv('COST_MEMORY', 0.014375)) # Memory GB m5.2xlarge / 32.
104+
COST_ELB = float(getenv('COST_ELB', 0.03)) # per hour
104105

105106
# maximum and limitation of IOPS and throughput
106107
FREE_IOPS = float(getenv('FREE_IOPS', 3000))
@@ -334,6 +335,7 @@ def index():
334335
'cost_throughput': COST_THROUGHPUT,
335336
'cost_core': COST_CORE,
336337
'cost_memory': COST_MEMORY,
338+
'cost_elb': COST_ELB,
337339
'min_pods': MIN_PODS,
338340
'free_iops': FREE_IOPS,
339341
'free_throughput': FREE_THROUGHPUT,
@@ -523,6 +525,8 @@ def get_postgresqls():
523525
'namespaced_name': namespace + '/' + name,
524526
'full_name': namespace + '/' + name + ('/' + uid if uid else ''),
525527
'status': status,
528+
'num_elb': spec.get('enableMasterLoadBalancer', 0) + spec.get('enableReplicaLoadBalancer', 0) + \
529+
spec.get('enableMasterPoolerLoadBalancer', 0) + spec.get('enableReplicaPoolerLoadBalancer', 0),
526530
}
527531
for cluster in these(
528532
read_postgresqls(
@@ -662,49 +666,20 @@ def update_postgresql(namespace: str, cluster: str):
662666

663667
spec['volume']['throughput'] = throughput
664668

665-
if 'enableConnectionPooler' in postgresql['spec']:
666-
cp = postgresql['spec']['enableConnectionPooler']
667-
if not cp:
668-
if 'enableConnectionPooler' in o['spec']:
669-
del o['spec']['enableConnectionPooler']
669+
additional_specs = ['enableMasterLoadBalancer',
670+
'enableReplicaLoadBalancer',
671+
'enableConnectionPooler',
672+
'enableReplicaConnectionPooler',
673+
'enableMasterPoolerLoadBalancer',
674+
'enableReplicaPoolerLoadBalancer',
675+
]
676+
677+
for var in additional_specs:
678+
if postgresql['spec'].get(var):
679+
spec[var] = True
670680
else:
671-
spec['enableConnectionPooler'] = True
672-
else:
673-
if 'enableConnectionPooler' in o['spec']:
674-
del o['spec']['enableConnectionPooler']
675-
676-
if 'enableReplicaConnectionPooler' in postgresql['spec']:
677-
cp = postgresql['spec']['enableReplicaConnectionPooler']
678-
if not cp:
679-
if 'enableReplicaConnectionPooler' in o['spec']:
680-
del o['spec']['enableReplicaConnectionPooler']
681-
else:
682-
spec['enableReplicaConnectionPooler'] = True
683-
else:
684-
if 'enableReplicaConnectionPooler' in o['spec']:
685-
del o['spec']['enableReplicaConnectionPooler']
686-
687-
if 'enableReplicaLoadBalancer' in postgresql['spec']:
688-
rlb = postgresql['spec']['enableReplicaLoadBalancer']
689-
if not rlb:
690-
if 'enableReplicaLoadBalancer' in o['spec']:
691-
del o['spec']['enableReplicaLoadBalancer']
692-
else:
693-
spec['enableReplicaLoadBalancer'] = True
694-
else:
695-
if 'enableReplicaLoadBalancer' in o['spec']:
696-
del o['spec']['enableReplicaLoadBalancer']
697-
698-
if 'enableMasterLoadBalancer' in postgresql['spec']:
699-
rlb = postgresql['spec']['enableMasterLoadBalancer']
700-
if not rlb:
701-
if 'enableMasterLoadBalancer' in o['spec']:
702-
del o['spec']['enableMasterLoadBalancer']
703-
else:
704-
spec['enableMasterLoadBalancer'] = True
705-
else:
706-
if 'enableMasterLoadBalancer' in o['spec']:
707-
del o['spec']['enableMasterLoadBalancer']
681+
if var in o['spec']:
682+
del o['spec'][var]
708683

709684
if 'users' in postgresql['spec']:
710685
spec['users'] = postgresql['spec']['users']

0 commit comments

Comments
 (0)