Add ability to create Prometheus listener

This changes allows the user to create a Prometheus listener through Horizon.

Story 2010300
Task 46296

Change-Id: I34cd06054c9eecde8f4938786de1d52dc7c78614
This commit is contained in:
Pierre-Yves Jourel 2022-09-15 19:11:43 +00:00
parent b4e162d836
commit 4e48040c42
9 changed files with 88 additions and 8 deletions

View File

@ -216,6 +216,11 @@ def create_loadbalancer(request):
kwargs = {'from_state': 'PENDING_CREATE'}
thread.start_new_thread(poll_loadbalancer_status, args, kwargs)
if data['loadbalancer'].get('prometheus'):
args = (request, loadbalancer.id, create_prometheus_listener)
kwargs = {'from_state': 'PENDING_CREATE'}
thread.start_new_thread(poll_loadbalancer_status, args, kwargs)
return _get_sdk_object_dict(loadbalancer)
@ -261,6 +266,26 @@ def create_listener(request, **kwargs):
return _get_sdk_object_dict(listener)
def create_prometheus_listener(request, **kwargs):
"""Create a Prometheus listener
"""
data = request.DATA
conn = _get_sdk_connection(request)
listener = conn.load_balancer.create_listener(
protocol="PROMETHEUS",
protocol_port=data['loadbalancer'].get('prometheus_port'),
load_balancer_id=kwargs['loadbalancer_id'],
connection_limit=-1,
name="Prometheus"
)
return _get_sdk_object_dict(listener)
def create_l7_policy(request, **kwargs):
"""Create a new l7 policy.

View File

@ -54,7 +54,8 @@
////////////
function protocolChange(protocol) {
var defaultPort = { HTTP: 80, TERMINATED_HTTPS: 443 }[protocol];
var defaultPort = { HTTP: 80, TERMINATED_HTTPS: 443, PROMETHEUS: 9100 }[protocol];
var nextButtonSelector = "div.modal-footer button:nth-last-of-type(2)";
while (listenerPortExists(defaultPort)) {
defaultPort += 1;
}
@ -65,6 +66,18 @@
member.port = { HTTP: 80, TERMINATED_HTTPS: 80 }[protocol];
});
if (protocol === 'PROMETHEUS') {
$('#wizard-side-nav ul').children().slice(-4).hide();
$scope.model.context.create_pool = false;
$scope.model.context.create_monitor = false;
$(nextButtonSelector).attr("disabled", "");
} else {
$('#wizard-side-nav ul').children().slice(-4).show();
$scope.model.context.create_pool = true;
$scope.model.context.create_monitor = true;
$(nextButtonSelector).removeAttr("disabled");
}
if (protocol === 'TERMINATED_HTTPS') {
$('#wizard-side-nav ul li:last').show();
} else {

View File

@ -68,6 +68,11 @@
expect(listener.protocol_port).toBe(443);
});
it('should update port on protocol change to PROMETHEUS', function() {
ctrl.protocolChange('PROMETHEUS');
expect(listener.protocol_port).toBe(9100);
});
it('should update port on protocol change to TCP', function() {
ctrl.protocolChange('TCP');
expect(listener.protocol_port).toBeUndefined();

View File

@ -54,7 +54,7 @@
ng-change="ctrl.protocolChange(model.spec.listener.protocol)"
ng-disabled="model.context.id">
<option ng-repeat="protocol in model.listenerProtocols" value="{$ protocol $}"
ng-disabled="protocol==='TERMINATED_HTTPS' && model.certificatesError">{$ protocol $}</option>
ng-disabled="(protocol==='TERMINATED_HTTPS' && model.certificatesError) || (protocol==='PROMETHEUS' && model.spec.loadbalancer.prometheus)">{$ protocol $}</option>
</select>
</div>
</div>

View File

@ -15,3 +15,9 @@
The network on which to allocate the load balancer's IP address.
</translate>
</p>
<p>
<strong>Prometheus</strong>
<translate>
This option create a Prometheus listerner for you.
</translate>
</p>

View File

@ -117,6 +117,30 @@
</div>
</div>
</div>
<div class="col-xs-12 col-sm-8 col-md-6">
<div class="form-group">
<label class="control-label required" translate>Prometheus</label>
<div class="form-field">
<div class="btn-group">
<label class="btn btn-default"
ng-repeat="option in model.yesNoOptions"
ng-model="model.spec.loadbalancer.prometheus"
uib-btn-radio="option.value">{$ ::option.label $}</label>
</div>
</div>
</div>
</div>
</div>
<div class="row" ng-if="model.spec.loadbalancer.prometheus">
<div class="col-xs-12 col-sm-8 col-md-6">
<div class="form-group">
<label translate class="control-label" for="prometheus_port">Prometheus port</label>
<input name="prometheus_port" id="prometheus_port" type="number" class="form-control" ng-pattern="/^\d+$/" min="1" max="65535"
ng-model="model.spec.loadbalancer.prometheus_port"
ng-required="model.spec.loadbalancer.prometheus">
</div>
</div>
</div>
</div>

View File

@ -86,7 +86,7 @@
members: [],
networks: {},
flavors: {},
listenerProtocols: ['HTTP', 'TCP', 'TERMINATED_HTTPS', 'HTTPS', 'UDP', 'SCTP'],
listenerProtocols: ['HTTP', 'TCP', 'TERMINATED_HTTPS', 'HTTPS', 'UDP', 'SCTP', 'PROMETHEUS'],
availability_zones: {},
l7policyActions: ['REJECT', 'REDIRECT_TO_URL', 'REDIRECT_TO_POOL'],
l7ruleTypes: ['HOST_NAME', 'PATH', 'FILE_TYPE', 'HEADER', 'COOKIE'],
@ -156,7 +156,9 @@
vip_subnet_id: null,
flavor_id: null,
availability_zone: null,
admin_state_up: true
admin_state_up: true,
prometheus: false,
prometheus_port: null,
},
listener: {
id: null,

View File

@ -495,7 +495,7 @@
it('has array of listener protocols', function() {
expect(model.listenerProtocols).toEqual(['HTTP', 'TCP', 'TERMINATED_HTTPS', 'HTTPS',
'UDP', 'SCTP']);
'UDP', 'SCTP', 'PROMETHEUS']);
});
it('has array of pool lb_algorithms', function() {
@ -866,8 +866,9 @@
});
it('should initialize listener protocols', function() {
expect(model.listenerProtocols.length).toBe(6);
expect(model.listenerProtocols.length).toBe(7);
expect(model.listenerProtocols.indexOf('TERMINATED_HTTPS')).toBe(2);
expect(model.listenerProtocols.indexOf('PROMETHEUS')).toBe(6);
});
});
@ -917,7 +918,7 @@
});
it('should initialize listener protocols', function() {
expect(model.listenerProtocols.length).toBe(5);
expect(model.listenerProtocols.length).toBe(6);
expect(model.listenerProtocols.indexOf('TERMINATED_HTTPS')).toBe(-1);
});
});
@ -1358,7 +1359,7 @@
// to implement tests for them.
it('has the right number of properties', function() {
expect(Object.keys(model.spec).length).toBe(11);
expect(Object.keys(model.spec.loadbalancer).length).toBe(7);
expect(Object.keys(model.spec.loadbalancer).length).toBe(9);
expect(Object.keys(model.spec.listener).length).toBe(16);
expect(Object.keys(model.spec.l7policy).length).toBe(8);
expect(Object.keys(model.spec.l7rule).length).toBe(7);

View File

@ -0,0 +1,4 @@
---
features:
- |
Add the ability to create a Prometheus listener.