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

feat(dashboard): add back_pressure_rate UI #14863

Merged
merged 17 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 0 additions & 106 deletions dashboard/components/BackPressureTable.tsx

This file was deleted.

1 change: 0 additions & 1 deletion dashboard/components/FragmentGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,6 @@ export default function FragmentGraph({
<g className="fragment-edges" />
<g className="fragments" />
</svg>
{/* <BackPressureTable selectedFragmentIds={includedFragmentIds} /> */}
</Fragment>
)
}
Expand Down
135 changes: 135 additions & 0 deletions dashboard/pages/api/metric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,148 @@
import { Metrics, MetricsSample } from "../../components/metrics"
import api from "./api"

export const INTERVAL = 5000
export interface BackPressuresMetrics {
outputBufferBlockingDuration: Metrics[]
}

// Get back pressure from meta node -> prometheus
export async function getActorBackPressures() {
const res: BackPressuresMetrics = await api.get(
"/metrics/actor/back_pressures"
)
return res
}

export interface BackPressureInfo {
actorId: number
fragmentId: number
downstreamFragmentId: number
value: number
}

export interface BackPressureRateInfo {
actorId: number
fragmentId: number
downstreamFragmentId: number
backPressureRate: number
}

function convertToMapAndAgg(
backPressures: BackPressureInfo[]
): Map<string, number> {
// FragmentId-downstreamFragmentId, total value
const mapValue = new Map<string, number>()
// FragmentId-downstreamFragmentId, total count
const mapNumber = new Map<string, number>()
// FragmentId-downstreamFragmentId, average value
const map = new Map<string, number>()
for (const item of backPressures) {
const key = `${item.fragmentId}-${item.downstreamFragmentId}`
if (mapValue.has(key) && mapNumber.has(key)) {
// add || tp avoid NaN and pass check
mapValue.set(key, (mapValue.get(key) || 0) + item.value)
mapNumber.set(key, (mapNumber.get(key) || 0) + 1)
} else {
mapValue.set(key, item.value)
mapNumber.set(key, 1)
}
}

for (const [key, value] of mapValue) {
// add || 1 to avoid NaN and pass check
fuyufjh marked this conversation as resolved.
Show resolved Hide resolved
map.set(key, value / (mapNumber.get(key) || 1))
yufansong marked this conversation as resolved.
Show resolved Hide resolved
}
return map
}

function convertFromMapAndAgg(
map: Map<string, number>
): BackPressureRateInfo[] {
const result: BackPressureRateInfo[] = []
map.forEach((value, key) => {
const [fragmentId, downstreamFragmentId] = key.split("-").map(Number)
fuyufjh marked this conversation as resolved.
Show resolved Hide resolved
const backPressureRateInfo: BackPressureRateInfo = {
actorId: 0,
fragmentId,
downstreamFragmentId,
backPressureRate: value,
}
result.push(backPressureRateInfo)
})
return result
}

function convertToBackPressureMetrics(
bpRates: BackPressureRateInfo[]
): BackPressuresMetrics {
const bpMetrics: BackPressuresMetrics = {
outputBufferBlockingDuration: [],
}
for (const item of bpRates) {
bpMetrics.outputBufferBlockingDuration.push({
metric: {
actorId: item.actorId.toString(),
fragmentId: item.fragmentId.toString(),
downstreamFragmentId: item.downstreamFragmentId.toString(),
},
sample: [
{
timestamp: Date.now(),
value: item.backPressureRate,
},
],
})
}
return bpMetrics
}

export function calculateBPRate(
backPressureNew: BackPressureInfo[],
backPressureOld: BackPressureInfo[]
): BackPressuresMetrics {
let mapNew = convertToMapAndAgg(backPressureNew)
let mapOld = convertToMapAndAgg(backPressureOld)
let result = new Map<string, number>()
mapNew.forEach((value, key) => {
if (mapOld.has(key)) {
result.set(
key,
// The *100 in end of the formular is to convert the BP rate to the value used in web UI drawing
((value - (mapOld.get(key) || 0)) / ((INTERVAL / 1000) * 1000000000)) *
100
)
} else {
result.set(key, 0)
}
})

return convertToBackPressureMetrics(convertFromMapAndAgg(result))
}

export const BackPressureInfo = {
fromJSON: (object: any) => {
return {
actorId: isSet(object.actorId) ? Number(object.actorId) : 0,
fragmentId: isSet(object.fragmentId) ? Number(object.fragmentId) : 0,
downstreamFragmentId: isSet(object.downstreamFragmentId)
? Number(object.downstreamFragmentId)
: 0,
value: isSet(object.value) ? Number(object.value) : 0,
}
},
}

// Get back pressure from meta node -> compute node
export async function getBackPressureWithoutPrometheus() {
const response = await api.get("/metrics/back_pressures")
Copy link
Member

@fuyufjh fuyufjh Feb 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we move it to another path such as "embedded_metrics" or sth? It's mixed with the metrics fetched from Prometheus, which looks confusing to me.

.route("/metrics/cluster", get(prometheus::list_prometheus_cluster))
.route(
"/metrics/actor/back_pressures",
get(prometheus::list_prometheus_actor_back_pressure),
)
.route("/metrics/back_pressures", get(get_back_pressure))

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, /metrics/actor/back_pressures actually output fragment-level metrics instead of actor-level... 😂 Legacy issues

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will solve the problem in a seperate PR

let backPressureInfos: BackPressureInfo[] = response.backPressureInfos.map(
BackPressureInfo.fromJSON
)
backPressureInfos = backPressureInfos.sort((a, b) => a.actorId - b.actorId)
return backPressureInfos
}

function calculatePercentile(samples: MetricsSample[], percentile: number) {
const sorted = samples.sort((a, b) => a.value - b.value)
const index = Math.floor(sorted.length * percentile)
Expand All @@ -49,3 +180,7 @@ export function p95(samples: MetricsSample[]) {
export function p99(samples: MetricsSample[]) {
return calculatePercentile(samples, 0.99)
}

function isSet(value: any): boolean {
return value !== null && value !== undefined
}
Loading
Loading