-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add automatically recalculate the size of the axis for the bandwidth.
Change filter for variable of the cdn-resource.
- Loading branch information
Denis
committed
Jul 20, 2021
1 parent
7c3cbdf
commit ae6a025
Showing
12 changed files
with
139 additions
and
43 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,8 +1,6 @@ | ||
# Changelog | ||
|
||
## 1.0.4 | ||
## 1.0.5 | ||
|
||
- Support for groupings and filtering data by vhosts, regions, countries, datacenters ids | ||
- Support for permanent token authentication | ||
- Add text formatting for legend key values | ||
- Add tests | ||
- Support deleted cdn resource | ||
- Support automatic chosen scale value for the bandwidth metric |
This file contains 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
This file contains 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,7 @@ | ||
export enum BandwidthEnum { | ||
Bits = "bit/s", | ||
KBits = "kbit/s", | ||
MBits = "Mbit/s", | ||
GBits = "Gbit/s", | ||
TBits = "Tbit/s", | ||
} |
This file contains 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,17 @@ | ||
/* eslint-disable no-magic-numbers */ | ||
import { preferredBandwidth } from "./bandwidth"; | ||
import { BandwidthEnum } from "./bandwidth-description"; | ||
|
||
describe("function bandwidth", () => { | ||
it("Should return 8 bit/s", () => { | ||
expect(preferredBandwidth(1)).toEqual(BandwidthEnum.Bits); | ||
}); | ||
|
||
it("Should return 0 bit/s", () => { | ||
expect(preferredBandwidth(0)).toEqual(BandwidthEnum.Bits); | ||
}); | ||
|
||
it("Should return 4 Gbit/s", () => { | ||
expect(preferredBandwidth(500000000)).toEqual(BandwidthEnum.GBits); | ||
}); | ||
}); |
This file contains 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,43 @@ | ||
/* eslint-disable no-magic-numbers */ | ||
import { BandwidthEnum } from "./bandwidth-description"; | ||
|
||
export const preferredBandwidth = ( | ||
bytes: number, | ||
periodInSeconds = 1 | ||
): BandwidthEnum => { | ||
const bits = (bytes * 8) / periodInSeconds; | ||
|
||
if (bits > 1000000000000) { | ||
return BandwidthEnum.TBits; | ||
} else if (bits > 1000000000) { | ||
return BandwidthEnum.GBits; | ||
} else if (bits > 1000000) { | ||
return BandwidthEnum.MBits; | ||
} else if (bits > 1000) { | ||
return BandwidthEnum.KBits; | ||
} else { | ||
return BandwidthEnum.Bits; | ||
} | ||
}; | ||
|
||
export const normalizedBandwidth = ( | ||
bytes: number, | ||
periodInSeconds: number, | ||
unit: BandwidthEnum, | ||
precision = 2 | ||
): number => { | ||
const bits = (bytes * 8) / periodInSeconds; | ||
|
||
switch (unit) { | ||
case BandwidthEnum.Bits: | ||
return Number(bits.toFixed(precision)); | ||
case BandwidthEnum.KBits: | ||
return Number((bits / 1000).toFixed(precision)); | ||
case BandwidthEnum.MBits: | ||
return Number((bits / 1000000).toFixed(precision)); | ||
case BandwidthEnum.GBits: | ||
return Number((bits / 1000000000).toFixed(precision)); | ||
case BandwidthEnum.TBits: | ||
return Number((bits / 1000000000000).toFixed(precision)); | ||
} | ||
}; |
This file contains 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,2 @@ | ||
export * from "./bandwidth-description"; | ||
export * from "./bandwidth"; |
This file contains 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
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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,28 @@ | ||
import { GCClientMetric, GCQuery, GCResponseStats } from "./types"; | ||
import { preferredBandwidth, normalizedBandwidth } from "./bandwidth"; | ||
import { getSecondsByGranularity } from "./granularity"; | ||
import { createGetterYValues, getUnitByMetric } from "./metric"; | ||
|
||
type Transform = (value: number) => number; | ||
const noopTransform = (v: number): number => v; | ||
|
||
export const getUnit = ( | ||
query: GCQuery, | ||
data: GCResponseStats[] | ||
): [string, Transform] => { | ||
const metric = query.metric.value!; | ||
const granulation = query.granularity.value!; | ||
const getter = createGetterYValues(metric); | ||
|
||
switch (metric) { | ||
case GCClientMetric.Bandwidth: | ||
const times = data.map((p) => getter(p.metrics)).flat(); | ||
// @ts-ignore | ||
const maxValue = Math.max(...times); | ||
const period = getSecondsByGranularity(granulation); | ||
const unit = preferredBandwidth(maxValue, period); | ||
return [unit, (value) => normalizedBandwidth(value, period, unit)]; | ||
default: | ||
return [getUnitByMetric(metric), noopTransform]; | ||
} | ||
}; |
This file contains 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