Skip to content

Conversation

@davidfowl
Copy link
Member

@davidfowl davidfowl commented Jul 24, 2021

  • Dump configured values in a JSON blob and emit an event
{
  "AllowSynchronousIO": false,
  "AddServerHeader": true,
  "AllowAlternateSchemes": false,
  "AllowResponseHeaderCompression": true,
  "EnableAltSvc": false,
  "IsDevCertLoaded": true,
  "RequestHeaderEncodingSelector": "default",
  "ResponseHeaderEncodingSelector": "default",
  "Limits": {
    "KeepAliveTimeout": "00:02:10",
    "MaxConcurrentConnections": null,
    "MaxConcurrentUpgradedConnections": null,
    "MaxRequestBodySize": 30000000,
    "MaxRequestBufferSize": 1048576,
    "MaxRequestHeaderCount": 100,
    "MaxRequestHeadersTotalSize": 32768,
    "MaxRequestLineSize": 8192,
    "MaxResponseBufferSize": 65536,
    "MinRequestBodyDataRate": "Bytes per second: 240, Grace Period: 00:00:05",
    "MinResponseDataRate": "Bytes per second: 240, Grace Period: 00:00:05",
    "RequestHeadersTimeout": "00:00:30",
    "Http2": {
      "MaxStreamsPerConnection": 100,
      "HeaderTableSize": 4096,
      "MaxFrameSize": 16384,
      "MaxRequestHeaderFieldSize": 16384,
      "InitialConnectionWindowSize": 131072,
      "InitialStreamWindowSize": 98304,
      "KeepAlivePingDelay": "10675199.02:48:05.4775807",
      "KeepAlivePingTimeout": "00:00:20"
    },
    "Http3": {
      "HeaderTableSize": 0,
      "MaxRequestHeaderFieldSize": 16384
    }
  },
  "ListenOptions": [
    {
      "Address": "https://127.0.0.1:7030",
      "IsTls": true,
      "Protocols": "Http1AndHttp2"
    },
    {
      "Address": "https://[::1]:7030",
      "IsTls": true,
      "Protocols": "Http1AndHttp2"
    },
    {
      "Address": "http://127.0.0.1:5030",
      "IsTls": false,
      "Protocols": "Http1AndHttp2"
    },
    {
      "Address": "http://[::1]:5030",
      "IsTls": false,
      "Protocols": "Http1AndHttp2"
    }
  ]
}

The payload size is event source and LOH safe so >= 2K and 4K (with more listen options).

Contributes to #34578

- Dump configured values in a dictionary and emit an event with the pairs
@JamesNK
Copy link
Member

JamesNK commented Jul 24, 2021

EventSource only allows primitive values afaik. If you want to use eventsource then could could log each name/value in a separate call.

Alternatively, DiagnosticSource supports passing a dictionary.

@davidfowl
Copy link
Member Author

@noahfalk did some testing and a dictionary worked the other day. But maybe only in narrow cases. I'll likely use JSON if tho doesn't work

@davidfowl
Copy link
Member Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@davidfowl
Copy link
Member Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@shirhatti
Copy link
Contributor

I'm a little worried about the options going out of sync with the event. Assuming we use this pattern of adding Serialize method everywhere maybe have an analyzer to detect that?

But besides that, looks good to me 👍🏾

@Tratcher
Copy link
Member

IsDevCertLoaded is internal, do we want to log it?

@davidfowl
Copy link
Member Author

I'm a little worried about the options going out of sync with the event. Assuming we use this pattern of adding Serialize method everywhere maybe have an analyzer to detect that?

Code reviewz! But a valid concern. We can add a comment to the file but yeah, an analyzer could probably detect it.

IsDevCertLoaded is internal, do we want to log it?

Seems useful for debugging.

@davidfowl davidfowl marked this pull request as ready for review July 26, 2021 23:51
@davidfowl davidfowl requested a review from BrennanConroy as a code owner July 26, 2021 23:51
@davidfowl
Copy link
Member Author

I should probably add a test

[NonEvent]
public void Configuration(KestrelServerOptions options)
{
var bufferWriter = new ArrayBufferWriter<byte>();
Copy link
Member

Choose a reason for hiding this comment

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

Is there an equivalent of checking log level here? Only want to write JSON if Informational and above events are being used.

Copy link
Member

Choose a reason for hiding this comment

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

This:

if (IsEnabled(EventLevel.Informational, EventKeywords.None))

Copy link
Member

Choose a reason for hiding this comment

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

This is checked in AddServerOptions.

Copy link
Member

Choose a reason for hiding this comment

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

The Configuration event is invoked from OnEventCommand and that path ideally would also test the level. If that level test was here it would make it easy to have it enforced uniformly. Currently Configuration() is also a public API so any other code could become a new caller in the future.

@halter73
Copy link
Member

"ListenOptions": []

Do we want to log the addresses configured by the IServerAddressesFeature when there are no ListenOptions and when IServerAddressesFeature.PreferHostingUrls is true? Otherwise this might be a little misleading.

@davidfowl
Copy link
Member Author

I do but it feels weird to put it on the object. Maybe it's fine?

Assert.Equal(Guid.Empty, connectionStop.RelatedActivityId);

Assert.Equal(eventIndex, events.Count);
}
Copy link
Member

Choose a reason for hiding this comment

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

Your choice in deciding how much you care, but if you want to you could write a unit test that deserializes the serialized JSON to see if the value round trips. Another option would be reflecting over all property names to confirm that they match the names observed in the JSON.

Copy link
Member Author

Choose a reason for hiding this comment

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

I will write a test that JSON deserializes

Copy link
Member

@noahfalk noahfalk left a comment

Choose a reason for hiding this comment

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

LGTM

@davidfowl
Copy link
Member Author

Do we want to log the addresses configured by the IServerAddressesFeature when there are no ListenOptions and when IServerAddressesFeature.PreferHostingUrls is true? Otherwise this might be a little misleading.

Dumped out OptionsInUse (seems to work well).

@davidfowl davidfowl enabled auto-merge (squash) July 29, 2021 07:48
@davidfowl davidfowl merged commit 2ee3f4a into main Jul 29, 2021
@davidfowl davidfowl deleted the davidfowl/kestrel-options-event branch July 29, 2021 10:44
@ghost ghost added this to the 6.0-rc1 milestone Jul 29, 2021
@davidfowl davidfowl mentioned this pull request Aug 12, 2021
9 tasks
@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Jun 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions feature-kestrel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants