-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: MOZGIII <mike-n@narod.ru>
- Loading branch information
Showing
16 changed files
with
482 additions
and
4 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
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,24 @@ | ||
use super::InternalEvent; | ||
use std::fmt::Debug; | ||
|
||
#[derive(Debug)] | ||
pub struct RequestPrepared<R> { | ||
pub request: R, | ||
} | ||
|
||
impl<R: Debug> InternalEvent for RequestPrepared<R> { | ||
fn emit_logs(&self) { | ||
trace!(message = "request prepared", ?self.request); | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct ResponseReceived<R> { | ||
pub response: R, | ||
} | ||
|
||
impl<R: Debug> InternalEvent for ResponseReceived<R> { | ||
fn emit_logs(&self) { | ||
trace!(message = "got response", ?self.response); | ||
} | ||
} |
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,39 @@ | ||
use super::InternalEvent; | ||
use metrics::counter; | ||
use std::fmt::Debug; | ||
|
||
#[derive(Debug)] | ||
pub struct StateItemAdded; | ||
|
||
#[derive(Debug)] | ||
pub struct StateItemUpdated; | ||
|
||
#[derive(Debug)] | ||
pub struct StateItemDeleted; | ||
|
||
#[derive(Debug)] | ||
pub struct StateResynced; | ||
|
||
impl InternalEvent for StateItemAdded { | ||
fn emit_metrics(&self) { | ||
counter!("k8s_state_ops", 1, "op_kind" => "item_added"); | ||
} | ||
} | ||
|
||
impl InternalEvent for StateItemUpdated { | ||
fn emit_metrics(&self) { | ||
counter!("k8s_state_ops", 1, "op_kind" => "item_updated"); | ||
} | ||
} | ||
|
||
impl InternalEvent for StateItemDeleted { | ||
fn emit_metrics(&self) { | ||
counter!("k8s_state_ops", 1, "op_kind" => "item_deleted"); | ||
} | ||
} | ||
|
||
impl InternalEvent for StateResynced { | ||
fn emit_metrics(&self) { | ||
counter!("k8s_state_ops", 1, "op_kind" => "resynced"); | ||
} | ||
} |
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 @@ | ||
use super::InternalEvent; | ||
use metrics::counter; | ||
use std::fmt::Debug; | ||
|
||
#[derive(Debug)] | ||
pub struct WatchRequestInvoked; | ||
|
||
impl InternalEvent for WatchRequestInvoked { | ||
fn emit_metrics(&self) { | ||
counter!("k8s_watch_request_invoked", 1); | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct WatchRequestInvocationFailed<E> { | ||
pub error: E, | ||
} | ||
|
||
impl<E: Debug> InternalEvent for WatchRequestInvocationFailed<E> { | ||
fn emit_logs(&self) { | ||
error!(message = "watch invocation failed", ?self.error); | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct WatchStreamItemObtained; | ||
|
||
impl InternalEvent for WatchStreamItemObtained { | ||
fn emit_metrics(&self) { | ||
counter!("k8s_watch_stream_items_obtained", 1); | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct WatchStreamErrored<E> { | ||
pub error: E, | ||
} | ||
|
||
impl<E: Debug> InternalEvent for WatchStreamErrored<E> { | ||
fn emit_logs(&self) { | ||
error!(message = "watch stream errored", ?self.error); | ||
} | ||
} |
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,9 @@ | ||
#![cfg(feature = "kubernetes")] | ||
|
||
use super::InternalEvent; | ||
|
||
pub mod api_watcher; | ||
pub mod instrumenting_state; | ||
pub mod instrumenting_watcher; | ||
pub mod reflector; | ||
pub mod stream; |
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,19 @@ | ||
use super::InternalEvent; | ||
use metrics::counter; | ||
|
||
/// Emitted when reflector gets a desync from the watch command. | ||
#[derive(Debug)] | ||
pub struct DesyncReceived<E> { | ||
/// The underlying error. | ||
pub error: E, | ||
} | ||
|
||
impl<E: std::fmt::Debug> InternalEvent for DesyncReceived<E> { | ||
fn emit_logs(&self) { | ||
warn!(message = "handling desync", error = ?self.error); | ||
} | ||
|
||
fn emit_metrics(&self) { | ||
counter!("k8s_reflector_desyncs", 1); | ||
} | ||
} |
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,14 @@ | ||
use super::InternalEvent; | ||
use metrics::counter; | ||
|
||
#[derive(Debug)] | ||
pub struct ChunkProcessed { | ||
pub byte_size: usize, | ||
} | ||
|
||
impl InternalEvent for ChunkProcessed { | ||
fn emit_metrics(&self) { | ||
counter!("k8s_stream_chunks_processed", 1); | ||
counter!("k8s_stream_bytes_processed", self.byte_size as u64); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
//! A watcher that adds instrumentation. | ||
use super::watcher::{self, Watcher}; | ||
use crate::internal_events::kubernetes::instrumenting_watcher as internal_events; | ||
use futures::{future::BoxFuture, stream::BoxStream, FutureExt, StreamExt}; | ||
use k8s_openapi::{WatchOptional, WatchResponse}; | ||
|
||
/// A watcher that wraps another watcher with instrumentation calls. | ||
pub struct InstrumentingWatcher<T> | ||
where | ||
T: Watcher, | ||
{ | ||
inner: T, | ||
} | ||
|
||
impl<T> InstrumentingWatcher<T> | ||
where | ||
T: Watcher, | ||
{ | ||
/// Create a new [`InstrumentingWatcher`]. | ||
pub fn new(inner: T) -> Self { | ||
Self { inner } | ||
} | ||
} | ||
|
||
impl<T> Watcher for InstrumentingWatcher<T> | ||
where | ||
T: Watcher, | ||
<T as Watcher>::Stream: 'static, | ||
{ | ||
type Object = <T as Watcher>::Object; | ||
|
||
type InvocationError = <T as Watcher>::InvocationError; | ||
|
||
type StreamError = <T as Watcher>::StreamError; | ||
type Stream = BoxStream<'static, Result<WatchResponse<Self::Object>, Self::StreamError>>; | ||
|
||
fn watch<'a>( | ||
&'a mut self, | ||
watch_optional: WatchOptional<'a>, | ||
) -> BoxFuture<'a, Result<Self::Stream, watcher::invocation::Error<Self::InvocationError>>> | ||
{ | ||
Box::pin(self.inner.watch(watch_optional).map(|result| { | ||
result | ||
.map(|stream| { | ||
emit!(internal_events::WatchRequestInvoked); | ||
Box::pin(stream.map(|item_result| { | ||
item_result | ||
.map(|item| { | ||
emit!(internal_events::WatchStreamItemObtained); | ||
item | ||
}) | ||
.map_err(|error| { | ||
emit!(internal_events::WatchRequestInvocationFailed { | ||
error: &error | ||
}); | ||
error | ||
}) | ||
})) as BoxStream<'static, _> | ||
}) | ||
.map_err(|error| { | ||
emit!(internal_events::WatchRequestInvocationFailed { error: &error }); | ||
error | ||
}) | ||
})) | ||
} | ||
} |
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
Oops, something went wrong.