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

SSE stream optimization #173

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 4 additions & 3 deletions dashboard/aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type aggregator struct {

once sync.Once

seenMetrics map[string]struct{}
seenMetrics []string
}

func closer(what io.Closer, logger logrus.FieldLogger) {
Expand All @@ -57,7 +57,7 @@ func aggregate(input, output string, opts *options, proc *process) error {
agg.registry = newRegistry()
agg.options = opts
agg.logger = proc.logger
agg.seenMetrics = make(map[string]struct{})
agg.seenMetrics = make([]string, 0)

var inputFile, outputFile afero.File
var err error
Expand Down Expand Up @@ -176,8 +176,9 @@ func (agg *aggregator) updateAndSend(
return
}

newbies := met.newbies(agg.seenMetrics)
newbies, updated := met.newbies(agg.seenMetrics)
if len(newbies) != 0 {
agg.seenMetrics = updated
agg.fireEvent(metricEvent, newbies)
}

Expand Down
75 changes: 60 additions & 15 deletions dashboard/assets/packages/model/dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,72 @@ type Metric = {
name: string;
contains?: ValueType;
type?: MetricType;
custom?: boolean;
};
declare class Query {
name: string;
aggregate?: AggregateType;
tags?: Record<string, string>;
group?: string;
scenario?: string;
constructor(query: string);
}
declare class Metrics {
values: Record<string, Metric>;
constructor({ values }?: {
names: Array<string>;
_aggregates: Record<MetricType, Array<AggregateType>>;
constructor({ values, names }?: {
values?: {} | undefined;
names?: never[] | undefined;
});
set aggregates(value: Record<MetricType, Array<string>>);
onEvent(data: Record<string, object>): void;
toAggregate(data: Array<Array<number>>): Record<string, Aggregate>;
find(query: string): Metric | undefined;
unit(name: string, aggregate?: AggregateType): UnitType;
}

declare enum EventType {
config = "config",
param = "param",
start = "start",
stop = "stop",
metric = "metric",
snapshot = "snapshot",
cumulative = "cumulative",
threshold = "threshold"
}
type ConfigEvent = {
type: EventType.config;
data: Record<string, unknown>;
};
type ParamEvent = {
type: EventType.param;
data: Record<string, unknown>;
};
type StartEvent = {
type: EventType.start;
data: Array<Array<number>>;
};
type StopEvent = {
type: EventType.stop;
data: Array<Array<number>>;
};
type MetricEvent = {
type: EventType.metric;
data: Record<string, Record<string, object>>;
};
type SnapshotEvent = {
type: EventType.snapshot;
data: Array<Array<number>>;
};
type CumulativeEvent = {
type: EventType.cumulative;
data: Array<Array<number>>;
};
type ThresholdEvent = {
type: EventType.threshold;
data: Record<string, Array<string>>;
};
type DashboardEvent = ConfigEvent | ParamEvent | StartEvent | StopEvent | MetricEvent | SnapshotEvent | CumulativeEvent | ThresholdEvent;

type SampleVectorInit = {
length: number;
capacity: number;
Expand Down Expand Up @@ -155,14 +202,9 @@ declare class Param implements Record<string, unknown> {
constructor(from?: Record<string, unknown>);
[x: string]: unknown;
}
declare enum EventType {
config = "config",
param = "param",
start = "start",
stop = "stop",
metric = "metric",
snapshot = "snapshot",
cumulative = "cumulative"
declare class Thresholds implements Record<string, Array<string>> {
constructor(from?: Record<string, string[]>);
[x: string]: Array<string>;
}
declare class Digest implements EventListenerObject {
config: Config;
Expand All @@ -172,24 +214,27 @@ declare class Digest implements EventListenerObject {
metrics: Metrics;
samples: Samples;
summary: Summary;
constructor({ config, param, start, stop, metrics, samples, summary }?: {
thresholds: Thresholds;
constructor({ config, param, start, stop, metrics, samples, summary, thresholds }?: {
config?: Config | undefined;
param?: Param | undefined;
start?: Date | undefined;
stop?: Date | undefined;
metrics?: Metrics | undefined;
samples?: Samples | undefined;
summary?: Summary | undefined;
thresholds?: Thresholds | undefined;
});
handleEvent(event: MessageEvent): void;
onEvent(type: EventType, data: Record<string, Aggregate>): void;
onEvent(event: DashboardEvent): void;
private onConfig;
private onParam;
private onStart;
private onStop;
private onMetric;
private onSnapshot;
private onCumulative;
private onThreshold;
}

export { Aggregate, AggregateType, Config, Digest, EventType, Metric, MetricType, Metrics, Param, Query, SampleVector, SampleVectorInit, Samples, SamplesView, Summary, SummaryRow, SummaryView, UnitType, ValueType };
export { Aggregate, AggregateType, Config, DashboardEvent, Digest, EventType, Metric, MetricType, Metrics, Param, Query, SampleVector, SampleVectorInit, Samples, SamplesView, Summary, SummaryRow, SummaryView, UnitType, ValueType };
Loading
Loading