Networks and Ports
~~~~~~~~~~~~~~~~~~
-All monitoring services can have the network and port they bind to configured with a yaml service specification
+All monitoring services can have the network and port they bind to configured with a yaml service specification. By default
+cephadm will use ``https`` protocol when configuring Grafana daemons unless the user explicitly sets the protocol to ``http``.
example spec file:
- 192.169.142.0/24
spec:
port: 4200
+ protocol: http
Using custom images
~~~~~~~~~~~~~~~~~~~
deps.append(self.get_active_mgr().name())
deps.append(str(self.get_module_option_ex('prometheus', 'server_port', 9283)))
deps.append(str(self.service_discovery_port))
+ # prometheus yaml configuration file (generated by prometheus.yml.j2) contains
+ # a scrape_configs section for each service type. This should be included only
+ # when at least one daemon of the corresponding service is running. Therefore,
+ # an explicit dependency is added for each service-type to force a reconfig
+ # whenever the number of daemons for those service-type changes from 0 to greater
+ # than zero and vice versa.
deps += [s for s in ['node-exporter', 'alertmanager', 'ingress'] if self.cache.get_daemons_by_service(s)]
else:
need = {
'services/grafana/grafana.ini.j2', {
'initial_admin_password': spec.initial_admin_password,
'http_port': daemon_spec.ports[0] if daemon_spec.ports else self.DEFAULT_SERVICE_PORT,
+ 'protocol': spec.protocol,
'http_addr': daemon_spec.ip if daemon_spec.ip else ''
})
assert dd.hostname is not None
addr = dd.ip if dd.ip else self._inventory_get_fqdn(dd.hostname)
port = dd.ports[0] if dd.ports else self.DEFAULT_SERVICE_PORT
- service_url = build_url(scheme='https', host=addr, port=port)
+ spec = cast(GrafanaSpec, self.mgr.spec_store[dd.service_name()].spec)
+ service_url = build_url(scheme=spec.protocol, host=addr, port=port)
self._set_service_url_on_dashboard(
'Grafana',
'dashboard get-grafana-api-url',
org_role = 'Viewer'
[server]
domain = 'bootstrap.storage.lab'
- protocol = https
+ protocol = {{ protocol }}
cert_file = /etc/grafana/certs/cert_file
cert_key = /etc/grafana/certs/cert_key
http_port = {{ http_port }}
"placement": {
"count": 1
},
- "service_type": "grafana"
+ "service_type": "grafana",
+ "protocol": "https"
},
{
"placement": {
config: Optional[Dict[str, str]] = None,
networks: Optional[List[str]] = None,
port: Optional[int] = None,
+ protocol: Optional[str] = 'https',
initial_admin_password: Optional[str] = None,
extra_container_args: Optional[List[str]] = None,
custom_configs: Optional[List[CustomConfig]] = None,
extra_container_args=extra_container_args, custom_configs=custom_configs)
self.initial_admin_password = initial_admin_password
+ self.protocol = protocol
+
+ def validate(self) -> None:
+ super(GrafanaSpec, self).validate()
+ if self.protocol not in ['http', 'https']:
+ err_msg = f"Invalid protocol '{self.protocol}'. Valid values are: 'http', 'https'."
+ raise SpecValidationError(err_msg)
yaml.add_representer(GrafanaSpec, ServiceSpec.yaml_representer)
from ceph.deployment.service_spec import HostPlacementSpec, PlacementSpec, \
ServiceSpec, RGWSpec, NFSServiceSpec, IscsiServiceSpec, AlertManagerSpec, \
- CustomContainerSpec
+ CustomContainerSpec, GrafanaSpec
from ceph.deployment.drive_group import DriveGroupSpec
from ceph.deployment.hostspec import SpecValidationError
assert ret == HostPlacementSpec.from_json(ret.to_json())
+@pytest.mark.parametrize(
+ "spec, raise_exception, msg",
+ [
+ (GrafanaSpec(protocol=''), True, '^Invalid protocol'),
+ (GrafanaSpec(protocol='invalid'), True, '^Invalid protocol'),
+ (GrafanaSpec(protocol='-http'), True, '^Invalid protocol'),
+ (GrafanaSpec(protocol='-https'), True, '^Invalid protocol'),
+ (GrafanaSpec(protocol='http'), False, ''),
+ (GrafanaSpec(protocol='https'), False, ''),
+ ])
+def test_apply_grafana(spec: GrafanaSpec, raise_exception: bool, msg: str):
+ if raise_exception:
+ with pytest.raises(SpecValidationError, match=msg):
+ spec.validate()
+ else:
+ spec.validate()
@pytest.mark.parametrize(
service_name: grafana
spec:
port: 1234
+ protocol: https
---
service_type: grafana
service_name: grafana
spec:
initial_admin_password: secure
port: 1234
+ protocol: https
---
service_type: ingress
service_id: rgw.foo