{"id":18555394,"url":"https://github.com/bearloga/wmf-pai-test","last_synced_at":"2025-07-18T07:08:02.957Z","repository":{"id":146996695,"uuid":"206839462","full_name":"bearloga/wmf-pai-test","owner":"bearloga","description":"API endpoint for testing Product Analytics Infrastructure working group's Event Platform Client libraries","archived":false,"fork":false,"pushed_at":"2020-08-28T14:12:54.000Z","size":36,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-04T14:56:38.995Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bearloga.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-09-06T17:04:28.000Z","updated_at":"2020-08-28T14:12:57.000Z","dependencies_parsed_at":"2023-05-29T14:15:25.918Z","dependency_job_id":null,"html_url":"https://github.com/bearloga/wmf-pai-test","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/bearloga/wmf-pai-test","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bearloga%2Fwmf-pai-test","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bearloga%2Fwmf-pai-test/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bearloga%2Fwmf-pai-test/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bearloga%2Fwmf-pai-test/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bearloga","download_url":"https://codeload.github.com/bearloga/wmf-pai-test/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bearloga%2Fwmf-pai-test/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265716306,"owners_count":23816354,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T21:26:25.728Z","updated_at":"2025-07-18T07:08:02.923Z","avatar_url":"https://github.com/bearloga.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Test endpoint\n\nThis repository contains code and instructions for setting up a web API for testing Product Analytics Infrastructure working group's Event Platform Client libraries. It relies on the [{plumber}](https://www.rplumber.io/) package for [R](https://www.r-project.org/).\n\nIt makes the following endpoints available at `BASE_URL=\"https://pai-test.wmflabs.org/\"`:\n\n- `/events`: records `POST` body in a log file\n- `/view`: displays logged requests as a table in a web page\n- `/clear`: empties the requests log\n- `/retain/n`: clears the log except the most recent `n` requests\n- `/streams`: returns the latest version of [streams configuration](stream-config.yaml) as JSON\n\nFor example, to log an event from the browser:\n\n```JS\nvar url = BASE_URL + \"/events\",\n    event = {\n      action: \"start\",\n    };\nnavigator.sendBeacon(url, JSON.stringify(event))\n```\n\n## Setup\n\n### Instance\n\nCreate a new Debian Buster instance on [CloudVPS](https://wikitech.wikimedia.org/wiki/Portal:Cloud_VPS) using the [Horizon UI](https://horizon.wikimedia.org/). `m1.small` flavor is fine. Make sure the `default` [security group](https://horizon.wikimedia.org/project/security_groups/) has a rule for Ingress Port 8000 CIDR 0.0.0.0/0 (`ALLOW IPv4 8000/tcp from 0.0.0.0/0`), then set up a DNS hostname in the [web proxies section of Horizon](https://horizon.wikimedia.org/project/proxy/) for the instance and be sure to change the port from 80 (default) to 8000.\n\n### Dependencies\n\n`sudo` while SSH'd to the instance (e.g. `test-endpoint-01.eqiad.wmflabs`):\n\n```bash\ndeb http://cran.r-project.org/bin/linux/debian buster-cran35/ \u003e\u003e /etc/apt/sources.list\napt-key adv --keyserver keys.gnupg.net --recv-key 'E19F5F87128899B192B1A2C2AD5F960A256A04AF'\n\napt-get update\n\napt-get install r-base r-base-dev libcurl4-openssl-dev libxml2-dev libssl-dev nodejs npm\nnpm install -g pm2\n```\n\n**Note**: see [this page](https://cran.r-project.org/bin/linux/debian/) for more information about installing R on Debian.\n\nThen, in R:\n\n```R\ninstall.packages(c(\"plumber\", \"urltools\", \"yaml\", \"tidyverse\"))\n```\n\n### Service\n\n`mkdir /usr/local/plumber` (`chown` if necessary), clone this repo, register the service with pm2, and save the settings in case of reboot:\n\n```bash\ngit clone https://github.com/bearloga/wmf-pai-test.git /usr/local/plumber/test\npm2 start --interpreter=\"Rscript\" /usr/local/plumber/test/run.R\npm2 save\n```\n\nFor more information, refer to [pm2 section](https://www.rplumber.io/docs/hosting.html#pm2) in [Plumber's docs](https://www.rplumber.io/docs/).\n\n**Note**: The instance's routable IP is hardcoded in [run.R](run.R). It would need to be changed in case of a new instance. In the future we may want to add an nginx config that reverse proxies from the routable ip to the local service and change the host in run.R back to the default of 127.0.0.1\n\n#### Maintainance\n\n```\ncd /usr/local/plumber/test\npm2 restart run.R\n```\n\nTo schedule `crontab`:\n\n```\n*/15 * * * * cd /usr/local/plumber/test \u0026\u0026 git pull\n```\n\n**Note**: may want to consider Puppetizing this so we could use the `notify` metaparameter with a `git` resource to automatically trigger `pm2` to restart if the repository was updated. For now we need to do this manually.\n\n## CloudVPS\n\n[Help:MediaWiki-Vagrant in Cloud VPS](https://wikitech.wikimedia.org/wiki/Help:MediaWiki-Vagrant_in_Cloud_VPS)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbearloga%2Fwmf-pai-test","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbearloga%2Fwmf-pai-test","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbearloga%2Fwmf-pai-test/lists"}