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

feat: support timestamp check on repomd #1248

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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
16 changes: 15 additions & 1 deletion modules/ocf_mirrors/files/healthcheck
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import requests
from prometheus_client import CollectorRegistry
from prometheus_client import Gauge
from prometheus_client import write_to_textfile
import xml.etree.ElementTree as ET

Mirror = namedtuple('Mirror', ['url', 'updated_at'])

Expand All @@ -34,6 +35,8 @@ def update_func(healthcheck):
return get_updated_datetime
elif healthcheck == 'recursive_ls':
return get_updated_recursive_ls
elif healthcheck == 'rpm':
return get_updated_rpm
else:
raise ValueError('Unsupported type: {}'.format(healthcheck))

Expand Down Expand Up @@ -98,7 +101,18 @@ def get_updated_manjaro(mirror_url):
updated_line, = [line for line in req.text.splitlines() if line.startswith('date=')]
return dateutil.parser.parse(updated_line.split('=', 1)[1])


def get_updated_rpm(mirror_url):
"""Find the time the repo was last updated.
Text in question should be of the form of a unix timestamp.
>>> get_updated_rpm(mirror_url)
datetime.datetime(2018, 1, 25, 21, 52, 18, tzinfo=tzutc())
"""
req = requests.get(mirror_url)
req.raise_for_status()
root = ET.fromstring(req.text)
timestamp = int(root[0].text)
return datetime.utcfromtimestamp(timestamp)

def write_prometheus(project, local, upstream):
registry = CollectorRegistry()
updated_upstream = Gauge(
Expand Down