本文整理汇总了TypeScript中x-pack/plugins/apm/common/idx.idx函数的典型用法代码示例。如果您正苦于以下问题:TypeScript idx函数的具体用法?TypeScript idx怎么用?TypeScript idx使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了idx函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: timeseriesTransformer
export function timeseriesTransformer({
timeseriesResponse,
bucketSize
}: {
timeseriesResponse: ESResponse;
bucketSize: number;
}): ApmTimeSeriesResponse {
const aggs = timeseriesResponse.aggregations;
const overallAvgDuration = idx(aggs, _ => _.overall_avg_duration.value);
const responseTimeBuckets = idx(aggs, _ => _.response_times.buckets);
const { avg, p95, p99 } = getResponseTime(responseTimeBuckets);
const transactionResultBuckets = idx(
aggs,
_ => _.transaction_results.buckets
);
const tpmBuckets = getTpmBuckets(transactionResultBuckets, bucketSize);
return {
totalHits: timeseriesResponse.hits.total,
responseTimes: {
avg,
p95,
p99
},
tpmBuckets,
overallAvgDuration
};
}
示例2: getService
export async function getService(
serviceName: string,
setup: Setup
): Promise<ServiceAPIResponse> {
const { start, end, esFilterQuery, client, config } = setup;
const filter: ESFilter[] = [
{ term: { [SERVICE_NAME]: serviceName } },
{ terms: { [PROCESSOR_EVENT]: ['error', 'transaction'] } },
{ range: rangeFilter(start, end) }
];
if (esFilterQuery) {
filter.push(esFilterQuery);
}
const params = {
index: [
config.get<string>('apm_oss.errorIndices'),
config.get<string>('apm_oss.transactionIndices')
],
body: {
size: 0,
query: {
bool: {
filter
}
},
aggs: {
types: {
terms: { field: TRANSACTION_TYPE, size: 100 }
},
agents: {
terms: { field: SERVICE_AGENT_NAME, size: 1 }
}
}
}
};
interface Aggs {
types: {
buckets: BucketAgg[];
};
agents: {
buckets: BucketAgg[];
};
}
const { aggregations } = await client<void, Aggs>('search', params);
const buckets = idx(aggregations, _ => _.types.buckets) || [];
const types = buckets.map(bucket => bucket.key);
const agentName = idx(aggregations, _ => _.agents.buckets[0].key);
return {
serviceName,
types,
agentName
};
}
示例3: idx
buckets: buckets.map(bucket => {
return {
...bucket,
lower: { value: idx(bucket, _ => _.lower.value) || null },
upper: { value: idx(bucket, _ => _.upper.value) || null },
anomaly_score: {
value: idx(bucket, _ => _.anomaly_score.value) || null
}
};
})
示例4: getErrorGroup
export async function getErrorGroup({
serviceName,
groupId,
setup
}: {
serviceName: string;
groupId: string;
setup: Setup;
}): Promise<ErrorGroupAPIResponse> {
const { start, end, esFilterQuery, client, config } = setup;
const filter: ESFilter[] = [
{ term: { [SERVICE_NAME]: serviceName } },
{ term: { [PROCESSOR_EVENT]: 'error' } },
{ term: { [ERROR_GROUP_ID]: groupId } },
{ range: rangeFilter(start, end) }
];
if (esFilterQuery) {
filter.push(esFilterQuery);
}
const params = {
index: config.get<string>('apm_oss.errorIndices'),
body: {
size: 1,
query: {
bool: {
filter,
should: [{ term: { [TRANSACTION_SAMPLED]: true } }]
}
},
sort: [
{ _score: 'desc' }, // sort by _score first to ensure that errors with transaction.sampled:true ends up on top
{ '@timestamp': { order: 'desc' } } // sort by timestamp to get the most recent error
]
}
};
const resp = await client<APMError>('search', params);
const error = idx(resp, _ => _.hits.hits[0]._source);
const transactionId = idx(error, _ => _.transaction.id);
const traceId = idx(error, _ => _.trace.id);
let transaction;
if (transactionId && traceId) {
transaction = await getTransaction(transactionId, traceId, setup);
}
return {
transaction,
error,
occurrencesCount: resp.hits.total
};
}
示例5: idx
const buckets = response.aggregations.distribution.buckets.map(bucket => {
const sampleSource = idx(bucket, _ => _.sample.hits.hits[0]._source);
const isSampled = idx(sampleSource, _ => _.transaction.sampled);
const sample = {
traceId: idx(sampleSource, _ => _.trace.id),
transactionId: idx(sampleSource, _ => _.transaction.id)
};
return {
key: bucket.key,
count: bucket.doc_count,
sample: isSampled ? sample : undefined
};
});
示例6: idx
const hits = buckets.map(bucket => {
const source = bucket.sample.hits.hits[0]._source;
const message =
idx(source, _ => _.error.log.message) ||
idx(source, _ => _.error.exception[0].message);
return {
message,
occurrenceCount: bucket.doc_count,
culprit: idx(source, _ => _.error.culprit),
groupId: idx(source, _ => _.error.grouping_key),
latestOccurrenceAt: source['@timestamp'],
handled: idx(source, _ => _.error.exception[0].handled)
};
});
示例7: anomalySeriesTransform
export function anomalySeriesTransform(
response: ESResponse | undefined,
mlBucketSize: number,
bucketSize: number,
timeSeriesDates: number[]
): AnomalyTimeSeriesResponse | undefined {
if (!response) {
return;
}
const buckets = (
idx(response, _ => _.aggregations.ml_avg_response_times.buckets) || []
).map(bucket => {
return {
x: bucket.key,
anomalyScore: bucket.anomaly_score.value,
lower: bucket.lower.value,
upper: bucket.upper.value
};
});
const bucketSizeInMillis = Math.max(bucketSize, mlBucketSize) * 1000;
return {
anomalyScore: getAnomalyScoreDataPoints(
buckets,
timeSeriesDates,
bucketSizeInMillis
),
anomalyBoundaries: getAnomalyBoundaryDataPoints(buckets, timeSeriesDates)
};
}
示例8: transactionGroupsTransformer
export function transactionGroupsTransformer({
response,
start,
end
}: {
response: ESResponse;
start: number;
end: number;
}): ITransactionGroup[] {
const buckets = idx(response, _ => _.aggregations.transactions.buckets) || [];
const duration = moment.duration(end - start);
const minutes = duration.asMinutes();
const results = buckets.map(bucket => {
const averageResponseTime = bucket.avg.value;
const transactionsPerMinute = bucket.doc_count / minutes;
const impact = bucket.sum.value;
const sample = bucket.sample.hits.hits[0]._source;
return {
name: bucket.key,
sample,
p95: bucket.p95.values['95.0'],
averageResponseTime,
transactionsPerMinute,
impact
};
});
return calculateRelativeImpacts(results);
}
示例9: getTransaction
export async function getTransaction(
transactionId: string,
traceId: string,
setup: Setup
): Promise<TransactionAPIResponse> {
const { start, end, esFilterQuery, client, config } = setup;
const filter: ESFilter[] = [
{ term: { [PROCESSOR_EVENT]: 'transaction' } },
{ term: { [TRANSACTION_ID]: transactionId } },
{ term: { [TRACE_ID]: traceId } },
{ range: rangeFilter(start, end) }
];
if (esFilterQuery) {
filter.push(esFilterQuery);
}
const params = {
index: config.get<string>('apm_oss.transactionIndices'),
body: {
size: 1,
query: {
bool: {
filter
}
}
}
};
const resp = await client<Transaction>('search', params);
return idx(resp, _ => _.hits.hits[0]._source);
}
示例10: return
return (id?: IWaterfallItem['id']) => {
if (!id) {
return undefined;
}
const item = itemsById[id];
if (idx(item, _ => _.docType) === 'transaction') {
return (item as IWaterfallItemTransaction).transaction;
}
};