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 Server-Timing header to unread page #806

Merged
merged 1 commit into from Dec 18, 2020

Conversation

cljoly
Copy link
Contributor

@cljoly cljoly commented Sep 23, 2020

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

Copy link
Member

@fguillot fguillot left a comment

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
Copy link
Contributor Author

cljoly commented Sep 28, 2020

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
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 marked this pull request as ready for review November 10, 2020 22:35
@cljoly
Copy link
Contributor Author

cljoly commented Nov 16, 2020

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

config/parser.go Outdated Show resolved Hide resolved
@cljoly cljoly force-pushed the server-timing-header branch 2 times, most recently from d03bcf3 to 373f952 Compare November 22, 2020 15:07
@@ -77,6 +77,8 @@ func (p *Parser) parseLines(lines []string) (err error) {
p.opts.logDateTime = parseBool(value, defaultLogDateTime)
case "DEBUG":
p.opts.debug = parseBool(value, defaultDebug)
case "SERVER_TIMING_HEADER":
Copy link
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.

Copy link
Contributor Author

@cljoly cljoly Nov 29, 2020

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?

@@ -69,6 +70,7 @@ type Options struct {
httpService bool
schedulerService bool
debug bool
timing bool
Copy link
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
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
Copy link
Contributor Author

cljoly commented Dec 17, 2020

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.

None yet

2 participants