Skip to content

Commit

Permalink
Merge pull request #550 from jacobweinstock/quieter-logging-for-iso
Browse files Browse the repository at this point in the history
Quieter HTTP 206 logging:

## Description

<!--- Please describe what this PR is going to change -->
Logging all 206 partial content requests from the middleware package creates a lot of messages per ISO request. In testing this was around 3000 requests. This is too many logs and will create too much noise. 

There is an HTTP middleware in Smee that logs a single line for all requests. This PR stops the middleware logger from logging anything when the `X-Global-Logging` header is set in the HTTP response. This allows HTTP handler functions to decide if middleware logging should occur or not.

For the ISO HTTP handler function we disable the middleware logging and only sample the HTTP 206 request messages. The following is an example output from an ISO mount using the 0.002% sampling rate. My estimate is that this sampling rate us about 5 - 10 log messages per ISO mount.

The first 8 lines are from when the system is booting up the ISO mounted as a virtual CDROM/DVD. The last 3 lines are from when HookOS boots up and mounts the ISO as a CDROM device.

```bash
{"level":"info","ts":1732046233.118308,"caller":"iso/iso.go:195","msg":"magic string found, patching the content","method":"GET","urlPath":"/hook-latest-lts-x86_64-efi-initrd.iso/iso/de-ad-be-ef-fe-ed/hook.iso","xff":"192.168.2.205, 192.168.2.205","remoteAddr":"192.168.2.205:35630","totalCount":48,"contentRange":"bytes 195100672-195133439/195420160"}
{"level":"info","ts":1732046241.343277,"caller":"iso/iso.go:152","msg":"HTTP GET method received with a 206 status code","method":"GET","urlPath":"/hook-latest-lts-x86_64-efi-initrd.iso/iso/de-ad-be-ef-fe-ed/hook.iso","xff":"192.168.2.205, 192.168.2.205","remoteAddr":"192.168.2.205:58796","totalCount":512}
{"level":"info","ts":1732046246.5436597,"caller":"iso/iso.go:152","msg":"HTTP GET method received with a 206 status code","method":"GET","urlPath":"/hook-latest-lts-x86_64-efi-initrd.iso/iso/de-ad-be-ef-fe-ed/hook.iso","xff":"192.168.2.205, 192.168.2.205","remoteAddr":"192.168.2.205:35488","totalCount":828}
{"level":"info","ts":1732046257.9578667,"caller":"iso/iso.go:152","msg":"HTTP GET method received with a 206 status code","method":"GET","urlPath":"/hook-latest-lts-x86_64-efi-initrd.iso/iso/de-ad-be-ef-fe-ed/hook.iso","xff":"192.168.2.205, 192.168.2.205","remoteAddr":"192.168.2.205:60176","totalCount":1424}
{"level":"info","ts":1732046269.1992714,"caller":"iso/iso.go:152","msg":"HTTP GET method received with a 206 status code","method":"GET","urlPath":"/hook-latest-lts-x86_64-efi-initrd.iso/iso/de-ad-be-ef-fe-ed/hook.iso","xff":"192.168.2.205, 192.168.2.205","remoteAddr":"192.168.2.205:46840","totalCount":2089}
{"level":"info","ts":1732046273.146468,"caller":"iso/iso.go:152","msg":"HTTP GET method received with a 206 status code","method":"GET","urlPath":"/hook-latest-lts-x86_64-efi-initrd.iso/iso/de-ad-be-ef-fe-ed/hook.iso","xff":"192.168.2.205, 192.168.2.205","remoteAddr":"192.168.2.205:49070","totalCount":2334}
{"level":"info","ts":1732046282.2612996,"caller":"iso/iso.go:152","msg":"HTTP GET method received with a 206 status code","method":"GET","urlPath":"/hook-latest-lts-x86_64-efi-initrd.iso/iso/de-ad-be-ef-fe-ed/hook.iso","xff":"192.168.2.205, 192.168.2.205","remoteAddr":"192.168.2.205:39434","totalCount":2897}
{"level":"info","ts":1732046282.5963988,"caller":"iso/iso.go:152","msg":"HTTP GET method received with a 206 status code","method":"GET","urlPath":"/hook-latest-lts-x86_64-efi-initrd.iso/iso/de-ad-be-ef-fe-ed/hook.iso","xff":"192.168.2.205, 192.168.2.205","remoteAddr":"192.168.2.205:39606","totalCount":2917}
{"level":"info","ts":1732046385.6623178,"caller":"iso/iso.go:142","msg":"HTTP HEAD method received","method":"HEAD","urlPath":"/hook-latest-lts-x86_64-efi-initrd.iso/iso/de-ad-be-ef-fe-ed/hook.iso","xff":"192.168.2.205, 192.168.2.205","remoteAddr":"192.168.2.205:36474","totalCount":3010}
{"level":"info","ts":1732046393.1938548,"caller":"iso/iso.go:142","msg":"HTTP HEAD method received","method":"HEAD","urlPath":"/hook-latest-lts-x86_64-efi-initrd.iso/iso/de-ad-be-ef-fe-ed/hook.iso","xff":"192.168.2.205, 192.168.2.205","remoteAddr":"192.168.2.205:36502","totalCount":3012}
{"level":"info","ts":1732046393.6070883,"caller":"iso/iso.go:195","msg":"magic string found, patching the content","method":"GET","urlPath":"/hook-latest-lts-x86_64-efi-initrd.iso/iso/de-ad-be-ef-fe-ed/hook.iso","xff":"192.168.2.205, 192.168.2.205","remoteAddr":"192.168.2.205:36814","totalCount":3045,"contentRange":"bytes 195035136-195158015/195420160"}
```

