Skip to content

Commit

Permalink
New Dns debug endpoint (#735)
Browse files Browse the repository at this point in the history
* add new rest endpoint rest/dns?name= for dns resolution

* Istio Authors->Fortio Authors on leftover files
  • Loading branch information
ldemailly committed Mar 20, 2023
1 parent 86740eb commit 69ae5d0
Show file tree
Hide file tree
Showing 36 changed files with 186 additions and 63 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2016 Istio Authors
Copyright 2016 Fortio Authors
Copyright 2018 Fortio Authors
Copyright 2015 Michal Witkowski (dflag/)

Expand Down
40 changes: 32 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- 1.53.1 -->
<!-- 1.54.0 -->
# Fortio

[![Awesome Go](https://fortio.org/mentioned-badge.svg)](https://github.com/avelino/awesome-go#networking)
Expand Down Expand Up @@ -60,13 +60,13 @@ You can install from source:
The [releases](https://github.com/fortio/fortio/releases) page has binaries for many OS/architecture combinations (see assets):

```shell
curl -L https://github.com/fortio/fortio/releases/download/v1.53.1/fortio-linux_amd64-1.53.1.tgz \
curl -L https://github.com/fortio/fortio/releases/download/v1.54.0/fortio-linux_amd64-1.54.0.tgz \
| sudo tar -C / -xvzpf -
# or the debian package
wget https://github.com/fortio/fortio/releases/download/v1.53.1/fortio_1.53.1_amd64.deb
dpkg -i fortio_1.53.1_amd64.deb
wget https://github.com/fortio/fortio/releases/download/v1.54.0/fortio_1.54.0_amd64.deb
dpkg -i fortio_1.54.0_amd64.deb
# or the rpm
rpm -i https://github.com/fortio/fortio/releases/download/v1.53.1/fortio-1.53.1-1.x86_64.rpm
rpm -i https://github.com/fortio/fortio/releases/download/v1.54.0/fortio-1.54.0-1.x86_64.rpm
# and more, see assets in release page
```

Expand All @@ -76,7 +76,7 @@ On a MacOS you can also install Fortio using [Homebrew](https://brew.sh/):
brew install fortio
```

On Windows, download https://github.com/fortio/fortio/releases/download/v1.53.1/fortio_win_1.53.1.zip and extract `fortio.exe` to any location, then using the Windows Command Prompt:
On Windows, download https://github.com/fortio/fortio/releases/download/v1.54.0/fortio_win_1.54.0.zip and extract `fortio.exe` to any location, then using the Windows Command Prompt:
```
fortio.exe server
```
Expand Down Expand Up @@ -127,7 +127,7 @@ Full list of command line flags (`fortio help`):
<!-- use release/updateFlags.sh to update this section -->
<pre>
<!-- USAGE_START -->
Φορτίο 1.53.1 usage:
Φορτίο 1.54.0 usage:
fortio command [flags] target
where command is one of: load (load testing), server (starts ui, rest api,
http-echo, redirect, proxies, tcp-echo, udp-echo and grpc ping servers),
Expand Down Expand Up @@ -390,6 +390,8 @@ You can set a default value for all these by passing `-echo-server-default-param
* `/fortio/rest/stop` stops all current run or by run id (passing `runid=` query argument).
* `/fortio/rest/status` lists the current runs (or the options of a single one if `runid` is passed).

* DNS api for troubleshooting latency based records / view of the DNS where fortio server is running. `/fortio/rest/dns?name=x` resolves all the IPs for `x`.

The `report` mode is a readonly subset of the above directly on `/`.

There is also the GRPC health and ping servers, as well as the http->https redirector.
Expand All @@ -406,7 +408,8 @@ Fortio X.Y.Z grpc 'ping' server listening on tcp [::]:8079
Fortio X.Y.Z https redirector server listening on tcp [::]:8081
Fortio X.Y.Z http-echo server listening on tcp [::]:8080
Data directory is /Users/ldemailly/dev/fortio
REST API on /fortio/rest/run, /fortio/rest/status, /fortio/rest/stop
REST API on /fortio/rest/run, /fortio/rest/status, /fortio/rest/stop, /fortio/rest/dns
Debug endpoint on /debug, Additional Echo on /debug/echo/, Flags on /fortio/flags, and Metrics on /debug/metrics
UI started - visit:
http://localhost:8080/fortio/
(or any host/ip reachable on this server)
Expand Down Expand Up @@ -844,6 +847,27 @@ and you get in result.json:

- There is also the `fortio/rest/stop` endpoint to stop a run by its id or all runs if not specified.

### DNS Rest api example

```bash
$ curl -s localhost:8080/fortio/rest/dns?name=debug.fortio.org | jq
```
Returns
```json
{
"Name": "debug.fortio.org",
"IPv4": [
"18.222.136.83",
"192.9.142.5",
"192.9.227.83"
],
"IPv6": [
"2600:1f16:9c6:b400:282c:a766:6cab:4e82",
"2603:c024:c00a:d144:7cd0:4951:7106:96b8",
"2603:c024:c00a:d144:6663:5896:7efb:fbf3"
]
}
```

### GRPC load test

Expand Down
2 changes: 1 addition & 1 deletion Webtest.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#! /bin/bash
# Copyright 2017 Istio Authors.
# Copyright 2017 Fortio Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion bincommon/commonflags.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018 Istio Authors
// Copyright 2018 Fortio Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion cli/fortio_main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017 Istio Authors
// Copyright 2017 Fortio Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion debian/copyright
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Upstream-Name: fortio
Source: https://github.com/fortio/fortio/

Files: *
Copyright: 2017 Istio Authors.
Copyright: 2017 Fortio Authors.
License: Apache-2.0
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion echosrv/echo.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017 Istio Authors.
// Copyright 2017 Fortio Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion fcurl/fcurl.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018 Istio Authors
// Copyright 2018 Fortio Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion fgrpc/grpcrunner.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017 Istio Authors
// Copyright 2017 Fortio Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion fgrpc/grpcrunner_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017 Istio Authors.
// Copyright 2017 Fortio Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion fgrpc/pingsrv.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017 Istio Authors.
// Copyright 2017 Fortio Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion fgrpc/pingsrv_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017 Istio Authors.
// Copyright 2017 Fortio Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion fhttp/http_client.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017 Istio Authors
// Copyright 2017 Fortio Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion fhttp/http_loglevel_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017 Istio Authors
// Copyright 2017 Fortio Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion fhttp/http_server.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017 Istio Authors
// Copyright 2017 Fortio Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion fhttp/http_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017 Istio Authors
// Copyright 2017 Fortio Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion fhttp/http_utils.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017 Istio Authors
// Copyright 2017 Fortio Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion fhttp/httprunner.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017 Istio Authors
// Copyright 2017 Fortio Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion fhttp/httprunner_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017 Istio Authors.
// Copyright 2017 Fortio Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
45 changes: 28 additions & 17 deletions fnet/network.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017 Istio Authors
// Copyright 2017 Fortio Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -354,25 +354,12 @@ func checkCache(host, port string) (found bool, res net.IP) {
func ResolveByProto(ctx context.Context, host string, port string, proto string) (*HostPortAddr, error) {
log.Debugf("Resolve() called with host=%s port=%s proto=%s", host, port, proto)
dest := &HostPortAddr{}
if strings.HasPrefix(host, "[") && strings.HasSuffix(host, "]") {
log.Debugf("host %s looks like an IPv6, stripping []", host)
host = host[1 : len(host)-1]
}
var err error
if host == "" {
return nil, fmt.Errorf("can't resolve empty host")
}
dest.Port, err = net.LookupPort(proto, port)
if err != nil {
log.Errf("Unable to resolve %s port '%s' : %v", proto, port, err)
return nil, err
}
isAddr := net.ParseIP(host)
if isAddr != nil {
dest.IP = isAddr
log.LogVf("Resolved %s:%s already an IP as addr %+v", host, port, dest)
return dest, nil
}
filter := FlagResolveIPType.Get()
dnsMethod := FlagResolveMethod.Get()
idx := uint32(0)
Expand All @@ -384,10 +371,9 @@ func ResolveByProto(ctx context.Context, host string, port string, proto string)
}
dnsMutex.Unlock()
}
addrs, err := net.DefaultResolver.LookupIP(ctx, filter, host)
addrs, err := ResolveAll(ctx, host, filter)
if err != nil {
log.Errf("Unable to lookup '%s' : %v", host, err)
return nil, err
return nil, err // error already logged
}
l := uint32(len(addrs))
if l > 1 {
Expand Down Expand Up @@ -421,6 +407,31 @@ func ResolveByProto(ctx context.Context, host string, port string, proto string)
return dest, nil
}

// ResolveAll returns all the IPs for the host.
// resolveType is a filter for the IPs to use, `ip4` for ipv4, `ip6` for ipv6, or `ip` or "" for both.
func ResolveAll(ctx context.Context, host, resolveType string) ([]net.IP, error) {
if strings.HasPrefix(host, "[") && strings.HasSuffix(host, "]") {
log.Debugf("host %s looks like an IPv6, stripping []", host)
host = host[1 : len(host)-1]
}
if host == "" {
return nil, fmt.Errorf("can't resolve empty host")
}
isAddr := net.ParseIP(host)
if isAddr != nil {
log.LogVf("Resolved %s already an IP as addr", host)
return []net.IP{isAddr}, nil
}
if resolveType == "" {
resolveType = "ip"
}
addrs, err := net.DefaultResolver.LookupIP(ctx, resolveType, host)
if err != nil {
log.Errf("Unable to lookup %q: %v", host, err)
}
return addrs, err
}

// UDPResolveDestination returns the UDP address of the "host:port" suitable for net.Dial.
// nil and the error in case of errors.
func UDPResolveDestination(ctx context.Context, dest string) (*net.UDPAddr, error) {
Expand Down
21 changes: 21 additions & 0 deletions fnet/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,27 @@ func TestDebugSummary(t *testing.T) {
}
}

func TestResolveIP6(t *testing.T) {
a, err := fnet.ResolveAll(context.Background(), "[::1]", "ip")
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
if len(a) != 1 {
t.Errorf("Unexpected number of addresses: %d", len(a))
}
aStr := a[0].String()
if aStr != "::1" {
t.Errorf("Unexpected address: %s", aStr)
}
}

func TestResolveNoFilter(t *testing.T) {
_, err := fnet.ResolveAll(context.Background(), "localhost", "")
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
}

// --- max logging for tests

func init() {
Expand Down
2 changes: 1 addition & 1 deletion histogram/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017 Istio Authors
// Copyright 2017 Fortio Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion log/logger.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017 Istio Authors
// Copyright 2017 Fortio Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion periodic/periodic.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017 Istio Authors
// Copyright 2017 Fortio Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion periodic/periodic_loglevel_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017 Istio Authors
// Copyright 2017 Fortio Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion periodic/periodic_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017 Istio Authors
// Copyright 2017 Fortio Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down

0 comments on commit 69ae5d0

Please sign in to comment.