Skip to content

Add Server-Timing header to unread page - #806

Merged
fguillot merged 1 commit into
miniflux:masterfrom
cljoly:server-timing-header
Dec 18, 2020
Merged

fguillot merged 1 commit into
miniflux:masterfrom
cljoly:server-timing-header

Conversation

@cljoly

@cljoly cljoly commented Sep 23, 2020 •

Copy link
Copy Markdown
Contributor

To be used as a basis to discuss #722. Current metrics may not be the
most interesting ones.

This is not deactivable at the moment, the header is:

server-timing: prep;dur=30.548655,sql_unread;dur=8.762088,sql_entries;dur=16.670605,render;dur=566.738683

Do we want this feature to be configurable?

The construction advised by the library

defer timing.NewMetric(name).Start().Stop()

does not work, the metric has a duration of 0s. I suspect this is due to
the request being finalized too early for the header to be added. Some
more granular metrics as added in this patch may be more relevant anyway.

Example result in browser:
image

@fguillot fguillot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feature should be optional (disabled by default). It should have a config option to enable the timing headers. To avoid adding if/else everywhere, it could be done at the middleware level only.

I would like to suggest different names:

  • Not sure what prep means, perhaps something like pre_processing might be more explicit.
  • sql_count_unread_entries
  • sql_fetch_unread_entries
  • template_rendering

@cljoly

cljoly commented Sep 28, 2020

Copy link
Copy Markdown
Contributor Author

To deactivate headers by default, I could make a PR to the upstream library to add an option disabling healders:

 uiRouter.Use(func(h http.Handler) http.Handler {
        return servertiming.Middleware(h, servertiming.MiddlewareOpts{DisableHeaders: true})
 })

This would ensure that headers are not written in the final requests, even if the measurements would be gathered.

I’ve applied the suggested names.

@fguillot

Copy link
Copy Markdown
Member

Sure, if they accepts the PR it's ok.

@cljoly
cljoly marked this pull request as draft October 6, 2020 20:38
cljoly added a commit to cljoly/go-server-timing that referenced this pull request Oct 12, 2020
This option prevents metrics from being written in the corresponding
header of the response.

This is useful to collect the metrics all the time but have a setting to
actually write it in the answer. For instance, this is desirable for
miniflux/v2#806
@cljoly
cljoly force-pushed the server-timing-header branch from 1ce3a09 to 35f108c Compare November 10, 2020 22:02
@cljoly
cljoly marked this pull request as ready for review November 10, 2020 22:35
@cljoly

cljoly commented Nov 16, 2020 •

Copy link
Copy Markdown
Contributor Author

@fguillot I think this PR is ready for you to take another look, when you have time.

Comment thread config/parser.go Outdated
@cljoly
cljoly force-pushed the server-timing-header branch 2 times, most recently from d03bcf3 to 373f952 Compare November 22, 2020 15:07
Comment thread config/parser.go
p.opts.logDateTime = parseBool(value, defaultLogDateTime)
case "DEBUG":
p.opts.debug = parseBool(value, defaultDebug)
case "SERVER_TIMING_HEADER":

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see you have updated the variable here, but all occurrences should be updated as well.

@cljoly cljoly Nov 29, 2020 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, it should be fixed now.
Unless you meant to change the timing field as well?

@cljoly
cljoly force-pushed the server-timing-header branch from 373f952 to 0df0a06 Compare November 29, 2020 19:31
Comment thread config/options.go Outdated
httpService bool
schedulerService bool
debug bool
timing bool

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to rename this one as well, that would make it explicit.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@cljoly
cljoly force-pushed the server-timing-header branch 3 times, most recently from dbe2ff8 to 1b99598 Compare December 13, 2020 21:50
To be used as a basis to discuss miniflux#722. Current metrics may not be the
most interesting ones.

This is not deactivable at the moment, the header is:
```
server-timing: prep;dur=30.548655,sql_unread;dur=8.762088,sql_entries;dur=16.670605,render;dur=566.738683
```

The construction advised by the library
```
defer timing.NewMetric(name).Start().Stop()
```
does not work, the metric has a duration of 0s. I suspect this is due to
the request being finalized too early for the header to be added. Some
more granular metrics as added in this patch may be more relevant anyway.
@cljoly
cljoly force-pushed the server-timing-header branch from 1b99598 to f66aed5 Compare December 17, 2020 16:41
@cljoly

cljoly commented Dec 17, 2020

Copy link
Copy Markdown
Contributor Author

I think it is ready for you to take another look @fguillot.

@fguillot
fguillot merged commit f88e93a into miniflux:master Dec 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants