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

Json logging #836

Merged
merged 9 commits into from
Aug 29, 2019
Merged

Json logging #836

merged 9 commits into from
Aug 29, 2019

Conversation

arianvp
Copy link
Contributor

@arianvp arianvp commented Aug 23, 2019

No description provided.

@arianvp
Copy link
Contributor Author

arianvp commented Aug 23, 2019

Self-review:

Use of this type is discouraged. Note the following equivalence:

Data.Monoid.Last x === Maybe (Data.Semigroup.Last x)

In addition to being equivalent in the structural sense, the two
also have 'Monoid' instances that behave the same. This type will
be marked deprecated in GHC 8.8, and removed in GHC 8.10.
Users are advised to use the variant from "Data.Semigroup" and wrap
it in 'Maybe'.

@fisx fisx mentioned this pull request Aug 26, 2019
@arianvp arianvp marked this pull request as ready for review August 26, 2019 14:42
@@ -6,10 +6,3 @@
-- | Orphan instances for non-Wire-specific types and classes.
module Orphans () where
Copy link
Contributor

Choose a reason for hiding this comment

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

please decomission the orphanage. it's abandoned.

The old netstrings option is now deprecated, use logFormat instead.
logFormat takes presedence of netstrings if both are set.
If none are set, log format defaults to Plain
The implementation is very trivial at the moment. Namely "undefined" as
I think we should spend some time bikeshedding what the log format will
look like in JSON. Once we have done that I can implement it in a few
minutes
@arianvp
Copy link
Contributor Author

arianvp commented Aug 27, 2019

@fisx Example logs:

