def handle_logstash(rc, ls_data): """ :param rc: connection to redis :type rc: StrictRedis :param ls_data: log stash record :type ls_data: dict """ dt_unixtime = string_dt_to_unixtime(ls_data["@timestamp"]) app.logger.debug("got ls_data: {}".format(ls_data)) # don't count statistics from builders if "clientip" in ls_data: if is_ip_from_builder_net(ls_data["clientip"]): return if "tags" not in ls_data: return tags = set(ls_data["tags"]) if "frontend" in tags and "repo_dl": name = REPO_DL_STAT_FMT.format(**ls_data) CounterStatLogic.incr(name=name, counter_type=CounterStatType.REPO_DL) db.session.commit() if "backend" in tags and "repomdxml" in tags: key = CHROOT_REPO_MD_DL_STAT_FMT.format(**ls_data) TimedStatEvents.add_event(rc, key, timestamp=dt_unixtime) if "backend" in tags and "rpm" in tags: key_chroot = CHROOT_RPMS_DL_STAT_FMT.format(**ls_data) key_project = PROJECT_RPMS_DL_STAT_FMT.format(**ls_data) TimedStatEvents.add_event(rc, key_chroot, timestamp=dt_unixtime) TimedStatEvents.add_event(rc, key_project, timestamp=dt_unixtime)
def render_generate_repo_file(copr_dir, name_release): name_release = app.config["CHROOT_NAME_RELEASE_ALIAS"].get( name_release, name_release) mock_chroot = coprs_logic.MockChrootsLogic.get_from_name( name_release, noarch=True).first() if not mock_chroot: raise ObjectNotFound("Chroot {} does not exist".format(name_release)) repo_id = "copr:{0}:{1}:{2}".format( app.config["PUBLIC_COPR_HOSTNAME"].split(":")[0], copr_dir.copr.owner_name.replace("@", "group_"), copr_dir.name) url = os.path.join(copr_dir.repo_url, '') # adds trailing slash repo_url = generate_repo_url(mock_chroot, url) pubkey_url = urljoin(url, "pubkey.gpg") response = flask.make_response( flask.render_template("coprs/copr_dir.repo", copr_dir=copr_dir, url=repo_url, pubkey_url=pubkey_url, repo_id=repo_id)) response.mimetype = "text/plain" response.headers["Content-Disposition"] = \ "filename={0}.repo".format(copr_dir.repo_name) name = REPO_DL_STAT_FMT.format( **{ 'copr_user': copr_dir.copr.user.name, 'copr_project_name': copr_dir.copr.name, 'copr_name_release': name_release, }) CounterStatLogic.incr(name=name, counter_type=CounterStatType.REPO_DL) db.session.commit() return response
def render_generate_repo_file(copr_dir, name_release, arch=None): copr = copr_dir.copr # redirect the aliased chroot only if it is not enabled yet if not any( [ch.name.startswith(name_release) for ch in copr.active_chroots]): name_release = app.config["CHROOT_NAME_RELEASE_ALIAS"].get( name_release, name_release) # if the arch isn't specified, find the fist one starting with name_release searched_chroot = name_release if not arch else name_release + "-" + arch mock_chroot = None for mc in copr.active_chroots: if not mc.name.startswith(searched_chroot): continue mock_chroot = mc if not mock_chroot: raise ObjectNotFound("Chroot {} does not exist in {}".format( searched_chroot, copr.full_name)) # append multilib counterpart repo only upon explicit request (ach != None), # and only if the chroot actually is multilib capable multilib_on = (arch and copr.multilib and mock_chroot in copr.active_multilib_chroots) # normal, arch agnostic repofile response_content = render_repo_template(copr_dir, mock_chroot) if multilib_on: # slightly lower cost than the default dnf cost=1000 response_content += "\n" + render_repo_template( copr_dir, mock_chroot, models.MockChroot.multilib_pairs[mock_chroot.arch], cost=1100) response = flask.make_response(response_content) response.mimetype = "text/plain" response.headers["Content-Disposition"] = \ "filename={0}.repo".format(copr_dir.repo_name) name = REPO_DL_STAT_FMT.format( **{ 'copr_user': copr_dir.copr.user.name, 'copr_project_name': copr_dir.copr.name, 'copr_name_release': name_release, }) CounterStatLogic.incr(name=name, counter_type=CounterStatType.REPO_DL) db.session.commit() return response
def get_copr_repo_dl_stat(cls, copr): # chroot -> stat_name chroot_by_stat_name = {} for chroot in copr.active_chroots: kwargs = { "copr_user": copr.owner.name, "copr_project_name": copr.name, "copr_name_release": chroot.name_release } chroot_by_stat_name[REPO_DL_STAT_FMT.format(**kwargs)] = chroot.name_release # [{counter: <value>, name: <stat_name>}, ...] stats = cls.get_multiply_same_type(counter_type=helpers.CounterStatType.REPO_DL, names_list=chroot_by_stat_name.keys()) # need: {chroot -> value, ... } repo_dl_stats = defaultdict(int) for stat in stats: repo_dl_stats[chroot_by_stat_name[stat.name]] = stat.counter return repo_dl_stats