-
Notifications
You must be signed in to change notification settings - Fork 2
Add same-metrics dataset for time series UI test scenarios #7
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
Open
kpatticha
wants to merge
13
commits into
simianhacker:main
Choose a base branch
from
kpatticha:add-same-metric-dataset
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8e62aef
Add `time_series_metric: histogram`
kpatticha a26d815
Merge branch 'main' of github.com:simianhacker/simian-forge
kpatticha 80b0710
Merge branch 'main' of github.com:simianhacker/simian-forge
kpatticha 4acc082
Add Same Metrics functionality t
kpatticha 1b1d814
Fix the dimension
kpatticha 33df8e4
Remove unused HAS_4_DIMENSIONS constant from same-metrics-template-bu…
kpatticha 864407e
Update Same Metrics functionality with better naming
kpatticha cbfeedd
Add Edge Cases functionality
kpatticha 358c167
Address code review commnets
kpatticha 622d56d
Address PR comments
kpatticha 7681887
Refactor index template assignment in simulators
kpatticha ca042dc
Update EdgeCasesSimulator to prevent document duplication and improve…
kpatticha 94cfbe8
Update src/simulators/same-metrics-simulator.ts
kpatticha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { | ||
| EdgeCasesDocument, | ||
| EdgeCasesMetrics, | ||
| } from "../types/edge-cases-types"; | ||
| import { FormatterResult } from "../types/simulator-types"; | ||
| import { getPhaseConfig } from "../simulators/edge-cases-template-builder"; | ||
| import { formatValueForFieldType } from "./histogram-helpers"; | ||
|
|
||
| export class EdgeCasesFormatter { | ||
| formatMetrics( | ||
| metrics: EdgeCasesMetrics, | ||
| ): FormatterResult<EdgeCasesDocument>[] { | ||
| const phaseConfig = getPhaseConfig(metrics.dataStream, metrics.phase); | ||
| const metricValue = formatValueForFieldType( | ||
| phaseConfig.metricFieldType, | ||
| metrics.counterValue, | ||
| ); | ||
|
|
||
| const doc: EdgeCasesDocument = { | ||
| "@timestamp": metrics.timestamp.toISOString(), | ||
| "metric.name": metrics.dataStream, | ||
| "test.data_stream": metrics.dataStream, | ||
| [metrics.dataStream]: metricValue, | ||
| }; | ||
| if (metrics.dimensions) { | ||
| for (const [key, value] of Object.entries(metrics.dimensions)) { | ||
| doc[key] = value; | ||
| } | ||
| } | ||
| return [{ documents: [doc], format: "edge-cases" }]; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| /** | ||
| * Shared histogram value builders for Elasticsearch histogram field types. | ||
| */ | ||
|
|
||
| export function buildHistogramValue(value: number): { | ||
| values: number[]; | ||
| counts: number[]; | ||
| } { | ||
| const base = Math.abs(value % 1000) || 1; | ||
| return { | ||
| values: [base * 0.5, base * 0.75, base, base * 1.25, base * 1.5], | ||
| counts: [1, 2, 4, 2, 1], | ||
| }; | ||
| } | ||
|
|
||
| export function buildTdigestValue(value: number): { | ||
| centroids: number[]; | ||
| counts: number[]; | ||
| } { | ||
| const base = Math.abs(value % 1000) || 1; | ||
| return { | ||
| centroids: [base * 0.5, base * 0.75, base, base * 1.25, base * 1.5], | ||
| counts: [1, 2, 4, 2, 1], | ||
| }; | ||
| } | ||
|
|
||
| export function buildExponentialHistogramValue( | ||
| value: number, | ||
| ): Record<string, unknown> { | ||
| const base = Math.abs(value % 1000) || 1; | ||
| return { | ||
| scale: 3, | ||
| sum: base * 10, | ||
| min: base * 0.5, | ||
| max: base * 1.5, | ||
| zero: { threshold: 0, count: 0 }, | ||
| positive: { | ||
| indices: [0, 1, 2, 3, 4], | ||
| counts: [1, 2, 4, 2, 1], | ||
| }, | ||
| negative: { | ||
| indices: [], | ||
| counts: [], | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Formats a numeric value into the correct shape for a given Elasticsearch field type. | ||
| */ | ||
| export function formatValueForFieldType( | ||
| fieldType: string, | ||
| value: number, | ||
| ): unknown { | ||
| switch (fieldType) { | ||
| case "exponential_histogram": | ||
| return buildExponentialHistogramValue(value); | ||
| case "tdigest": | ||
| return buildTdigestValue(value); | ||
| case "histogram": | ||
| return buildHistogramValue(value); | ||
| default: | ||
| return value; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { | ||
| SameMetricsDocument, | ||
| SameMetricsMetrics, | ||
| } from "../types/same-metrics-types"; | ||
| import { FormatterResult } from "../types/simulator-types"; | ||
| import { STREAM_TEMPLATE_CONFIGS } from "../simulators/same-metrics-template-builder"; | ||
| import { formatValueForFieldType } from "./histogram-helpers"; | ||
|
|
||
| const METRIC_NAME = "request_duration"; | ||
|
|
||
| export class SameMetricsFormatter { | ||
| formatMetrics( | ||
| metrics: SameMetricsMetrics, | ||
| ): FormatterResult<SameMetricsDocument>[] { | ||
| const streamConfig = STREAM_TEMPLATE_CONFIGS[metrics.dataStream]; | ||
| const fieldType = streamConfig?.metricFieldType ?? "double"; | ||
|
|
||
| const metricValue = formatValueForFieldType(fieldType, metrics.counterValue); | ||
|
|
||
| const doc: SameMetricsDocument = { | ||
| "@timestamp": metrics.timestamp.toISOString(), | ||
| "metric.name": METRIC_NAME, | ||
| request_duration: metricValue, | ||
| "test.scenario": metrics.scenario, | ||
| "test.data_stream": metrics.dataStream, | ||
| }; | ||
| if (metrics.dimensions) { | ||
| for (const [key, value] of Object.entries(metrics.dimensions)) { | ||
| doc[key] = value; | ||
| } | ||
| } | ||
| return [{ documents: [doc], format: "same-metrics" }]; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.