Skip to content

Commit

Permalink
Update dependencies, add deny.toml (#261)
Browse files Browse the repository at this point in the history
Co-authored-by: Mark Mandel <[email protected]>
  • Loading branch information
XAMPPRocky and markmandel authored May 18, 2021
1 parent efdd0f7 commit 57dd4b6
Show file tree
Hide file tree
Showing 13 changed files with 92 additions and 64 deletions.
20 changes: 10 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,32 @@ categories = ["game-development", "network-programming"]
edition = "2018"

[dependencies]
backoff = "0.2.1"
backoff = "0.3"
base64 = "0.13"
base64-serde = "0.6"
bytes = "1.0.1"
clap = "2.33.0"
either = "1.6.1"
humantime-serde = "1.0.0"
hyper = "0.14.2"
num_cpus = "1.13.0"
parking_lot = "0.11.0"
prometheus = { version = "0.9", default-features = false }
prometheus = { version = "0.12", default-features = false }
prost = "0.7.0"
prost-types = "0.7.0"
rand = "0.8"
serde = { version = "1.0.104", features = ["derive"] }
serde_yaml = "0.8.11"
serde_json = "1.0.60"
serde_yaml = "0.8.11"
slog = "2.7.0"
slog-async = "2.6.0"
slog-json = "2.3.0"
tokio = { version = "1.1.0", features = ["rt-multi-thread", "signal", "test-util", "parking_lot"] }
slog-term = "2.5.0"
rand = "0.7.3"
base64 = "0.12.3"
base64-serde = "0.5.1"
tonic = "0.4.0"
uuid = {version = "0.8.1", default-features = false, features = ["v4"]}
snap = "1.0.3"
tokio = { version = "1.1.0", features = ["rt-multi-thread", "signal", "test-util", "parking_lot"] }
tokio-stream = "0.1.2"
either = "1.6.1"
tonic = "0.4.0"
uuid = {version = "0.8.1", default-features = false, features = ["v4"]}

[dev-dependencies]
reqwest = "0.11.0"
Expand Down
28 changes: 28 additions & 0 deletions deny.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#
# Copyright 2021 Google LLC All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# This section is considered when running `cargo deny check licenses`
# More documentation for the licenses section can be found here:
# https://embarkstudios.github.io/cargo-deny/checks/licenses/cfg.html
[licenses]
unlicensed = "deny"
copyleft = "deny"
default = "allow"
exceptions = [
# Each entry is the crate and version constraint, and its specific allow
# list
{ allow = ["MPL-2.0"], name = "slog-json", version = "*" },
]
4 changes: 2 additions & 2 deletions src/extensions/filters/capture_bytes/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
use prometheus::core::{AtomicI64, GenericCounter};
use prometheus::core::{AtomicU64, GenericCounter};
use prometheus::Result as MetricsResult;
use prometheus::{IntCounter, Registry};

use crate::metrics::{filter_opts, CollectorExt};

/// Register and manage metrics for this filter
pub(super) struct Metrics {
pub(super) packets_dropped_total: GenericCounter<AtomicI64>,
pub(super) packets_dropped_total: GenericCounter<AtomicU64>,
}

impl Metrics {
Expand Down
10 changes: 5 additions & 5 deletions src/extensions/filters/compress/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
use prometheus::core::{AtomicI64, GenericCounter};
use prometheus::core::{AtomicU64, GenericCounter};
use prometheus::{IntCounter, Registry};
use prometheus::{IntCounterVec, Result as MetricsResult};

use crate::metrics::{filter_opts, CollectorExt};

/// Register and manage metrics for this filter
pub(super) struct Metrics {
pub(super) packets_dropped_compress: GenericCounter<AtomicI64>,
pub(super) packets_dropped_decompress: GenericCounter<AtomicI64>,
pub(super) compressed_bytes_total: GenericCounter<AtomicI64>,
pub(super) decompressed_bytes_total: GenericCounter<AtomicI64>,
pub(super) packets_dropped_compress: GenericCounter<AtomicU64>,
pub(super) packets_dropped_decompress: GenericCounter<AtomicU64>,
pub(super) compressed_bytes_total: GenericCounter<AtomicU64>,
pub(super) decompressed_bytes_total: GenericCounter<AtomicU64>,
}

impl Metrics {
Expand Down
36 changes: 18 additions & 18 deletions src/extensions/filters/compress/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ impl Compress {
/// Track a failed attempt at compression
fn failed_compression<T>(&self, err: Box<dyn std::error::Error>) -> Option<T> {
if self.metrics.packets_dropped_compress.get() % 1000 == 0 {
warn!(self.log, "Packets are being dropped as they could not be compressed";
"mode" => #?self.compression_mode, "error" => %err,
warn!(self.log, "Packets are being dropped as they could not be compressed";
"mode" => #?self.compression_mode, "error" => %err,
"count" => self.metrics.packets_dropped_compress.get());
}
self.metrics.packets_dropped_compress.inc();
Expand All @@ -198,8 +198,8 @@ impl Compress {
/// Track a failed attempt at decompression
fn failed_decompression<T>(&self, err: Box<dyn std::error::Error>) -> Option<T> {
if self.metrics.packets_dropped_decompress.get() % 1000 == 0 {
warn!(self.log, "Packets are being dropped as they could not be decompressed";
"mode" => #?self.compression_mode, "error" => %err,
warn!(self.log, "Packets are being dropped as they could not be decompressed";
"mode" => #?self.compression_mode, "error" => %err,
"count" => self.metrics.packets_dropped_decompress.get());
}
self.metrics.packets_dropped_decompress.inc();
Expand All @@ -216,10 +216,10 @@ impl Filter for Compress {
Ok(()) => {
self.metrics
.decompressed_bytes_total
.inc_by(original_size as i64);
.inc_by(original_size as u64);
self.metrics
.compressed_bytes_total
.inc_by(ctx.contents.len() as i64);
.inc_by(ctx.contents.len() as u64);
Some(ctx.into())
}
Err(err) => self.failed_compression(err),
Expand All @@ -228,10 +228,10 @@ impl Filter for Compress {
Ok(()) => {
self.metrics
.compressed_bytes_total
.inc_by(original_size as i64);
.inc_by(original_size as u64);
self.metrics
.decompressed_bytes_total
.inc_by(ctx.contents.len() as i64);
.inc_by(ctx.contents.len() as u64);
Some(ctx.into())
}
Err(err) => self.failed_decompression(err),
Expand All @@ -247,10 +247,10 @@ impl Filter for Compress {
Ok(()) => {
self.metrics
.decompressed_bytes_total
.inc_by(original_size as i64);
.inc_by(original_size as u64);
self.metrics
.compressed_bytes_total
.inc_by(ctx.contents.len() as i64);
.inc_by(ctx.contents.len() as u64);
Some(ctx.into())
}
Err(err) => self.failed_compression(err),
Expand All @@ -259,10 +259,10 @@ impl Filter for Compress {
Ok(()) => {
self.metrics
.compressed_bytes_total
.inc_by(original_size as i64);
.inc_by(original_size as u64);
self.metrics
.decompressed_bytes_total
.inc_by(ctx.contents.len() as i64);
.inc_by(ctx.contents.len() as u64);
Some(ctx.into())
}

Expand Down Expand Up @@ -490,11 +490,11 @@ mod tests {
read_response.contents.len()
);
assert_eq!(
expected.len() as i64,
expected.len() as u64,
compress.metrics.decompressed_bytes_total.get()
);
assert_eq!(
read_response.contents.len() as i64,
read_response.contents.len() as u64,
compress.metrics.compressed_bytes_total.get()
);

Expand All @@ -514,11 +514,11 @@ mod tests {
assert_eq!(0, compress.metrics.packets_dropped_compress.get());
// multiply by two, because data was sent both upstream and downstream
assert_eq!(
(read_response.contents.len() * 2) as i64,
(read_response.contents.len() * 2) as u64,
compress.metrics.compressed_bytes_total.get()
);
assert_eq!(
(expected.len() * 2) as i64,
(expected.len() * 2) as u64,
compress.metrics.decompressed_bytes_total.get()
);
}
Expand All @@ -540,11 +540,11 @@ mod tests {

// multiply by two, because data was sent both downstream and upstream
assert_eq!(
(compressed.len() * 2) as i64,
(compressed.len() * 2) as u64,
compress.metrics.compressed_bytes_total.get()
);
assert_eq!(
(expected.len() * 2) as i64,
(expected.len() * 2) as u64,
compress.metrics.decompressed_bytes_total.get()
);

Expand Down
2 changes: 1 addition & 1 deletion src/extensions/filters/load_balancer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub struct RandomEndpointChooser;
impl EndpointChooser for RandomEndpointChooser {
fn choose_endpoints(&self, endpoints: &mut UpstreamEndpoints) {
// Note: Unwrap is safe here because the index is guaranteed to be in range.
let idx = (&mut thread_rng()).gen_range(0, endpoints.size());
let idx = (&mut thread_rng()).gen_range(0..endpoints.size());
endpoints.keep(idx)
.expect("BUG: unwrap should have been safe because index into endpoints list should be in range");
}
Expand Down
4 changes: 2 additions & 2 deletions src/extensions/filters/local_rate_limit/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
*/

use crate::metrics::{filter_opts, CollectorExt};
use prometheus::core::{AtomicI64, GenericCounter};
use prometheus::core::{AtomicU64, GenericCounter};
use prometheus::Result as MetricsResult;
use prometheus::{IntCounter, Registry};

pub(super) struct Metrics {
pub(super) packets_dropped_total: GenericCounter<AtomicI64>,
pub(super) packets_dropped_total: GenericCounter<AtomicU64>,
}

impl Metrics {
Expand Down
8 changes: 4 additions & 4 deletions src/extensions/filters/token_router/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
use prometheus::core::{AtomicI64, GenericCounter};
use prometheus::core::{AtomicU64, GenericCounter};
use prometheus::{IntCounterVec, Registry, Result as MetricsResult};

use crate::metrics::{filter_opts, CollectorExt};

/// Register and manage metrics for this filter
pub(super) struct Metrics {
pub(super) packets_dropped_no_token_found: GenericCounter<AtomicI64>,
pub(super) packets_dropped_invalid_token: GenericCounter<AtomicI64>,
pub(super) packets_dropped_no_endpoint_match: GenericCounter<AtomicI64>,
pub(super) packets_dropped_no_token_found: GenericCounter<AtomicU64>,
pub(super) packets_dropped_invalid_token: GenericCounter<AtomicU64>,
pub(super) packets_dropped_no_endpoint_match: GenericCounter<AtomicU64>,
}

impl Metrics {
Expand Down
4 changes: 2 additions & 2 deletions src/proxy/server/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
*/

use crate::metrics::{opts, CollectorExt};
use prometheus::core::{AtomicI64, GenericCounter};
use prometheus::core::{AtomicU64, GenericCounter};
use prometheus::{IntCounterVec, Registry, Result as MetricsResult};

#[derive(Clone)]
pub struct Metrics {
pub packets_dropped_no_endpoints: GenericCounter<AtomicI64>,
pub packets_dropped_no_endpoints: GenericCounter<AtomicU64>,
}

impl Metrics {
Expand Down
18 changes: 9 additions & 9 deletions src/proxy/sessions/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@
*/

use crate::metrics::{histogram_opts, opts, CollectorExt};
use prometheus::core::{AtomicI64, GenericCounter, GenericGauge};
use prometheus::core::{AtomicI64, AtomicU64, GenericCounter, GenericGauge};
use prometheus::{
Histogram, HistogramVec, IntCounterVec, IntGaugeVec, Registry, Result as MetricsResult,
};

#[derive(Clone)]
pub struct Metrics {
pub active_sessions: GenericGauge<AtomicI64>,
pub sessions_total: GenericCounter<AtomicI64>,
pub rx_bytes_total: GenericCounter<AtomicI64>,
pub tx_bytes_total: GenericCounter<AtomicI64>,
pub rx_packets_total: GenericCounter<AtomicI64>,
pub tx_packets_total: GenericCounter<AtomicI64>,
pub rx_errors_total: GenericCounter<AtomicI64>,
pub tx_errors_total: GenericCounter<AtomicI64>,
pub packets_dropped_total: GenericCounter<AtomicI64>,
pub sessions_total: GenericCounter<AtomicU64>,
pub rx_bytes_total: GenericCounter<AtomicU64>,
pub tx_bytes_total: GenericCounter<AtomicU64>,
pub rx_packets_total: GenericCounter<AtomicU64>,
pub tx_packets_total: GenericCounter<AtomicU64>,
pub rx_errors_total: GenericCounter<AtomicU64>,
pub tx_errors_total: GenericCounter<AtomicU64>,
pub packets_dropped_total: GenericCounter<AtomicU64>,
pub duration_secs: Histogram,
}

Expand Down
4 changes: 2 additions & 2 deletions src/proxy/sessions/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl Session {
error!(log, "Error receiving packet"; "error" => %err);
},
Ok((size, recv_addr)) => {
metrics.rx_bytes_total.inc_by(size as i64);
metrics.rx_bytes_total.inc_by(size as u64);
metrics.rx_packets_total.inc();
Session::process_recv_packet(
&log,
Expand Down Expand Up @@ -263,7 +263,7 @@ impl Session {
.await
.map(|size| {
self.metrics.tx_packets_total.inc();
self.metrics.tx_bytes_total.inc_by(size as i64);
self.metrics.tx_bytes_total.inc_by(size as u64);
Some(size)
})
.map_err(|err| {
Expand Down
6 changes: 3 additions & 3 deletions src/xds/ads_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use crate::xds::envoy::service::discovery::v3::{
use crate::xds::listener::ListenerManager;
use crate::xds::metrics::Metrics;
use crate::xds::{CLUSTER_TYPE, ENDPOINT_TYPE, LISTENER_TYPE};
use prometheus::core::{AtomicI64, GenericGauge};
use prometheus::core::{AtomicU64, GenericGauge};
use tokio::sync::mpsc::error::SendError;

/// AdsClient is a client that can talk to an XDS server using the ADS protocol.
Expand Down Expand Up @@ -361,9 +361,9 @@ impl AdsClient {
// This updates metrics for connection state. It updates the metric to 1 upon
// creation and back to 0 once it goes out of scope (i.e when the function returns,
// we are no longer connected since the client must have been dropped as well).
struct ConnectionState(GenericGauge<AtomicI64>);
struct ConnectionState(GenericGauge<AtomicU64>);
impl ConnectionState {
fn connected(metric: GenericGauge<AtomicI64>) -> Self {
fn connected(metric: GenericGauge<AtomicU64>) -> Self {
metric.set(1);
Self(metric)
}
Expand Down
12 changes: 6 additions & 6 deletions src/xds/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
*/

use crate::metrics::{opts, CollectorExt};
use prometheus::core::{AtomicI64, GenericCounter, GenericGauge};
use prometheus::core::{AtomicU64, GenericCounter, GenericGauge};
use prometheus::Result as MetricsResult;
use prometheus::{IntCounter, Registry};

#[derive(Clone)]
pub struct Metrics {
pub connected_state: GenericGauge<AtomicI64>,
pub update_attempt_total: GenericCounter<AtomicI64>,
pub update_success_total: GenericCounter<AtomicI64>,
pub update_failure_total: GenericCounter<AtomicI64>,
pub requests_total: GenericCounter<AtomicI64>,
pub connected_state: GenericGauge<AtomicU64>,
pub update_attempt_total: GenericCounter<AtomicU64>,
pub update_success_total: GenericCounter<AtomicU64>,
pub update_failure_total: GenericCounter<AtomicU64>,
pub requests_total: GenericCounter<AtomicU64>,
}

impl Metrics {
Expand Down

0 comments on commit 57dd4b6

Please sign in to comment.