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

[APM] Render related errors link in transaction flyout #29807

Merged

Conversation

ogupte
Copy link
Contributor

@ogupte ogupte commented Feb 1, 2019

[APM] closes #29563 by rendering related errors link with error count in transaction flyout

transaction-flyout-view-related-errors-traceid

@ogupte ogupte self-assigned this Feb 1, 2019
@ogupte ogupte requested a review from sorenlouv February 1, 2019 09:04
@ogupte ogupte requested a review from a team as a code owner February 1, 2019 09:04
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@sorenlouv sorenlouv assigned sorenlouv and unassigned sorenlouv Feb 1, 2019
export interface TraceAPIResponse {
trace: TraceItems;
transactionErrorCounts: TransactionErrorCounts;
}
Copy link
Member

@sorenlouv sorenlouv Feb 1, 2019

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']
Copy link
Member

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
) => {
Copy link
Member

@sorenlouv sorenlouv Feb 1, 2019

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)

Copy link
Contributor Author

@ogupte ogupte Feb 1, 2019

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

@sorenlouv
Copy link
Member

sorenlouv commented Feb 1, 2019

@ogupte Do you think it is too much for this PR to also get rid of the Transaction fetch (and getTransactionWithErrorCount), as we talked about in #29563 (comment)?

@ogupte
Copy link
Contributor Author

ogupte commented Feb 1, 2019

@ogupte Do you think it is too much for this PR to also get rid of the Transaction fetch (and getTransactionWithErrorCount), as we talked about in #29563 (comment)?

I plan to add it to this PR. I just wanted feedback earlier on the solution of the core issue.

@ogupte ogupte force-pushed the apm-29563-related-errors-transaction-flyout branch from 349c7ae to e85a849 Compare February 4, 2019 07:20
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

'search',
errorsAggParams
)
]).then(([traceResponse, errorsAggResponse]) => {
Copy link
Member

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
Copy link
Member

@sorenlouv sorenlouv Feb 4, 2019

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.

};
},
{}
);
Copy link
Member

@sorenlouv sorenlouv Feb 4, 2019

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?

  1. Current:
const errorsPerTransaction = errorsAggResponse.aggregations.transactions.buckets.reduce(
  (accumulatedErrorsPerTransaction, bucket: TraceErrorsAggBucket) => {
    const {
      key,
      errors: { doc_count }
    } = bucket;
    return {
      ...accumulatedErrorsPerTransaction,
      [key]: doc_count
    };
  },
  {}
);
  1. 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.

Copy link
Contributor Author

@ogupte ogupte Feb 4, 2019

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.

Copy link
Member

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,
Copy link
Member

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':
Copy link
Member

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)

@ogupte ogupte force-pushed the apm-29563-related-errors-transaction-flyout branch from e85a849 to 0043961 Compare February 5, 2019 05:44
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

bool: {
filter: [
{ term: { [TRACE_ID]: traceId } },
{ terms: { [PROCESSOR_EVENT]: ['span', 'transaction'] } },
Copy link
Member

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 ?

Copy link
Member

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 🥇

}
}
}
}
Copy link
Member

@sorenlouv sorenlouv Feb 5, 2019

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'
                }
              }
            }
          }

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 forgot this was holdover from when all trace items were included in the returned set

@sorenlouv
Copy link
Member

@ogupte While reviewing I noticed a test for getWaterfall was missing. That is something I should have added as part of the original implementation of getWaterfall but I must have forgotten it.
I added it to aid myself in reviewing, and thought we might as well use it, so I pushed it to your branch. Hope it's okay :)

id
);
if (waterfallItemTransaction) {
return waterfallItemTransaction.errorCount;
Copy link
Member

@sorenlouv sorenlouv Feb 5, 2019

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.

@elasticmachine
Copy link
Contributor

💔 Build Failed

entryTransaction: Transaction
hits: TraceAPIResponse['trace'],
errorsPerTransaction: TraceAPIResponse['errorsPerTransaction'],
entryTransactionId?: Transaction['transaction']['id']
Copy link
Member

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')],
Copy link
Member

@sorenlouv sorenlouv Feb 5, 2019

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.

@sorenlouv
Copy link
Member

retest

@ogupte ogupte force-pushed the apm-29563-related-errors-transaction-flyout branch from ebbf0e0 to 97e0939 Compare February 7, 2019 16:58
@ogupte
Copy link
Contributor Author

ogupte commented Feb 7, 2019

retest

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@ogupte
Copy link
Contributor Author

ogupte commented Feb 7, 2019

retest

@elasticmachine
Copy link
Contributor

💔 Build Failed

@ogupte
Copy link
Contributor Author

ogupte commented Feb 8, 2019

retest

@elasticmachine
Copy link
Contributor

💔 Build Failed

@ogupte ogupte force-pushed the apm-29563-related-errors-transaction-flyout branch from 97e0939 to e5d2f28 Compare February 8, 2019 05:31
@elasticmachine
Copy link
Contributor

💔 Build Failed

@ogupte
Copy link
Contributor Author

ogupte commented Feb 8, 2019

retest

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@ogupte ogupte merged commit 7ae1b4f into elastic:master Feb 8, 2019
ogupte added a commit to ogupte/kibana that referenced this pull request Feb 8, 2019
* [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
ogupte added a commit to ogupte/kibana that referenced this pull request Feb 8, 2019
* [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
ogupte added a commit that referenced this pull request Feb 8, 2019
* [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
ogupte added a commit that referenced this pull request Feb 8, 2019
* [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
lukeelmers pushed a commit to lukeelmers/kibana that referenced this pull request Feb 8, 2019
* [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
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.

[APM] Link to related errors from transaction flyout
3 participants