Skip to content

Instantly share code, notes, and snippets.

@Mossop
Created June 10, 2015 21:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mossop/d68f4c8079e32e7fca7d to your computer and use it in GitHub Desktop.
Save Mossop/d68f4c8079e32e7fca7d to your computer and use it in GitHub Desktop.
{"nbformat_minor": 0, "cells": [{"source": "Gets one ping per client who has signable add-ons installed and active. Each of pings is a list of addons for a client", "cell_type": "markdown", "metadata": {}}, {"execution_count": 8, "cell_type": "code", "source": "import ujson as json\n\nfrom moztelemetry.spark import get_pings, get_one_ping_per_client\n\ndef extract(ping):\n ping = json.loads(ping)\n\n addons = []\n activeAddons = ping[\"environment\"][\"addons\"][\"activeAddons\"]\n for id in activeAddons.keys():\n addon = activeAddons[id]\n if \"signedState\" in addon:\n addons.append(addon)\n return { \"clientID\": ping[\"clientID\"], \"addons\": addons }\n\npings = get_pings(sc, app=\"Firefox\", channel=\"nightly\", build_id=(\"20150603000000\", \"20150610999999\"), fraction=1)\n\n# Filter to pings that have signable add-ons\npings = pings.map(extract)\npings = pings.filter(lambda x: len(x[\"addons\"]) > 0)\n\n# Reduce to one per client\npings = get_one_ping_per_client(pings).map(lambda x: x[\"addons\"])\npings.count()", "outputs": [{"execution_count": 8, "output_type": "execute_result", "data": {"text/plain": "33621"}, "metadata": {}}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "Reduces to only the add-ons that were signed by AMO. Each of expected is a list of addons for a client", "cell_type": "markdown", "metadata": {}}, {"execution_count": 9, "cell_type": "code", "source": "def only_signed(addons):\n return list(filter(lambda x: x[\"version\"][-9:] == \".1-signed\", addons))\n\nexpected = pings.map(only_signed).filter(lambda x: len(x) > 0)\nexpected.count()", "outputs": [{"execution_count": 9, "output_type": "execute_result", "data": {"text/plain": "23568"}, "metadata": {}}], "metadata": {"collapsed": false, "trusted": true}}, {"execution_count": 10, "cell_type": "code", "source": "# Reduces a list of add-ons to only those that pass a check function\ndef reduce_addon_state(check):\n def mapper(addons):\n return list(filter(check, addons))\n\n return mapper", "outputs": [], "metadata": {"collapsed": false, "trusted": true}}, {"source": "Gets the number of clients that have at least one add-on installed that doesn't meet the signing requirements (signedState <= 0)", "cell_type": "markdown", "metadata": {}}, {"execution_count": 11, "cell_type": "code", "source": "upset_users = pings.map(reduce_addon_state(lambda a: a[\"signedState\"] <= 0)).filter(lambda x: len(x) > 0)\nupset_users.count()", "outputs": [{"execution_count": 11, "output_type": "execute_result", "data": {"text/plain": "20289"}, "metadata": {}}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "Same again but only for add-ons that weren't sideloaded", "cell_type": "markdown", "metadata": {}}, {"execution_count": 12, "cell_type": "code", "source": "def not_foreign(addon):\n if not \"foreignInstall\" in addon:\n return True\n return addon[\"foreignInstall\"] == \"false\"\n\nupset_no_foreign = pings.map(reduce_addon_state(lambda a: not_foreign(a) and a[\"signedState\"] <= 0)).filter(lambda x: len(x) > 0)\nupset_no_foreign.count()", "outputs": [{"execution_count": 12, "output_type": "execute_result", "data": {"text/plain": "877"}, "metadata": {}}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "Gets the number of clients that have at least one AMO signed add-on installed that shows as broken (signedState < 0)", "cell_type": "markdown", "metadata": {}}, {"execution_count": 13, "cell_type": "code", "source": "broken = expected.map(reduce_addon_state(lambda a: a[\"signedState\"] < 0)).filter(lambda x: len(x) > 0)\nbroken.count()", "outputs": [{"execution_count": 13, "output_type": "execute_result", "data": {"text/plain": "461"}, "metadata": {}}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "Gets the number of clients that have at least one AMO signed add-on installed that shows as not signed (signedState == 0)", "cell_type": "markdown", "metadata": {}}, {"execution_count": 14, "cell_type": "code", "source": "missing = expected.map(reduce_addon_state(lambda a: a[\"signedState\"] == 0)).filter(lambda x: len(x) > 0)\nmissing.count()", "outputs": [{"execution_count": 14, "output_type": "execute_result", "data": {"text/plain": "18"}, "metadata": {}}], "metadata": {"collapsed": false, "trusted": true}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.9", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment