Skip to content

Commit

Permalink
feat(types): adds additional type definitions for Signalflow client, …
Browse files Browse the repository at this point in the history
…and ingest client (#113)

1. includes additional code from Splunk's internal types for the Signalflow client
1. includes types for ingest client from the `@types/signalfx` npm module
  • Loading branch information
sfishel-splunk authored Feb 6, 2024
1 parent 1625c26 commit d263cd7
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 40 deletions.
4 changes: 4 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
The Initial Developers of the ingest.d.ts file are Vladimir Grenaderov <https://github.com/VladimirGrenaderov> and Max Boguslavskiy <https://github.com/maxbogus>.
Copyright 2019 - 2024 Vladimir Grenaderov and Max Boguslavskiy. All Rights Reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
35 changes: 35 additions & 0 deletions lib/ingest.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Definitions by: Vladimir Grenaderov <https://github.com/VladimirGrenaderov>
// Max Boguslavskiy <https://github.com/maxbogus>

export interface IngestOptions {
enableAmazonUniqueId?: boolean | undefined;
dimensions?: object | undefined;
ingestEndpoint?: string | undefined;
timeout?: number | undefined;
batchSize?: number | undefined;
userAgents?: string[] | undefined;
proxy?: string | undefined;
}

export interface SignalMetric {
metric: string;
value: number;
timestamp?: number | undefined;
dimensions?: object | undefined;
}

export interface SignalReport {
cumulative_counters?: SignalMetric[] | undefined;
gauges?: SignalMetric[] | undefined;
counters?: SignalMetric[] | undefined;
}

export class Ingest {
constructor(token: string, options?: IngestOptions);
send(report: SignalReport): void;
}

export class IngestJson {
constructor(token: string, options?: IngestOptions);
send(report: SignalReport): void;
}
150 changes: 110 additions & 40 deletions lib/signalfx.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,72 @@ export type Streamer = {

export const streamer: Streamer;

type StreamControlMessageStreamStart = {
event: 'STREAM_START' | 'END_OF_CHANNEL';
type StreamControlMessageBase = {
type: 'control-message';
channel: string;
timestampMs: number;
};

export type StreamControlMessageStreamStart = StreamControlMessageBase & {
event: 'STREAM_START';
traceId: string;
};

export type StreamControlMessageEndOfChannel = StreamControlMessageBase & {
event: 'END_OF_CHANNEL';
};

export type StreamControlMessageKeepAlive = StreamControlMessageBase & {
event: 'KEEP_ALIVE';
};

type StreamControlMessageJobStart = {
export type StreamControlMessageJobStart = StreamControlMessageBase & {
event: 'JOB_START';
handle: string;
};

type StreamControlMessageJobProgress = {
export type StreamControlMessageJobProgress = StreamControlMessageBase & {
event: 'JOB_PROGRESS';
progress: number;
};

export type StreamControlMessageChannelAbort = StreamControlMessageBase & {
event: 'CHANNEL_ABORT';
abortInfo: Record<string, unknown>;
};

export type StreamControlMessageChannelAttach = StreamControlMessageBase & {
event: 'ATTACH';
channelsAttached: unknown;
};

export type StreamControlMessageChannelDetach = StreamControlMessageBase & {
event: 'DETACH';
channelsDetached: unknown;
};

/**
* Provide information about the stream itself
*/
type StreamControlMessage = {
export type StreamControlMessage = {
type: 'control-message';
channel: string;
timestampMs: number;
} & (
| StreamControlMessageStreamStart
| StreamControlMessageEndOfChannel
| StreamControlMessageKeepAlive
| StreamControlMessageJobStart
| StreamControlMessageJobProgress
| StreamControlMessageChannelAbort
| StreamControlMessageChannelAttach
| StreamControlMessageChannelDetach
);

/**
* Metadata messages contain the metadata from the output time series of your computation.
*/
type StreamMetadataMessage = {
export type StreamMetadataMessage = {
type: 'metadata';
channel: string;
tsId: string;
Expand All @@ -76,32 +111,34 @@ type StreamMetadataMessage = {
/**
* Expired TSID messages indicate that a specific output timeseries is probably no longer useful for the computation.
*/
type StreamExpiredTSIDMessage = {
export type StreamExpiredTSIDMessage = {
type: 'expired-tsid';
channel: string;
tsId: string;
};

type StreamDataPoint = {
export type StreamDataPoint = {
tsId: string;
value: number;
};

/**
* Data messages contain the actual timeseries results generated by the computation.
*/
type StreamDataMessage = {
export type StreamDataMessage = {
type: 'data';
channel: string;
data: StreamDataPoint[];
logicalTimestampMs: number;
maxDelayMs?: number;
};

type EventState = 'ok' | 'anomalous' | 'manually_resolved' | 'stopped';
export type EventState = 'ok' | 'anomalous' | 'manually_resolved' | 'stopped';

/**
* Sent when an anomaly triggers a SignalFx detector, or when the triggered detector resolves
*/
type StreamEventMessage = {
export type StreamEventMessage = {
type: 'event';
channel: string;
properties: {
Expand All @@ -114,7 +151,31 @@ type StreamEventMessage = {
tsId: string;
};

type StreamMessageMessage = {
export declare type LiveTailMetadata = {
eventsMatched: number;
eventsSent: number;
};

export type LiveTailResult = {
id: string;
_raw: string;
_time: string;
[key: string]: string | number;
};

export type StreamLogDataMessage = {
type: 'log-data';
results: LiveTailResult[];
metadata: LiveTailMetadata;
};

export type StreamLiveTailStartedMessage = {
type: 'livetail-started';
channel: string;
timestampMs: number;
};

export type StreamMessageMessage = {
type: 'message';
channel: string;
logicalTimestampMs: number;
Expand All @@ -127,18 +188,40 @@ type StreamMessageMessage = {
};
};

export type StreamAuthenticatedMessage = {
type: 'authenticated';
channel: string;
userId: string;
orgId: string;
};

export type StreamComputationStartedMessage = {
type: 'computation-started';
channel: string;
computationId: string;
};

export type StreamEstimationMessage = {
type: 'estimation';
channel: string;
result: unknown;
};

/**
* Union of all stream messages.
*/
type StreamMessage =
export type StreamMessage =
| StreamControlMessage
| StreamMetadataMessage
| StreamExpiredTSIDMessage
| StreamDataMessage
| StreamEventMessage
| StreamLogDataMessage
| StreamLiveTailStartedMessage
| StreamMessageMessage;
| StreamMessageMessage
| StreamAuthenticatedMessage
| StreamComputationStartedMessage
| StreamEstimationMessage;

export type StreamError = {
type: 'error';
Expand All @@ -150,20 +233,20 @@ export type StreamError = {
errors?: { code: string }[];
};

type StreamCallback = (error: StreamError | undefined, message: StreamMessage | undefined) => void;
export type StreamCallback = (error: StreamError | undefined, message: StreamMessage | undefined) => void;

interface LiveTailOptions {
export interface LiveTailOptions {
query: object;
throttleOptions: object;
}
interface SignalFlowClient {
export interface SignalFlowClient {
execute(opts: ExecuteOptions): Stream;
disconnect(): void;
livetail(opts: LiveTailOptions): LiveTail | undefined;
initialized?: boolean;
}

interface Stream {
export interface Stream {
stream(fn: StreamCallback): boolean;
close(): boolean;

Expand All @@ -173,31 +256,18 @@ interface Stream {
get_metadata(tsId: string): StreamMetadataMessage;
}

interface LiveTail {
export interface LiveTail {
stream(fn: StreamCallback): boolean;
close(): boolean;
}

export type LiveTailResult = {
id: string;
_raw: string;
_time: string;
[key: string]: string | number;
};

export type StreamLogDataMessage = {
type: 'log-data';
results: LiveTailResult[];
metadata: LiveTailMetadata;
};

export declare type LiveTailMetadata = {
eventsMatched: number;
eventsSent: number;
export const CONSTANTS: {
MESSAGE_TYPES: {
METADATA: 'metadata',
DATA: 'data',
EVENT: 'event',
CONTROL: 'control-message'
};
};

export type StreamLiveTailStartedMessage = {
type: 'livetail-started';
channel: string;
timestampMs: number;
};
export * from './ingest';

0 comments on commit d263cd7

Please sign in to comment.