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 dbname to mango exec stats #4990

Merged
merged 9 commits into from
Mar 5, 2024
Merged

Conversation

chewbranca
Copy link
Contributor

@chewbranca chewbranca commented Feb 23, 2024

Overview

This PR includes the database name in the "mango-stats" alongside the existing data around documents processed to generate the request. The motivation here is two fold: 1) there's a scenario where chttpd:maybe_log returns false and the chttpd socket handling the request has died where a front load balancer processing the request never got the X-Couch-Request-ID, thereby losing the connection of the underlying request that induced the particular load; this is especially problematic when the socket died because the request was excessively long. 2) this allows for grouping by dbname directly on the reports, making it easier to quickly scan and summarize activity from the report.

This PR also sneaks in a patch to mango_cursor_nouveau to include the recent stats logic patch.

Testing recommendations

I've added a new test to show the dbname field arrives in the couch_log:report logic yet does not extend the field into the http response when the _find query does execution_stats=true.

Checklist

  • Code is written and works correctly
  • Changes are covered by tests
  • Any new configurable parameters are documented in rel/overlay/etc/default.ini
  • Documentation changes were made in the src/docs folder
  • Documentation changes were backported (separated PR) to affected branches

src/mango/src/mango_cursor_text.erl Outdated Show resolved Hide resolved
to_json(Stats, true).

to_json(Stats, IncludeDbName) ->
Base =
Copy link
Contributor

Choose a reason for hiding this comment

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

Or you could just simply say:

Base = [{dbname, Stats#execution_stats.dbname} || IncludeDbName]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not quite following your suggestion, we need to include the tuple {dbname, Stats#execution_stats.dbname} in the list conditionally. I think perhaps you're suggesting to move the construction of the the base into the arity one function head, like:

to_json(Stats) ->
    to_json(Stats, [{dbname, Stats#execution_stats.dbname}]).

to_json(Stats, Base) ->
  {[
    ...
    | Base
  ]}.

But that would change the caller here https://github.com/apache/couchdb/pull/4990/files/69f80aa3a270030601ebd111bd3a1dc62a5df8fa#diff-478704bf59b4beb680fc69863dfe63a544cfea5d6dca7507d6ce080c84b6cb35R119 to have to supply the base list into to_json, eg to_json(Stats, []) instead of to_json(Stats, false), and I don't think having to supply the base list instead of a boolean is a cleaner approach.

Is this what you were suggesting or something else? I agree that it's a bit clunky for sure.

Copy link
Contributor

Choose a reason for hiding this comment

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

There is no need to change the function's interface. What I suggested is a semantical equivalent of your original definition. This alternative syntax is based on how list comprehensions in Erlang work. The Boolean value on the right-hand side of the || symbol acts as a predicate and the value on the left-hand side is added to the resulting list if that is true otherwise omitted.

For example, consider the following in the Erlang shell:

> [1 || true].
[1]
> [1 || false].
[]

List comprehensions do not require the use of variables, hence this formulation becomes a valid although unusual instance.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahhhhh I see what you mean, I haven't seen that structure before. Interesting, but seems a bit esoteric. Perhaps if we make that a common pattern in the codebase.

Copy link
Contributor

Choose a reason for hiding this comment

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

When applied in a sequence, it works out quite nicely:

Reason =
[needs_text_search || not NotTextSearch] ++
[field_mismatch || not SelectorHasRequiredFields] ++
[sort_order_mismatch || not CanUseSort],

Copy link
Contributor

Choose a reason for hiding this comment

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

That said, it would look nice in this case as well. Of course, this is just a suggestion, I am adding this example for consideration only where Base is removed completely:

   {[
        {total_keys_examined, Stats#execution_stats.totalKeysExamined},
        {total_docs_examined, Stats#execution_stats.totalDocsExamined},
        {total_quorum_docs_examined, Stats#execution_stats.totalQuorumDocsExamined},
        {results_returned, Stats#execution_stats.resultsReturned},
        {execution_time_ms, Stats#execution_stats.executionTimeMs}
        | [{dbname, Stats#execution_stats.dbname} || IncludeDbName]
    ]}.

src/mango/src/mango_execution_stats.hrl Show resolved Hide resolved
@@ -128,6 +129,8 @@ execute(Cursor, UserFun, UserAcc) ->
{FinalUserAcc0, Stats1} = mango_execution_stats:maybe_add_stats(
Opts, UserFun, Stats0, FinalUserAcc
),
%% This needs Stats1 as log_end is called in maybe_add_stats
mango_execution_stats:log_stats(Stats1),
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice catch!

@chewbranca chewbranca force-pushed the add-dbname-to-mango-exec-stats branch from 517fce8 to 22781e1 Compare March 5, 2024 00:26
Copy link
Contributor

@pgj pgj left a comment

Choose a reason for hiding this comment

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

+1 if passes the CI

@pgj
Copy link
Contributor

pgj commented Mar 5, 2024

The Mango integration test suites (make mango-test) are failing, most of them are HTTP 500s:

[2024-03-05T14:04:18.471Z] Ran 384 tests in 12.251s
[2024-03-05T14:04:18.471Z] 
[2024-03-05T14:04:18.471Z] FAILED (failures=3, errors=75, skipped=143)

@pgj
Copy link
Contributor

pgj commented Mar 5, 2024

This seems to be the cause:

[error] 2024-03-05T14:20:35.042023Z [email protected] <0.757.0> ca0f3d4937 req_err(3855649447) badrecord : undefined
    [<<"mango_execution_stats:log_start/1 L106">>,<<"mango_cursor_view:execute/3 L220">>,<<"mango_httpd:handle_find_req/2 L213">>,<<"mango_httpd:handle_req/2 L35">>,<<"chttpd:handle_req_after_auth/2 L416">>,<<"chttpd:process_request/1 L394">>,<<"chttpd:handle_request_int/1 L329">>,<<"mochiweb_http:headers/6 L140">>]

@chewbranca chewbranca force-pushed the add-dbname-to-mango-exec-stats branch from aea49de to 7928150 Compare March 5, 2024 21:21
@pgj
Copy link
Contributor

pgj commented Mar 5, 2024

Okay, cool. Looks like all the issues have been fixed.

@chewbranca chewbranca merged commit ab2cf16 into main Mar 5, 2024
14 checks passed
pgj pushed a commit to pgj/couchdb that referenced this pull request Mar 14, 2024
* WIP: include dbname in mango exec stats

* Don't output dbname in exec stats http response

* Make sure mango nouveau logs reports

* Test that mango reports get the dbname in the stats

* With compliant formatting

* Switch to adding exec stats dbname during create

* Add stats to explain cursor

* Add stats to mango cursor special

* Fix mango special cursor test
@chewbranca chewbranca deleted the add-dbname-to-mango-exec-stats branch June 5, 2024 20:09
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.

None yet

2 participants