Also added is some checking/validation around content-size. A max content size of 512Kb is implemented.

And finally, the Tiltfile was updated and implements live updates. Any associated kustomize directories and files were removed and deploying Smee is done via the stack helm chart.

## Why is this needed

<!--- Link to issue you have raised -->

Fixes: #

## How Has This Been Tested?
<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran to -->
<!--- see how your change affects other areas of the code, etc. -->


## How are existing users impacted? What migration steps/scripts do we need?

<!--- Fixes a bug, unblocks installation, removes a component of the stack etc -->
<!--- Requires a DB migration script, etc. -->


## Checklist:

I have:

- [ ] updated the documentation and/or roadmap (if required)
- [ ] added unit or e2e tests
- [ ] provided instructions on how to upgrade
  • Loading branch information
jacobweinstock authored Nov 21, 2024
2 parents e74e9fa + edd662d commit 9a66ea8
Show file tree
Hide file tree
Showing 20 changed files with 352 additions and 328 deletions.
54 changes: 45 additions & 9 deletions Tiltfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,47 @@
local_resource(
'compile smee',
'make cmd/smee/smee-linux-amd64'
load('ext://restart_process', 'docker_build_with_restart')
load('ext://local_output', 'local_output')
load('ext://helm_resource', 'helm_resource')

local_resource('compile smee',
cmd='make cmd/smee/smee-linux-amd64',
deps=["go.mod", "go.sum", "internal", "Dockerfile", "cmd/smee/main.go", "cmd/smee/flag.go", "cmd/smee/backend.go"],
)
docker_build(
'quay.io/tinkerbell/smee',
'.',
dockerfile='Dockerfile',
only=['.']

docker_build_with_restart(
'quay.io/tinkerbell/smee',
'.',
dockerfile='Dockerfile',
entrypoint=['/usr/bin/smee'],
live_update=[
sync('cmd/smee/smee-linux-amd64', '/usr/bin/smee'),
],
)
default_registry('ttl.sh/meohmy-dghentld')

default_trusted_proxies = local_output("kubectl get nodes -o jsonpath='{.items[*].spec.podCIDR}' | tr ' ' ','")
trusted_proxies = os.getenv('TRUSTED_PROXIES', default_trusted_proxies)
lb_ip = os.getenv('LB_IP', '')
stack_version = os.getenv('STACK_CHART_VERSION', '0.5.0')
stack_location = os.getenv('STACK_LOCATION', 'oci://ghcr.io/tinkerbell/charts/stack') # or a local path like '/home/tink/repos/tinkerbell/charts/tinkerbell/stack'
namespace = 'tink'

if lb_ip == '':
fail('Please set the LB_IP environment variable. This is required to deploy the stack.')

# to use a KinD cluster, add a macvlan interface into the KinD docker container. for example: `docker network connect macvlan kind-control-plane`
# Then uncomment the 2 interface lines below.
helm_resource('stack',
chart=stack_location,
namespace=namespace,
image_deps=['quay.io/tinkerbell/smee'],
image_keys=[('smee.image')],
flags=[
'--create-namespace',
'--version=%s' % stack_version,
'--set=global.trustedProxies={%s}' % trusted_proxies,
'--set=global.publicIP=%s' % lb_ip,
#'--set=stack.kubevip.interface=eth1',
#'--set=stack.relay.sourceInterface=eth1',
],
release_name='stack'
)
k8s_yaml(kustomize('./manifests/kustomize/overlays/kind'))
2 changes: 1 addition & 1 deletion cmd/smee/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func main() {
return cfg.iso.magicString
}(),
}
isoHandler, err := ih.Reverse()
isoHandler, err := ih.HandlerFunc()
if err != nil {
panic(fmt.Errorf("failed to create iso handler: %w", err))
}
Expand Down
6 changes: 6 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ toolchain go1.23.2

require (
github.com/ccoveille/go-safecast v1.2.0
github.com/diskfs/go-diskfs v1.4.2
github.com/fsnotify/fsnotify v1.8.0
github.com/ghodss/yaml v1.0.0
github.com/go-logr/logr v1.4.2
Expand Down Expand Up @@ -38,6 +39,8 @@ require (
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/djherbis/times v1.6.0 // indirect
github.com/elliotwutingfeng/asciiset v0.0.0-20230602022725-51bbb787efab // indirect
github.com/emicklei/go-restful/v3 v3.12.1 // indirect
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
Expand Down Expand Up @@ -74,12 +77,15 @@ require (
github.com/pierrec/lz4/v4 v4.1.19 // indirect
github.com/pin/tftp/v3 v3.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pkg/xattr v0.4.9 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/rs/zerolog v1.33.0 // indirect
github.com/sirupsen/logrus v1.9.4-0.20230606125235-dd1b4c2e81af // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/u-root/uio v0.0.0-20230305220412-3e8cd9d6bf63 // indirect
github.com/ulikunitz/xz v0.5.11 // indirect
github.com/vishvananda/netns v0.0.4 // indirect
github.com/x448/float16 v0.8.4 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.32.0 // indirect
Expand Down
19 changes: 19 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/diskfs/go-diskfs v1.4.2 h1:khBr9RTkqAZFaMYK7PP8NooL30hqj3bSgRmj3Ouguls=
github.com/diskfs/go-diskfs v1.4.2/go.mod h1:ss1uAUBhgDdEOewZFDWWpYqJFjNPbK7hYSjRoQE+D94=
github.com/djherbis/times v1.6.0 h1:w2ctJ92J8fBvWPxugmXIv7Nz7Q3iDMKNx9v5ocVH20c=
github.com/djherbis/times v1.6.0/go.mod h1:gOHeRAz2h+VJNZ5Gmc/o7iD9k4wW7NMVqieYCY99oc0=
github.com/elliotwutingfeng/asciiset v0.0.0-20230602022725-51bbb787efab h1:h1UgjJdAAhj+uPL68n7XASS6bU+07ZX1WJvVS2eyoeY=
github.com/elliotwutingfeng/asciiset v0.0.0-20230602022725-51bbb787efab/go.mod h1:GLo/8fDswSAniFG+BFIaiSPcK610jyzgEhWYPQwuQdw=
github.com/emicklei/go-restful/v3 v3.12.1 h1:PJMDIM/ak7btuL8Ex0iYET9hxM3CI2sjZtzpL63nKAU=
github.com/emicklei/go-restful/v3 v3.12.1/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
github.com/evanphx/json-patch/v5 v5.9.0 h1:kcBlZQbplgElYIlo/n1hJbls2z/1awpXxpRi0/FOJfg=
Expand Down Expand Up @@ -52,6 +58,8 @@ github.com/go-playground/validator/v10 v10.22.1 h1:40JcKH+bBNGFczGuoBYgX4I6m/i27
github.com/go-playground/validator/v10 v10.22.1/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI=
github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM=
github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
Expand Down Expand Up @@ -134,6 +142,8 @@ github.com/pin/tftp/v3 v3.1.0 h1:rQaxd4pGwcAJnpId8zC+O2NX3B2/NscjDZQaqEjuE7c=
github.com/pin/tftp/v3 v3.1.0/go.mod h1:xwQaN4viYL019tM4i8iecm++5cGxSqen6AJEOEyEI0w=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/xattr v0.4.9 h1:5883YPCtkSd8LFbs13nXplj9g9tlrwoJRjgpgMu1/fE=
github.com/pkg/xattr v0.4.9/go.mod h1:di8WF84zAKk8jzR1UBTEWh9AUlIZZ7M/JNt8e9B6ktU=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand All @@ -150,10 +160,13 @@ github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWN
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/sirupsen/logrus v1.9.4-0.20230606125235-dd1b4c2e81af h1:Sp5TG9f7K39yfB+If0vjp97vuT74F72r8hfRpP8jLU0=
github.com/sirupsen/logrus v1.9.4-0.20230606125235-dd1b4c2e81af/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tinkerbell/ipxedust v0.0.0-20241108174245-aa0c0298057d h1:MjxkPQbW7jGCgjMCjeS0Hs/o4yXqynEBDv1mUcFF+JI=
Expand All @@ -162,6 +175,8 @@ github.com/tinkerbell/tink v0.12.1 h1:5ZCiGY1te59Qz/udFlzjh1UwKtmFBPOgo/LSK0J9Jy
github.com/tinkerbell/tink v0.12.1/go.mod h1:H4w56sG0rMsEgHB3rBpW8/6KWKAvvAQWYHuZFpURkoU=
github.com/u-root/uio v0.0.0-20230305220412-3e8cd9d6bf63 h1:YcojQL98T/OO+rybuzn2+5KrD5dBwXIvYBvQ2cD3Avg=
github.com/u-root/uio v0.0.0-20230305220412-3e8cd9d6bf63/go.mod h1:eLL9Nub3yfAho7qB0MzZizFhTU2QkLeoVsWdHtDW264=
github.com/ulikunitz/xz v0.5.11 h1:kpFauv27b6ynzBNT/Xy+1k+fK4WswhN/6PN5WhFAGw8=
github.com/ulikunitz/xz v0.5.11/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/vishvananda/netlink v1.3.0 h1:X7l42GfcV4S6E4vHTsw48qbrV+9PVojNfIhZcwQdrZk=
github.com/vishvananda/netlink v1.3.0/go.mod h1:i6NetklAujEcC6fK0JPjT8qSwWyO0HLn4UKG+hGqeJs=
github.com/vishvananda/netns v0.0.4 h1:Oeaw1EM2JMxD51g9uhtC0D7erkIjgmj8+JZc26m1YX8=
Expand Down Expand Up @@ -218,7 +233,10 @@ golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220408201424-a24fb2fb8a0f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220622161953-175b2fd9d664/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down Expand Up @@ -264,6 +282,7 @@ gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
k8s.io/api v0.31.2 h1:3wLBbL5Uom/8Zy98GRPXpJ254nEFpl+hwndmk9RwmL0=
Expand Down
10 changes: 6 additions & 4 deletions internal/ipxe/http/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ func (h *loggingMiddleware) ServeHTTP(w http.ResponseWriter, req *http.Request)
if uri == "/metrics" {
log = false
}
if log {
h.log.V(1).Info("request", "method", method, "uri", uri, "client", client)
}

res := &responseWriter{ResponseWriter: w}
h.handler.ServeHTTP(res, req) // process the request

if log {
// The "X-Global-Logging" header allows all registered HTTP handlers to disable this global logging
// by setting the header to any non empty string. This is useful for handlers that handle partial content of
// larger file. The ISO handler, for example.
r := res.Header().Get("X-Global-Logging")

if log && r == "" {
h.log.Info("response", "method", method, "uri", uri, "client", client, "duration", time.Since(start), "status", res.statusCode)
}
}
Expand Down
Loading

0 comments on commit 9a66ea8

Please sign in to comment.