-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[APM] Render related errors link in transaction flyout #29807
[APM] Render related errors link in transaction flyout #29807
Conversation
💚 Build Succeeded |
.../app/TransactionDetails/Transaction/WaterfallContainer/Waterfall/TransactionFlyout/index.tsx
Outdated
Show resolved
Hide resolved
export interface TraceAPIResponse { | ||
trace: TraceItems; | ||
transactionErrorCounts: TransactionErrorCounts; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think TraceItems
, or TransactionErrorCounts
should be separate types. We can access them as TraceAPIResponse['trace']
and TraceAPIResponse['transactionErrorCounts']
@@ -82,7 +84,8 @@ interface IWaterfallItemSpan extends IWaterfallItemBase { | |||
export type IWaterfallItem = IWaterfallItemSpan | IWaterfallItemTransaction; | |||
|
|||
function getTransactionItem( | |||
transaction: Transaction | |||
transaction: Transaction, | |||
transactionErrorCounts: TraceAPIResponse['transactionErrorCounts'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we call this errorCountPerTransaction
or errorsPerTransaction
?
( | ||
acc: object, | ||
{ key, errors: { doc_count } }: TraceErrorsAggregationBucket | ||
) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it's me, but I found this line a bit hard to parse. What do you think about:
(acc, bucket: TraceErrorsAggregationBucket) => {
(acc: object
doesn't add anything afaict)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh whoops. i meant to change the name before committing
@ogupte Do you think it is too much for this PR to also get rid of the Transaction fetch (and |
I plan to add it to this PR. I just wanted feedback earlier on the solution of the core issue. |
349c7ae
to
e85a849
Compare
💚 Build Succeeded |
'search', | ||
errorsAggParams | ||
) | ||
]).then(([traceResponse, errorsAggResponse]) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for changing this. ES query can sometimes end up long and confusing (especially if we need to transform the data before sending it to the client) so everywhere else we only have one query per file.
In this case it's not so big, but I'd still like that separation, since it makes it very easy to get an overview and test in separation.
return resp.hits.hits.map(hit => hit._source); | ||
return Promise.all([ | ||
client<Span | Transaction>('search', traceParams), // query for trace items (spans & transaction) | ||
client<Span | Transaction, TraceErrorsAggResponse>( // agg for transaction error count |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Span | Transaction
is wrong for the error, isn't it? Should probably be never
or something like that.
}; | ||
}, | ||
{} | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personal nit: which of the two do find easier to read?
- Current:
const errorsPerTransaction = errorsAggResponse.aggregations.transactions.buckets.reduce(
(accumulatedErrorsPerTransaction, bucket: TraceErrorsAggBucket) => {
const {
key,
errors: { doc_count }
} = bucket;
return {
...accumulatedErrorsPerTransaction,
[key]: doc_count
};
},
{}
);
- or adapted:
const errorsPerTransaction = errorsAggResponse.aggregations.transactions.buckets.reduce(
(acc, bucket: TraceErrorsAggBucket) => ({
...acc,
[bucket.key]: bucket.errors.doc_count
})
{}
);
I realize this is very much personal pref.. I generally avoid the nested destructuring but I might be the odd one out :)
And I find acc
descriptive enough most of the time. Unless I have nested reducers I'm never confused what it refers to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I usually prefer nested destructuring followed by composition in smaller terms, but I don't feel strongly about it, so i can adapt. I'm happy to make these kinds of changes in the spirit of style cohesion and readability, but generally, I feel like code styles we want to enforce should be codified in the linting step, otherwise it can be rather subjective.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but generally, I feel like code styles we want to enforce should be codified in the linting step, otherwise it can be rather subjective
Good point 👍 This made me curious to see if there was an ESLint rule for this. The closest I got was this closed issue, so clearly there hasn't been overwhelming support for this idea.
hits: Array<Span | Transaction>, | ||
entryTransaction: Transaction | ||
hits: TraceAPIResponse['trace'], | ||
entryTransaction: Transaction, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When you make the other change we talked about, we will no longer have this entryTransaction
. Instead we'll have a entryTransactionId
@@ -256,7 +261,7 @@ export function getWaterfall( | |||
case 'span': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We no longer need the filter
above (because we don't get error documents any longer). And the default
case below is probably not that useful anymore (it seems overly defensive)
e85a849
to
0043961
Compare
💚 Build Succeeded |
bool: { | ||
filter: [ | ||
{ term: { [TRACE_ID]: traceId } }, | ||
{ terms: { [PROCESSOR_EVENT]: ['span', 'transaction'] } }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work? Can you provide an array of values to terms
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see you use terms
instead of term
. Didn't know about that. Awesome 🥇
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need the nested aggregation:
aggs: {
errors: {
filter: {
term: {
'processor.event': 'error'
}
}
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i forgot this was holdover from when all trace items were included in the returned set
@ogupte While reviewing I noticed a test for |
id | ||
); | ||
if (waterfallItemTransaction) { | ||
return waterfallItemTransaction.errorCount; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few comments about getWaterfallItemTransactionById
, createGetTransactionById
and createGetErrorCountByTransactionId
:
createGetErrorCountByTransactionId
I don't think we need createGetErrorCountByTransactionId
since we already have errorsPerTransaction
which is a StringMap
like itemsById
. We can just return it as errorCountByTransactionId
or errorsPerTransaction
- whatever makes the naming consistent.
createGetTransactionById
I think createGetTransactionById
can be simplified to:
function createTransactionById(hits: Array<Transaction | Span>) {
const transactions = hits.filter(
hit => hit.processor.event === 'transaction'
) as Transaction[];
return indexBy(transactions, 'transaction.id');
}
In this case I don't think we need getWaterfallItemTransactionById
anymore.
💔 Build Failed |
entryTransaction: Transaction | ||
hits: TraceAPIResponse['trace'], | ||
errorsPerTransaction: TraceAPIResponse['errorsPerTransaction'], | ||
entryTransactionId?: Transaction['transaction']['id'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not 100% decided on this, but I find it a bit easier to read more generic type annotations instead of the very custom ones. For instance:
hits: Array<Span | Transaction>,
errorsPerTransaction: StringMap<number>,
entryTransactionId?: string
This is totally up for debate. Just putting out some thoughts.
const { start, end, client, config } = setup; | ||
|
||
const params: SearchParams = { | ||
index: [config.get('apm_oss.errorIndices')], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is querying the error index, should this file perhaps be located under "lib/errors"?
Not necessarily saying it should, just trying to find a system that makes sense.
retest |
ebbf0e0
to
97e0939
Compare
retest |
💔 Build Failed |
💔 Build Failed |
retest |
💔 Build Failed |
retest |
💔 Build Failed |
…r count in transaction flyout
… queries, improved code org/readability
…up the current transaction data within the trace (waterfall) data
…rrors_per_transaction.ts under 'errors'
…e waterfall helpers
…bar for related errors
97e0939
to
e5d2f28
Compare
💔 Build Failed |
retest |
💚 Build Succeeded |
* [APM] closes elastic#29563 by rendering related errors link with error count in transaction flyout * [APM] improved get_trace query by narrowing indices and parallelizing queries, improved code org/readability * [APM] code improvements, split get_trace queries into separate source files * [APM] remove initial transaction details request in favor of looking up the current transaction data within the trace (waterfall) data * Add test for `getWaterfall` * Revert change to `getWaterfallItems` test * simplified aggregation, waterfall helpers code, and moved get_trace_errors_per_transaction.ts under 'errors' * improved naming and readbility of waterfall properties * removed unused routes and queries and fixed some invisible bugs in the waterfall helpers * added trace.id in addition to the transaction.id filter in the kuery bar for related errors
* [APM] closes elastic#29563 by rendering related errors link with error count in transaction flyout * [APM] improved get_trace query by narrowing indices and parallelizing queries, improved code org/readability * [APM] code improvements, split get_trace queries into separate source files * [APM] remove initial transaction details request in favor of looking up the current transaction data within the trace (waterfall) data * Add test for `getWaterfall` * Revert change to `getWaterfallItems` test * simplified aggregation, waterfall helpers code, and moved get_trace_errors_per_transaction.ts under 'errors' * improved naming and readbility of waterfall properties * removed unused routes and queries and fixed some invisible bugs in the waterfall helpers * added trace.id in addition to the transaction.id filter in the kuery bar for related errors
* [APM] closes #29563 by rendering related errors link with error count in transaction flyout * [APM] improved get_trace query by narrowing indices and parallelizing queries, improved code org/readability * [APM] code improvements, split get_trace queries into separate source files * [APM] remove initial transaction details request in favor of looking up the current transaction data within the trace (waterfall) data * Add test for `getWaterfall` * Revert change to `getWaterfallItems` test * simplified aggregation, waterfall helpers code, and moved get_trace_errors_per_transaction.ts under 'errors' * improved naming and readbility of waterfall properties * removed unused routes and queries and fixed some invisible bugs in the waterfall helpers * added trace.id in addition to the transaction.id filter in the kuery bar for related errors
* [APM] closes #29563 by rendering related errors link with error count in transaction flyout * [APM] improved get_trace query by narrowing indices and parallelizing queries, improved code org/readability * [APM] code improvements, split get_trace queries into separate source files * [APM] remove initial transaction details request in favor of looking up the current transaction data within the trace (waterfall) data * Add test for `getWaterfall` * Revert change to `getWaterfallItems` test * simplified aggregation, waterfall helpers code, and moved get_trace_errors_per_transaction.ts under 'errors' * improved naming and readbility of waterfall properties * removed unused routes and queries and fixed some invisible bugs in the waterfall helpers * added trace.id in addition to the transaction.id filter in the kuery bar for related errors
* [APM] closes elastic#29563 by rendering related errors link with error count in transaction flyout * [APM] improved get_trace query by narrowing indices and parallelizing queries, improved code org/readability * [APM] code improvements, split get_trace queries into separate source files * [APM] remove initial transaction details request in favor of looking up the current transaction data within the trace (waterfall) data * Add test for `getWaterfall` * Revert change to `getWaterfallItems` test * simplified aggregation, waterfall helpers code, and moved get_trace_errors_per_transaction.ts under 'errors' * improved naming and readbility of waterfall properties * removed unused routes and queries and fixed some invisible bugs in the waterfall helpers * added trace.id in addition to the transaction.id filter in the kuery bar for related errors
[APM] closes #29563 by rendering related errors link with error count in transaction flyout