[galley] {"request":"N/A","targets":"336a018e-c8f1-49c4-b395-f781c94a255f","msgs":["D","Teams.addTeamMemberInternal"]}
[galley] {"code":"403","label":"legalhold-not-enabled","request":"N/A","msgs":["D","\"legal hold is not enabled for this team\""]
[galley] {"code":"400","label":"legalhold-invalid-key","request":"N/A","msgs":["D","\"legal hold service pubkey is invalid\""]}
[galley] {"request":"N/A","targets":"2a18c226-eb2f-4037-8d74-dac55a04417c","msgs":["D","LegalHold.approveDevice"]}
[galley] {"request":"N/A","targets":"[\"2a18c226-eb2f-4037-8d74-dac55a04417c\",\"65a325d3-5ec9-4669-97be-7605b76894db\"]","msgs":["D","LegalHold.removeSettings"]}
[galley] {"code":"403","label":"no-team-member","request":"N/A","msgs":["D","\"Requesting user is not a team member.\""]}
[galley] {"request":"N/A","targets":"[\"2a18c226-eb2f-4037-8d74-dac55a04417c\",\"65a325d3-5ec9-4669-97be-7605b76894db\"]","msgs":["D","LegalHold.removeSettings"]}
[galley] {"code":"403","label":"operation-denied","request":"N/A","msgs":["D","\"Insufficient permissions (missing ChangeLegalHoldTeamSettings)\""]}
[galley] {"request":"N/A","targets":"[\"2a18c226-eb2f-4037-8d74-dac55a04417c\",\"65a325d3-5ec9-4669-97be-7605b76894db\"]","msgs":["D","LegalHold.removeSettings"]}
[galley] {"code":"403","label":"access-denied","request":"N/A","msgs":["D","\"This operation requires reauthentication\""]}
[galley] {"request":"N/A","targets":"[\"2a18c226-eb2f-4037-8d74-dac55a04417c\",\"65a325d3-5ec9-4669-97be-7605b76894db\"]","msgs":["D","LegalHold.removeSettings"]}
[galley] {"request":"N/A","targets":"[\"2a18c226-eb2f-4037-8d74-dac55a04417c\",\"65a325d3-5ec9-4669-97be-7605b76894db\"]","msgs":["D","LegalHold.removeSettings'"]}
[galley] {"request":"N/A","targets":"[\"2a18c226-eb2f-4037-8d74-dac55a04417c\",\"65a325d3-5ec9-4669-97be-7605b76894db\"]","msgs":["D","LegalHold.removeSettings"]}
[galley] {"request":"N/A","targets":"[\"2a18c226-eb2f-4037-8d74-dac55a04417c\",\"65a325d3-5ec9-4669-97be-7605b76894db\"]","msgs":["D","LegalHold.removeSettings'"]}
[galley] {"code":"404","label":"no-team","request":"N/A","msgs":["D","\"team not found\""]}
[galley] {"code":"404","label":"no-team","request":"N/A","msgs":["D","\"team not found\""]}
[galley] {"request":"N/A","targets":"e5fc30a4-a24b-424b-a827-4ba1ee566882","msgs":["D","Teams.addTeamMemberInternal"]}
[galley] {"request":"N/A","targets":"[\"992eb7f9-2c28-4172-97b0-b44b9e5a4119\",\"e5fc30a4-a24b-424b-a827-4ba1ee566882\"]","msgs":["D","LegalHold.createSettings"]}
[galley] {"request":"N/A","targets":"e5fc30a4-a24b-424b-a827-4ba1ee566882","msgs":["D","LegalHold.requestDevice"]}

@arianvp arianvp requested a review from fisx August 27, 2019 13:02
@tiago-loureiro
Copy link
Contributor

[galley] {"request":"N/A","targets":"[\"2a18c226-eb2f-4037-8d74-dac55a04417c\",\"65a325d3-5ec9-4669-97be-7605b76894db\"]","msgs":["D","LegalHold.removeSettings"]}

The \" is due to the show . toByteString mentioned here

Also, I see that "D" shows up as "msgs", that should be a diff. field named "level"

@arianvp
Copy link
Contributor Author

arianvp commented Aug 27, 2019

Also, I see that "D" shows up as "msgs", that should be a diff. field named "level"

This I cannot change I think. tinylog internally sets the loglevel not as a field but just appends it to the Msg I think. I'm not sure how to not make it do that? I'm actually ignoring the logLevel argument in my jsonRenderer function https://github.com/wireapp/wire-server/pull/836/files#diff-79a662d6500cd50cb5717cf50673a5c8R62 so I hoped this would cause the log level to not show up in the msgs field

@fisx
Copy link
Contributor

fisx commented Aug 27, 2019

[galley] {"request":"N/A","targets":"[\"2a18c226-eb2f-4037-8d74-dac55a04417c\",\"65a325d3-5ec9-4669-97be-7605b76894db\"]","msgs":["D","LegalHold.removeSettings"]}

the targets value could be an array instead of a string. (not sure that makes sense; only do it if you like the idea, and it's easy to change.)

[debug level should have its own field]

there are ways to parse this out of the messages list again, but i think it's not worth the effort and the risk of complications with tinylog updates.

Copy link
Contributor

@fisx fisx left a comment

Choose a reason for hiding this comment

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

I feel very nit-picky now (sorry!), please let me know if I'm being annoying. The substance of your code is great. If you disagree with any of my comments, fight me! :-)

libs/extended/src/System/Logger/Extended.hs Show resolved Hide resolved
libs/extended/src/System/Logger/Extended.hs Show resolved Hide resolved
libs/extended/src/System/Logger/Extended.hs Outdated Show resolved Hide resolved
libs/extended/src/System/Logger/Extended.hs Outdated Show resolved Hide resolved
libs/extended/src/System/Logger/Extended.hs Outdated Show resolved Hide resolved
libs/extended/src/System/Logger/Extended.hs Outdated Show resolved Hide resolved
libs/extended/src/System/Logger/Extended.hs Outdated Show resolved Hide resolved
libs/extended/src/System/Logger/Extended.hs Outdated Show resolved Hide resolved
libs/extended/src/System/Logger/Extended.hs Outdated Show resolved Hide resolved
services/galley/galley.integration.yaml Outdated Show resolved Hide resolved
No need to declare an instance because encoding is only used locally.
Furthermore, we avoid an intermediate list being allocated when
serializing fields of a log message
@arianvp
Copy link
Contributor Author

arianvp commented Aug 28, 2019

the targets value could be an array instead of a string. (not sure that makes sense; only do it if you like the idea, and it's easy to change.)

it's not easy to change. type Field = (Builder, Builder) Tinylog makes too many assumptions about the logformat for us to do something more sensible here

@arianvp arianvp requested a review from fisx August 28, 2019 09:18
@arianvp
Copy link
Contributor Author

arianvp commented Aug 28, 2019

Also, I see that "D" shows up as "msgs", that should be a diff. field named "level"

@tiago-loureiro do you want me to add an extra field called level eventhough I can not get rid of the D in the log messages? (I really still don't understand why this D is showing up there in the first place. I'm very confused about it)

@fisx
Copy link
Contributor

fisx commented Aug 28, 2019

the targets value could be an array instead of a string. (not sure that makes sense; only do it if you like the idea, and it's easy to change.)

it's not easy to change. type Field = (Builder, Builder) Tinylog makes too many assumptions about the logformat for us to do something more sensible here

you could parse it back from the string, i guess... :-) (could you?)

@fisx
Copy link
Contributor

fisx commented Aug 28, 2019

Also, I see that "D" shows up as "msgs", that should be a diff. field named "level"

@tiago-loureiro do you want me to add an extra field called level eventhough I can not get rid of the D in the log messages? (I really still don't understand why this D is showing up there in the first place. I'm very confused about it)

it's the call to lmsg in this line.

I say we leave it in and add an extra field for debug level as tiago suggested, just in case it'll make analytics easier.

Copy link
Contributor

@fisx fisx left a comment

Choose a reason for hiding this comment

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

I'm happy now! (Please do not merge before ci is happy, too! :))

libs/extended/src/System/Logger/Extended.hs Show resolved Hide resolved
@arianvp
Copy link
Contributor Author

arianvp commented Aug 28, 2019

you could parse it back from the string, i guess... :-) (could you?)

There is an unsafeToEncoding function that turns any bytestring into an Encoding. We could use that I guess but we have to be sure that what we put in is valid JSON otherwise bad things happen =)

@arianvp arianvp merged commit dfabfec into more-debug-logging Aug 29, 2019
@arianvp arianvp deleted the json-logging branch August 29, 2019 09:49
arianvp added a commit that referenced this pull request Aug 29, 2019
* Add logs for team operations
* Add logging for legalhold

* Json logging (#836)

* Allow to set log format
The old netstrings option is now deprecated, use logFormat instead.
logFormat takes presedence of netstrings if both are set.
If none are set, log format defaults to Plain
* Implement json renderer for tinylog
jschaul pushed a commit that referenced this pull request Sep 2, 2019
* Add json logging and logging  (#828)  (#836)

* Add logs for team operations
* Add logging for legalhold

* Json logging (#836)

* Allow to set log format
The old netstrings option is now deprecated, use logFormat instead.
logFormat takes presedence of netstrings if both are set.
If none are set, log format defaults to Plain
* Implement json renderer for tinylog

* Specialize the error cases on conversation lookup. (#841)

Getting a conversation you left will now give 403 access-denied, not 404 not-found.

* Feature Flags in galley options. (#825)

* Feature flags in galley options file.

* Honour sso feature flag.

* Honour legalhold feature flag (test).

* Honour legalhold feature flag (handler).

* Disable all LH tests if feature is disabled.

* Check options settings for feature flag.

* Avoid catch-all pattern.

Catch-all patterns are not future-proof if constructors for new
falvors of "disabled" are added.
@fisx fisx mentioned this pull request Sep 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants