Skip to content

Commit

Permalink
Add object_totals to Overview
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelklishin committed Jan 6, 2025
1 parent 816e1b3 commit 879e99d
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 110 deletions.
113 changes: 111 additions & 2 deletions src/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,125 @@
// 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.
use crate::responses::{TagList, TagMap, XArguments};
use crate::responses::*;
use serde_json::Map;
use std::fmt;
use std::fmt::Display;

impl fmt::Display for TagList {
impl Display for ObjectTotals {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, "connections: {}", self.connections)?;
writeln!(f, "channels: {}", self.channels)?;
writeln!(f, "queues: {}", self.queues)?;
writeln!(f, "exchanges: {}", self.exchanges)?;

Ok(())
}
}

impl Display for TagList {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt_comma_separated_list(f, &self.0)
}
}

impl Display for TagMap {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt_map_as_colon_separated_pairs(f, &self.0)
}
}

impl Display for DeprecatedFeatureList {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
for df in &self.0 {
writeln!(f, "{}", df)?;
}

Ok(())
}
}

impl Display for DeprecatedFeature {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, "name: {}", self.name)?;
writeln!(f, "description: {}", self.description)?;
writeln!(f, "deprecation_phase: {}", self.deprecation_phase)?;

Ok(())
}
}

impl Display for PluginList {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt_vertical_list_with_bullets(f, &self.0)
}
}

impl Display for XArguments {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt_map_as_colon_separated_pairs(f, &self.0)
}
}

impl Display for FeatureFlag {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, "name: {}", self.name)?;
writeln!(f, "description: {}", self.description)?;
writeln!(f, "doc URL: {}", self.doc_url)?;
writeln!(f, "stability: {}", self.stability)?;
writeln!(f, "provided by: {}", self.provided_by)?;

Ok(())
}
}

impl Display for FeatureFlagList {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
for ff in &self.0 {
writeln!(f, "{}", ff)?;
}

Ok(())
}
}

impl Display for MessageList {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
for msg in &self.0 {
writeln!(f, "{}", msg)?;
}

Ok(())
}
}

impl Display for MessageRouted {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self.routed {
true => write!(f, "Message published and routed successfully"),
false => write!(f, "Message published but NOT routed"),
}
}
}

impl Display for MessageProperties {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt_map_as_colon_separated_pairs(f, &self.0)
}
}

impl Display for GetMessage {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, "payload: {}", self.payload)?;
writeln!(f, "exchange: {}", self.exchange)?;
writeln!(f, "routing key: {}", self.routing_key)?;
writeln!(f, "redelivered: {}", self.redelivered)?;
writeln!(f, "properties: {}", self.properties)?;

Ok(())
}
}

#[allow(dead_code)]
pub fn fmt_list_as_json_array(f: &mut fmt::Formatter<'_>, xs: &[String]) -> fmt::Result {
match xs.len() {
Expand Down
110 changes: 2 additions & 108 deletions src/responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
// 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.
use core::fmt::Display;
use std::{fmt, ops};

use crate::commons::{BindingDestinationType, PolicyTarget};
Expand All @@ -35,21 +34,9 @@ pub struct TagList(pub Vec<String>);
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct PluginList(pub Vec<String>);

impl fmt::Display for PluginList {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt_vertical_list_with_bullets(f, &self.0)
}
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct XArguments(pub Map<String, serde_json::Value>);

impl fmt::Display for XArguments {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt_map_as_colon_separated_pairs(f, &self.0)
}
}

#[derive(Debug, Deserialize, Clone)]
#[cfg_attr(feature = "tabled", derive(Tabled))]
#[allow(dead_code)]
Expand Down Expand Up @@ -954,57 +941,20 @@ pub struct GetMessage {
pub payload_encoding: String,
}

impl Display for GetMessage {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, "payload: {}", self.payload)?;
writeln!(f, "exchange: {}", self.exchange)?;
writeln!(f, "routing key: {}", self.routing_key)?;
writeln!(f, "redelivered: {}", self.redelivered)?;
writeln!(f, "properties: {}", self.properties)?;

Ok(())
}
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(transparent)]
pub struct MessageList(pub Vec<GetMessage>);

impl Display for MessageList {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
for msg in &self.0 {
writeln!(f, "{}", msg)?;
}

Ok(())
}
}

#[derive(Debug, Deserialize, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "tabled", derive(Tabled))]
pub struct MessageRouted {
pub routed: bool,
}

impl Display for MessageRouted {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self.routed {
true => write!(f, "Message published and routed successfully"),
false => write!(f, "Message published but NOT routed"),
}
}
}

#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq, Default)]
#[serde(transparent)]
pub struct MessageProperties(pub Map<String, serde_json::Value>);

impl Display for MessageProperties {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt_map_as_colon_separated_pairs(f, &self.0)
}
}

#[derive(Debug, Deserialize, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "tabled", derive(Tabled))]
pub struct ChurnRates {
Expand Down Expand Up @@ -1037,16 +987,7 @@ pub struct ObjectTotals {
pub channels: u64,
pub queues: u64,
pub exchanges: u64,
}
impl Display for ObjectTotals {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, "connections: {}", self.connections)?;
writeln!(f, "channels: {}", self.channels)?;
writeln!(f, "queues: {}", self.queues)?;
writeln!(f, "exchanges: {}", self.exchanges)?;

Ok(())
}
pub consumers: u64,
}

#[derive(Debug, Deserialize, Clone, Eq, PartialEq)]
Expand All @@ -1063,12 +1004,6 @@ pub struct Listener {
#[serde(transparent)]
pub struct TagMap(pub Map<String, serde_json::Value>);

impl Display for TagMap {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt_map_as_colon_separated_pairs(f, &self.0)
}
}

#[derive(Debug, Deserialize, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "tabled", derive(Tabled))]
pub struct Overview {
Expand All @@ -1089,6 +1024,7 @@ pub struct Overview {

pub statistics_db_event_queue: u64,
pub churn_rates: ChurnRates,
pub object_totals: ObjectTotals,
}

#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
Expand Down Expand Up @@ -1211,32 +1147,10 @@ pub struct FeatureFlag {
pub provided_by: String,
}

impl Display for FeatureFlag {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, "name: {}", self.name)?;
writeln!(f, "description: {}", self.description)?;
writeln!(f, "doc URL: {}", self.doc_url)?;
writeln!(f, "stability: {}", self.stability)?;
writeln!(f, "provided by: {}", self.provided_by)?;

Ok(())
}
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(transparent)]
pub struct FeatureFlagList(pub Vec<FeatureFlag>);

impl Display for FeatureFlagList {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
for ff in &self.0 {
writeln!(f, "{}", ff)?;
}

Ok(())
}
}

#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
#[serde(rename_all = "snake_case")]
pub enum DeprecationPhase {
Expand Down Expand Up @@ -1309,30 +1223,10 @@ pub struct DeprecatedFeature {
pub provided_by: String,
}

impl Display for DeprecatedFeature {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, "name: {}", self.name)?;
writeln!(f, "description: {}", self.description)?;
writeln!(f, "deprecation_phase: {}", self.deprecation_phase)?;

Ok(())
}
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(transparent)]
pub struct DeprecatedFeatureList(pub Vec<DeprecatedFeature>);

impl Display for DeprecatedFeatureList {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
for df in &self.0 {
writeln!(f, "{}", df)?;
}

Ok(())
}
}

fn undefined() -> String {
"?".to_string()
}
Expand Down

0 comments on commit 879e99d

Please sign in to comment.