Skip to content

Instantly share code, notes, and snippets.

View tobz's full-sized avatar
💁‍♂️
it me

Toby Lawrence tobz

💁‍♂️
it me
View GitHub Profile
{
static METRICS_INIT: metrics::OnceIdentifier = metrics::OnceIdentifier::new();
if let Some(recorder) = metrics::try_recorder() {
let id = METRICS_INIT.get_or_init(|| {
recorder.register_histogram(
{
format!("{}.{}", std::module_path!(), "service.execution_time")
}
.into(),
None,
@tobz
tobz / blah.rs
Last active April 15, 2020 14:34
fn poll_write(
self: Pin<&mut Self>,
cx: &mut Context,
buf: &[u8]
) -> Poll<io::Result<usize>> {
let me = self.project();
// encrypt our input buffer
let mut ebuf = if let Some(wbuf) = me.remaining.take() {
// we had a leftover buffer, so extend it from our current input,
impl<S: AsyncRead + Unpin> AsyncRead for Decryption<S> {
fn poll_read(
self: Pin<&mut Self>,
cx: &mut Context,
buf: &mut [u8]
) -> Poll<io::Result<usize>> {
let this = self.project();
let n = match this.stream.poll_read(cx, buf) {
Poll::Pending => return Poll::Pending,
Poll::Ready(res) => res?,
// current best approach i can think of (doesn't optimize for static labels):
struct Metadata<'a> {
fields: &'static [&'static str],
// not even sure if this works with items having same lifetime as the list? whatever
values: &'a [&'a str],
}
fn with_runtime_labels() {
// this is some label value, gathered at runtime, of type &'a str
pub fn handle_logfilter<S>(handle: Handle<EnvFilter, S>)
-> impl Filter<Extract = impl Reply, Error = Rejection> + Clone
where
S: Subscriber,
{
let handle = warp::any().map(move || handle.clone());
warp::path("logfilter")
.and(warp::post())
.and(
warp::body::bytes().and_then(|body: Bytes| async move {
syntax = "proto3";
package grpc.pettycache.cache;
message GetSingleKeyRequest {
bytes key = 1;
}
message GetSingleKeyResponse {
bytes key = 1;
# using tokio ^0.1 and metrics-exporter-http ^0.2
std::thread::spawn(move || {
tokio::runtime::current_thread::block_on_all(exporter.into_future());
});
@tobz
tobz / context.rs
Last active December 4, 2019 20:18
use std::sync::Arc;
use futures_intrusive::sync::ManualResetEvent;
use crate::wg::{WaitGroup, WaitGroupHandle};
pub struct Context {
start: WaitGroup,
done: WaitGroup,
close: Arc<ManualResetEvent>,
}
pub async fn parse_redis_value_async<R>(reader: &mut R) -> RedisResult<Value>
where
R: AsyncBufRead + Unpin,
{
let mut state = AnySendPartialState::default();
let mut pending_data = false;
let mut buffered = Vec::new();
loop {
// Figure out the view into our "current" buffer. We can track of data returned by the
/// Parses a redis value asynchronously.
pub async fn parse_redis_value_async<R>(reader: &mut R) -> RedisResult<Value>
where
R: AsyncBufRead,
{
let mut state = AnySendPartialState::default();
let mut pending_data = false;
let mut buffered = Vec::new();