Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for server options (-s and -o) #19

Merged

Conversation

bazzani
Copy link
Contributor

@bazzani bazzani commented Jun 17, 2024

We want to be able to pass a server ID or fully qualified hostname to the speedtest CLI command so that we can use a specific server to test against, rather than the default server that the CLI selects for us.

This change adds two new mutually exclusive environment variables which can be used to specify either:

  1. SPEEDTEST_SERVER_ID - A server from the server list using its id
  2. SPEEDTEST_HOSTNAME - A server, from the server list, using its host's fully qualified domain name

Impact on the speedtest CLI command:

  1. If SPEEDTEST_SERVER_ID is specified, the -s option will be added

  2. If SPEEDTEST_HOSTNAME is specified, the -o option will be added

  3. If both environment variables are specified, the container will error out and not run the speedtest CLI command

  4. If neither of the new environment variables are not present, the CLI command will be called as usual with the default server

    • JSON=$(speedtest --accept-license --accept-gdpr -f json)
  5. If you specify an invalid server ID/host name you will see an error:

  • {"type":"log","timestamp":"2024-06-17T03:39:08Z","message":"Configuration - No servers defined (NoServersException)","level":"error"}

To get the available ids, sponsors, and hostnames from speedtest run:

  • curl -s https://cli.speedtest.net/api/cli/config | jq -r '.servers[] | "id: \(.id), sponsor: \(.sponsor), host: \(.host)"'

and you will get a response like:

id: 32298, sponsor: SYNLINQ, host: speedtest1.synlinq.de:8080
id: 44081, sponsor: 23M GmbH, host: speedtest.23m.com:8080
id: 53257, sponsor: LWLcom GmbH, host: netservice01.fra02.lwlcom.net:8080
id: 40094, sponsor: PVDataNet, host: speedtestde.pvdatanet.com:8080
id: 55462, sponsor: Twerion.net | Minecraft Server, host: speedtest.twerion.net:8080
id: 37492, sponsor: Melbicom, host: speedtest-fra.melbicom.net:8080
id: 10010, sponsor: fdcservers.net, host: lg-fra.fdcservers.net:8080
id: 54504, sponsor: Deutsche Glasfaser, host: speed2.dg-sys.net:8080
id: 46569, sponsor: wirsNET, host: speed1.wirsnet.com:8080
id: 23712, sponsor: kko.me | avrx.de, host: speedtest.kko.me:8080

Remove the port number from the entry and run the container with the new environment variable, for example:

  • docker run -e SPEEDTEST_SERVER_ID=32298 robinmanuelthiel/speedtest:latest
  • docker run -e SPEEDTEST_HOSTNAME=speedtest1.synlinq.de robinmanuelthiel/speedtest:latest

@bazzani
Copy link
Contributor Author

bazzani commented Jun 17, 2024

Hi @robinmanuelthiel, I have tested the container with the following scenarios and they all behave as I expected.

Please do let me know if you would like any changes made, or indeed if we should carry out some more testing.

  1. no server option environment variables specified (as-is behaviour)
  2. SPEEDTEST_SERVER_ID environment variable specified
  3. SPEEDTEST_HOSTNAME environment variable specified
  4. both SPEEDTEST_SERVER_ID and SPEEDTEST_HOSTNAME environment variables specified
  5. invalid SPEEDTEST_SERVER_ID environment variable specified
  6. invalid SPEEDTEST_HOSTNAME environment variable specified
Snags attached below, please expand to view

1.

2.

3.

4.

5.

6.

@bazzani bazzani force-pushed the add-support-for-server-flags branch 4 times, most recently from a78c2ff to bb13164 Compare June 17, 2024 04:40
We want to be able to pass a server ID or fully qualified hostname to
the speedtest CLI command so that we can use a specific server to test
against, rather than the default server that the CLI selects for us.

This change adds two new mutually exclusive environment variables which
can be used to specify either:
1. `SPEEDTEST_SERVER_ID` - A server from the server list using its id
2. `SPEEDTEST_HOSTNAME`  - A server, from the server list, using its
    host's fully qualified domain name

Impact on the speedtest CLI command:
1. If `SPEEDTEST_SERVER_ID` is specified, the `-s` option will be added

2. If `SPEEDTEST_HOSTNAME` is specified, the `-o` option will be added

3. If both environment variables are specified, the container will error
   out and not run the speedtest CLI command

4. If neither of the new environment variables are not present, the CLI
   command will be called as usual with the default server
   - `JSON=$(speedtest --accept-license --accept-gdpr -f json)`

5. If you specify an invalid server ID/host name you will see an error:
- `{"type":"log","timestamp":"2024-06-17T03:39:08Z","message":"Configuration - No servers defined (NoServersException)","level":"error"}`

---

To get the available ids, sponsors, and hostnames from speedtest run:
- `curl -s https://cli.speedtest.net/api/cli/config | jq -r '.servers[] | "id: \(.id), sponsor: \(.sponsor), host: \(.host)"'`

and you will get a response like:

```
id: 32298, sponsor: SYNLINQ, host: speedtest1.synlinq.de:8080
id: 44081, sponsor: 23M GmbH, host: speedtest.23m.com:8080
id: 53257, sponsor: LWLcom GmbH, host: netservice01.fra02.lwlcom.net:8080
id: 40094, sponsor: PVDataNet, host: speedtestde.pvdatanet.com:8080
id: 55462, sponsor: Twerion.net | Minecraft Server, host: speedtest.twerion.net:8080
id: 37492, sponsor: Melbicom, host: speedtest-fra.melbicom.net:8080
id: 10010, sponsor: fdcservers.net, host: lg-fra.fdcservers.net:8080
id: 54504, sponsor: Deutsche Glasfaser, host: speed2.dg-sys.net:8080
id: 46569, sponsor: wirsNET, host: speed1.wirsnet.com:8080
id: 23712, sponsor: kko.me | avrx.de, host: speedtest.kko.me:8080
```

Remove the port number from the entry and run the container with the new
environment variable, for example:
- `docker run -e SPEEDTEST_SERVER_ID=32298 robinmanuelthiel/speedtest:latest`
- `docker run -e SPEEDTEST_HOSTNAME=speedtest1.synlinq.de robinmanuelthiel/speedtest:latest`
@bazzani bazzani force-pushed the add-support-for-server-flags branch from bb13164 to cf30d79 Compare June 17, 2024 04:41
@robinmanuelthiel
Copy link
Owner

Looks lovely, thanks a lot!

@robinmanuelthiel robinmanuelthiel merged commit 817def7 into robinmanuelthiel:master Jun 17, 2024
1 check passed
@robinmanuelthiel robinmanuelthiel linked an issue Jun 17, 2024 that may be closed by this pull request
@bazzani bazzani deleted the add-support-for-server-flags branch June 17, 2024 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Define server to speedtest
2 participants