Jump to content

Tool:Iw

From Wikitech
Toolforge tools
Website https://iw.toolforge.org
Description Redirect to Toolforge tools
Keywords interwiki
Maintainer(s) BryanDavis (View all)
License GNU General Public License 3.0 or later
Admin log Tools.iw/SAL

Iw is a redirection service designed to be used for creating interwiki links to Toolforge tools.

Interwiki links are used in many Wikimedia wikis including Wikitech to create links to Toolforge tools. The interwiki system is prefix based and does not currently robustly support a single interwiki prefix targeting multiple hosts. This creates a problem for migration of Toolforge tools from path based routing (https://tools.wmflabs.org/$TOOL) to host based routing (https://$TOOL.toolforge.org/). The iw tool is an attempt to bridge this gap by providing a prefix (https://iw.toolforge.org/) with a backend that will redirect to other Toolforge tools.

On-wiki usage

See meta:Interwiki map for configuration management. Request for current configuration.

URLs with query parameters

The MediaWiki interwiki link syntax does not support URL query parameters. If you need to link to a Toolforge tool including a query string you should use external link syntax.

If desired you can use the {{fullurl:interwiki:remote page name|query_string}} magic word syntax to generate the link URL. This might look something like [{{fullurl:toolforge:guc|user=Example}} global contribs].

If you are the maintainer of a tool that needs query parameters for deep linking, consider adding your own support for encoding the query in the URL path instead of—or in addition to—query string usage. For example, instead of https://my-cool-tool.toolforge.org/?qid=Q7246 support something like https://my-cool-tool.toolforge.org/Q7246.

Implementation

Due to incompatible changes in the Kubernetes Ingress used in Toolforge, the implementation of iw.toolforge.org and iw.beta.toolforge.org has moved to the HAProxy load balancer layer of the Toolforge ingress stack.

The initial HAProxy implementation was introduced by changeset 1201847.

Testing

You can run the following script to verify URLs redirect as expected.

import requests

urls = {
    '/': 'https://wikitech.wikimedia.org/wiki/Portal:Toolforge',
    '/test': 'https://test.toolforge.org/',
    '/test/path/': 'https://test.toolforge.org/path/',
    '/test/?query=foo': 'https://test.toolforge.org/?query=foo'
}

for iw, expected in urls.items():
    iw_url = 'https://iw.toolforge.org' + iw
    req = requests.get(iw_url)
    assert req.url == expected, f'{iw_url} redirected to {expected}'
    print('.', end='')

print('')
print('All URLs redirected properly')

Legacy implementation

Originally, Iw was an Ingress only tool running on Toolforge's Kubernetes cluster. "Ingress only" means that the tool does not run any application code, but instead does all of its work using Kubernetes Ingress objects to configure the Kubernetes cluster's nginx ingress controller.

$ ssh login.toolforge.org
$ become iw
$ cd iw
$ vim ingress.yaml
$ kubectl apply --validate=true -f ingress.yaml
$HOME/iw/ingress.yaml
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: iw-domain
  namespace: tool-iw
  labels:
    name: iw-domain
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/use-regex: "true"
    # Redirect to the host based route for the target tool at *.toolforge.org
    nginx.ingress.kubernetes.io/temporal-redirect: https://$1.toolforge.org/$3$is_args$args
spec:
  rules:
    - host: iw.toolforge.org
      http:
        paths:
          - backend:
              service:
                name: unused
                port:
                  number: 8000
            path: /([A-Za-z0-9_-]+)(/|$)(.*)
            # Example path: /bash/random
            # Captures:
            # $0 == /bash/random
            # $1 == bash
            # $2 == /
            # $3 == random
            pathType: ImplementationSpecific
---
# T257104: ingress to handle https://iw.toolforge.org/
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: iw-root
  namespace: tool-iw
  labels:
    name: iw-root
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/temporal-redirect: https://toolforge.org/$is_args$args
spec:
  rules:
    - host: iw.toolforge.org
      http:
        paths:
          - backend:
              service:
                name: unused
                port:
                  number: 8000
            path: /
            pathType: Prefix