pepr 0.45.0-nightly.2 → 0.45.0-nightly.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +1 -1
- package/dist/controller.js +1 -1
- package/dist/lib/processors/watch-processor.d.ts +22 -1
- package/dist/lib/processors/watch-processor.d.ts.map +1 -1
- package/dist/lib/telemetry/metrics.d.ts +2 -3
- package/dist/lib/telemetry/metrics.d.ts.map +1 -1
- package/dist/lib.js +26 -27
- package/dist/lib.js.map +3 -3
- package/package.json +3 -3
- package/src/lib/processors/watch-processor.ts +58 -33
- package/src/lib/telemetry/metrics.ts +3 -3
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"!src/**/*.test.ts",
|
|
16
16
|
"!dist/**/*.test.d.ts*"
|
|
17
17
|
],
|
|
18
|
-
"version": "0.45.0-nightly.
|
|
18
|
+
"version": "0.45.0-nightly.4",
|
|
19
19
|
"main": "dist/lib.js",
|
|
20
20
|
"types": "dist/lib.d.ts",
|
|
21
21
|
"scripts": {
|
|
@@ -48,12 +48,12 @@
|
|
|
48
48
|
"follow-redirects": "1.15.9",
|
|
49
49
|
"http-status-codes": "^2.3.0",
|
|
50
50
|
"json-pointer": "^0.6.2",
|
|
51
|
-
"kubernetes-fluent-client": "3.
|
|
51
|
+
"kubernetes-fluent-client": "3.4.0",
|
|
52
52
|
"pino": "9.6.0",
|
|
53
53
|
"pino-pretty": "13.0.0",
|
|
54
54
|
"prom-client": "15.1.3",
|
|
55
55
|
"ramda": "0.30.1",
|
|
56
|
-
"sigstore": "3.
|
|
56
|
+
"sigstore": "3.1.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@commitlint/cli": "19.7.1",
|
|
@@ -4,11 +4,12 @@ import Log from "../telemetry/logger";
|
|
|
4
4
|
import { Binding } from "../types";
|
|
5
5
|
import { Capability } from "../core/capability";
|
|
6
6
|
import { Event } from "../enums";
|
|
7
|
-
import { K8s, KubernetesObject, WatchCfg, WatchEvent } from "kubernetes-fluent-client";
|
|
7
|
+
import { K8s, KubernetesObject, WatchCfg, WatchEvent, GenericClass } from "kubernetes-fluent-client";
|
|
8
8
|
import { Queue } from "../core/queue";
|
|
9
|
-
import { WatchPhase } from "kubernetes-fluent-client/dist/fluent/types";
|
|
9
|
+
import { WatchPhase, WatcherType } from "kubernetes-fluent-client/dist/fluent/types";
|
|
10
|
+
import { KubernetesListObject } from "kubernetes-fluent-client/dist/types";
|
|
10
11
|
import { filterNoMatchReason } from "../filter/filter";
|
|
11
|
-
import { metricsCollector } from "../telemetry/metrics";
|
|
12
|
+
import { metricsCollector, MetricsCollectorInstance } from "../telemetry/metrics";
|
|
12
13
|
import { removeFinalizer } from "../finalizer";
|
|
13
14
|
|
|
14
15
|
// stores Queue instances
|
|
@@ -157,36 +158,8 @@ async function runBinding(
|
|
|
157
158
|
}
|
|
158
159
|
}, watchCfg);
|
|
159
160
|
|
|
160
|
-
//
|
|
161
|
-
watcher
|
|
162
|
-
Log.error(err, "Watch failed after 5 attempts, giving up");
|
|
163
|
-
process.exit(1);
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
watcher.events.on(WatchEvent.CONNECT, url => logEvent(WatchEvent.CONNECT, url));
|
|
167
|
-
|
|
168
|
-
watcher.events.on(WatchEvent.DATA_ERROR, err => logEvent(WatchEvent.DATA_ERROR, err.message));
|
|
169
|
-
watcher.events.on(WatchEvent.RECONNECT, retryCount =>
|
|
170
|
-
logEvent(WatchEvent.RECONNECT, `Reconnecting after ${retryCount} attempt${retryCount === 1 ? "" : "s"}`),
|
|
171
|
-
);
|
|
172
|
-
watcher.events.on(WatchEvent.RECONNECT_PENDING, () => logEvent(WatchEvent.RECONNECT_PENDING));
|
|
173
|
-
watcher.events.on(WatchEvent.GIVE_UP, err => logEvent(WatchEvent.GIVE_UP, err.message));
|
|
174
|
-
watcher.events.on(WatchEvent.ABORT, err => logEvent(WatchEvent.ABORT, err.message));
|
|
175
|
-
watcher.events.on(WatchEvent.OLD_RESOURCE_VERSION, err => logEvent(WatchEvent.OLD_RESOURCE_VERSION, err));
|
|
176
|
-
watcher.events.on(WatchEvent.NETWORK_ERROR, err => logEvent(WatchEvent.NETWORK_ERROR, err.message));
|
|
177
|
-
watcher.events.on(WatchEvent.LIST_ERROR, err => logEvent(WatchEvent.LIST_ERROR, err.message));
|
|
178
|
-
watcher.events.on(WatchEvent.LIST, list => logEvent(WatchEvent.LIST, JSON.stringify(list, undefined, 2)));
|
|
179
|
-
watcher.events.on(WatchEvent.CACHE_MISS, windowName => {
|
|
180
|
-
metricsCollector.incCacheMiss(windowName);
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
watcher.events.on(WatchEvent.INIT_CACHE_MISS, windowName => {
|
|
184
|
-
metricsCollector.initCacheMissWindow(windowName);
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
watcher.events.on(WatchEvent.INC_RESYNC_FAILURE_COUNT, retryCount => {
|
|
188
|
-
metricsCollector.incRetryCount(retryCount);
|
|
189
|
-
});
|
|
161
|
+
// Register event handlers
|
|
162
|
+
registerWatchEventHandlers(watcher, logEvent, metricsCollector);
|
|
190
163
|
|
|
191
164
|
// Start the watch
|
|
192
165
|
try {
|
|
@@ -205,3 +178,55 @@ export function logEvent(event: WatchEvent, message: string = "", obj?: Kubernet
|
|
|
205
178
|
Log.debug(logMessage);
|
|
206
179
|
}
|
|
207
180
|
}
|
|
181
|
+
|
|
182
|
+
export type WatchEventArgs<K extends WatchEvent, T extends GenericClass> = {
|
|
183
|
+
[WatchEvent.LIST]: KubernetesListObject<InstanceType<T>>;
|
|
184
|
+
[WatchEvent.RECONNECT]: number;
|
|
185
|
+
[WatchEvent.CACHE_MISS]: string;
|
|
186
|
+
[WatchEvent.INIT_CACHE_MISS]: string;
|
|
187
|
+
[WatchEvent.GIVE_UP]: Error;
|
|
188
|
+
[WatchEvent.ABORT]: Error;
|
|
189
|
+
[WatchEvent.OLD_RESOURCE_VERSION]: string;
|
|
190
|
+
[WatchEvent.NETWORK_ERROR]: Error;
|
|
191
|
+
[WatchEvent.LIST_ERROR]: Error;
|
|
192
|
+
[WatchEvent.DATA_ERROR]: Error;
|
|
193
|
+
[WatchEvent.CONNECT]: string;
|
|
194
|
+
[WatchEvent.RECONNECT_PENDING]: undefined;
|
|
195
|
+
[WatchEvent.DATA]: undefined;
|
|
196
|
+
[WatchEvent.INC_RESYNC_FAILURE_COUNT]: number;
|
|
197
|
+
}[K];
|
|
198
|
+
|
|
199
|
+
export type LogEventFunction = (event: WatchEvent, message?: string) => void;
|
|
200
|
+
export function registerWatchEventHandlers(
|
|
201
|
+
watcher: WatcherType<GenericClass>,
|
|
202
|
+
logEvent: LogEventFunction,
|
|
203
|
+
metricsCollector: MetricsCollectorInstance,
|
|
204
|
+
): void {
|
|
205
|
+
const eventHandlers: {
|
|
206
|
+
[K in WatchEvent]?: (arg: WatchEventArgs<K, GenericClass>) => void;
|
|
207
|
+
} = {
|
|
208
|
+
[WatchEvent.DATA]: () => null,
|
|
209
|
+
[WatchEvent.GIVE_UP]: err => {
|
|
210
|
+
// If failure continues, log and exit
|
|
211
|
+
logEvent(WatchEvent.GIVE_UP, err.message);
|
|
212
|
+
process.exit(1);
|
|
213
|
+
},
|
|
214
|
+
[WatchEvent.CONNECT]: url => logEvent(WatchEvent.CONNECT, url),
|
|
215
|
+
[WatchEvent.DATA_ERROR]: err => logEvent(WatchEvent.DATA_ERROR, err.message),
|
|
216
|
+
[WatchEvent.RECONNECT]: retryCount =>
|
|
217
|
+
logEvent(WatchEvent.RECONNECT, `Reconnecting after ${retryCount} attempt${retryCount === 1 ? "" : "s"}`),
|
|
218
|
+
[WatchEvent.RECONNECT_PENDING]: () => logEvent(WatchEvent.RECONNECT_PENDING),
|
|
219
|
+
[WatchEvent.ABORT]: err => logEvent(WatchEvent.ABORT, err.message),
|
|
220
|
+
[WatchEvent.OLD_RESOURCE_VERSION]: errMessage => logEvent(WatchEvent.OLD_RESOURCE_VERSION, errMessage),
|
|
221
|
+
[WatchEvent.NETWORK_ERROR]: err => logEvent(WatchEvent.NETWORK_ERROR, err.message),
|
|
222
|
+
[WatchEvent.LIST_ERROR]: err => logEvent(WatchEvent.LIST_ERROR, err.message),
|
|
223
|
+
[WatchEvent.LIST]: list => logEvent(WatchEvent.LIST, JSON.stringify(list, undefined, 2)),
|
|
224
|
+
[WatchEvent.CACHE_MISS]: windowName => metricsCollector.incCacheMiss(windowName),
|
|
225
|
+
[WatchEvent.INIT_CACHE_MISS]: windowName => metricsCollector.initCacheMissWindow(windowName),
|
|
226
|
+
[WatchEvent.INC_RESYNC_FAILURE_COUNT]: retryCount => metricsCollector.incRetryCount(retryCount),
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
Object.entries(eventHandlers).forEach(([event, handler]) => {
|
|
230
|
+
watcher.events.on(event, handler);
|
|
231
|
+
});
|
|
232
|
+
}
|
|
@@ -9,7 +9,7 @@ import Log from "./logger";
|
|
|
9
9
|
|
|
10
10
|
const loggingPrefix = "MetricsCollector";
|
|
11
11
|
|
|
12
|
-
type MetricsCollectorInstance = InstanceType<typeof MetricsCollector>;
|
|
12
|
+
export type MetricsCollectorInstance = InstanceType<typeof MetricsCollector>;
|
|
13
13
|
interface MetricNames {
|
|
14
14
|
errors: string;
|
|
15
15
|
alerts: string;
|
|
@@ -148,8 +148,8 @@ export class MetricsCollector {
|
|
|
148
148
|
* Increments the retry count gauge.
|
|
149
149
|
* @param count - The count to increment by.
|
|
150
150
|
*/
|
|
151
|
-
incRetryCount = (count:
|
|
152
|
-
this.incGauge(this.#metricNames.resyncFailureCount, { count });
|
|
151
|
+
incRetryCount = (count: number): void => {
|
|
152
|
+
this.incGauge(this.#metricNames.resyncFailureCount, { count: count.toString() });
|
|
153
153
|
};
|
|
154
154
|
|
|
155
155
|
/**
|