Page MenuHomePhabricator

Fix inconsistency between production and AQS 2.0 response codes
Closed, ResolvedPublicBUG REPORT

Description

In some situations, the AQS 2.0 Unique Devices service returns success (200) and empty data, while the production service returns an error (404). We should match production behavior.

Here are urls that illustrate this inconsistency:

https://wikimedia.org/api/rest_v1/metrics/unique-devices/wrongwebsitefortesting.org/all-sites/monthly/20220701/20220929
http://localhost:8080/metrics/unique-devices/wrongwebsitefortesting.org/all-sites/monthly/20220701/20220929

Here are some more:

http://localhost:8080/metrics/unique-devices/en.m.wikipedia/all-sites/daily/20210101/20210201
https://wikimedia.org/api/rest_v1/metrics/unique-devices/en.m.wikipedia/all-sites/daily/20210101/20210201

Note:
Where reasonably possible, we should extract changes that affect all AQS 2.0 services to the aqsassist package. That way, we don't have to make this same change in all the services, and if further changes are necessary we will then only have to make them in one place.

If a change is likely to affect all Go services at WMF and not just AQS 2.0, we should extract that to the Go service scaffolding, so that future services can benefit from it.

Event Timeline

@FGoodwin A couple of the scenarios still show the wrong response codes

Scenario 1:

if a user enters the mobile version endpoints like "en.m.wikipedia.com"

Note: I used python here so you can create a .py file and just run the below

prod

import requests


prod_url = 'https://wikimedia.org/api/rest_v1/metrics/unique-devices/en.m.wikipedia.org/all-sites/daily/20190129/20200229'

header = {"accept": "application/json",
          "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36"}

response = requests.get(prod_url, headers=header)

print(response.status_code)
print(response.json())

local ( I run mine on port 8089)

import requests



base_url = "http://localhost:8089/metrics/unique-devices/en.m.wikipedia.org/all-sites/daily/20190129/20200229"

header = {"accept": "application/json",
          "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36"}

response = requests.get(base_url, headers=header)

print(response.status_code)
print(response.json())

Scenario 2:
When user enters a completely invalid proect

prod

import requests


prod_url = 'https://wikimedia.org/api/rest_v1/metrics/unique-devices/wrongwebsitefortesting.org/all-sites/daily/20190129/20200229'

header = {"accept": "application/json",
          "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36"}

response = requests.get(prod_url, headers=header)

print(response.status_code)
print(response.json())

local

import requests

base_url = "http://localhost:8089/metrics/unique-devices/wrongwebsitefortesting.org/all-sites/daily/20190129/20200229"

header = {"accept": "application/json",
          "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36"}

response = requests.get(base_url, headers=header)

print(response.status_code)
print(response.json())

Test status : QA PASS

Scenario : With valid project:

project = en.wikipedia.org
status code = 200 ( PASS )

Scenario : With invalid project:

project = en.wikipedia.org/wiki/.invalid
status code = 404 ( PASS )

Scenario : With Wrong project:

project = wrongwebsitefortesting.org
status code = 404 ( PASS )

Scenario : With Wrong granularity:

granularity = wrongdate
status code = 400 ( PASS )

Scenario : With Earlier date later than end date:

date = /daily/20200529/20200229
status code = 400 ( PASS )

Scenario : With mobile version of project

project = /en.m.wikipedia.org
status code = 404 ( PASS )