Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow enabling prometheus metrics #67

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ options:
type: string
default: ""
description: Username for the remote registry when configured as a pull-through cache.
debug-port:
type: int
default: 5001
description: The external port on which the docker registry debug server listens.
http-host:
type: string
default: ""
Expand All @@ -54,6 +58,10 @@ options:
type: string
default: "info"
description: Logging output level ('error', 'warn', 'info', or 'debug').
prometheus-metrics:
type: boolean
default: false
description: Enable/disable prometheus metrics.
registry-image:
type: string
default: "registry:2"
Expand Down
27 changes: 25 additions & 2 deletions lib/charms/layer/docker_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ def configure_registry():
if os.path.isfile(tls_ca):
http['tls']['clientcas'] = [tls_ca]
docker_volumes[tls_ca] = '/etc/docker/registry/ca.crt'

# debug https://docs.docker.com/registry/configuration/#debug
# The debug server always listens on port 5001, with debug-port used
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this link is a 404

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fun, looks like the registry was recently donated to the CNCF (as noted at https://docs.docker.com/registry/). Would you like all the URLs updated in this PR, or in a separate one? I've changed this URL specifically since it's directly related to the changes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah... just the one is fine.

# for mapping from the host network only.
if charm_config.get('prometheus-metrics'):
http['debug'] = {
'addr': '0.0.0.0:5001',
'prometheus': {'enabled': charm_config['prometheus-metrics']},
}
registry_config['http'] = http

# log (https://docs.docker.com/registry/configuration/#log)
Expand Down Expand Up @@ -418,6 +427,7 @@ def start_registry(name=None, run_args=None):
charm_config = hookenv.config()
image = charm_config.get('registry-image')
port = charm_config.get('registry-port')
debug_port = charm_config.get('debug-port')
if not name:
name = charm_config.get('registry-name')

Expand All @@ -431,10 +441,11 @@ def start_registry(name=None, run_args=None):
level=hookenv.ERROR)
raise
else:
# NB: config determines the port, but the container always listens to 5000
# NB: config determines the port, but the container always listens to 5000 and
# 5001
# https://docs.docker.com/registry/deploying/#customize-the-published-port
cmd = ['docker', 'run', '-d', '-p', '{}:5000'.format(port),
'--restart', 'unless-stopped']
'-p', '{}:5001'.format(debug_port), '--restart', 'unless-stopped']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, okay so we're port-forwarding the debug-port into the hard-coded port 5001 from above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, I based this off the registry-port config option.

# HTTP/HTTPS proxy configuration
http_proxy = charm_config.get('registry-http-proxy')
if http_proxy:
Expand All @@ -456,8 +467,18 @@ def start_registry(name=None, run_args=None):
level=hookenv.ERROR)
raise

previous_registry_port = charm_config.previous('registry-port')
previous_debug_port = charm_config.previous('debug-port')

if previous_registry_port:
hookenv.close_port(previous_registry_port)
hookenv.open_port(port)

if previous_debug_port:
hookenv.close_port(previous_debug_port)
if charm_config.get('prometheus-metrics'):
hookenv.open_port(debug_port)


def stop_registry(name=None, remove=True):
'''Stop a registry container.
Expand All @@ -470,6 +491,7 @@ def stop_registry(name=None, remove=True):
'''
charm_config = hookenv.config()
port = charm_config.get('registry-port')
debug_port = charm_config.get('debug-port')
if not name:
name = charm_config.get('registry-name')

Expand All @@ -494,6 +516,7 @@ def stop_registry(name=None, remove=True):
raise

hookenv.close_port(port)
hookenv.close_port(debug_port)


def write_tls(ca, cert, key):
Expand Down
2 changes: 2 additions & 0 deletions wheelhouse.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
calver
hatchling
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, why are these packages included? Neither are used.

Suggested change
calver
hatchling

Copy link
Contributor

@addyess addyess Oct 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I resolved an issue in the layer-docker which was requiring these packages. Please try without them @shanepelletier

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I was pretty sure I needed them for something. I've removed them now, thanks for fixing the root cause!

Loading