Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Billing compute cost from unit price config value #171

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ comfy-table = "7.1.1"
csv = "1.3.0"
handlebars = "6.1.0"
slack-hook = "0.8.0"
include_dir = "0.7.4"

[dev-dependencies]
mockall = "0.12.1"
Expand Down
18 changes: 18 additions & 0 deletions bootstrap/rpc/crds/blockfrostport.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
{
"cost": {
"0": {
"minimum": 0,
"delta": 0
},
"1": {
"minimum": 0,
"delta": 0.0000006
},
"2": {
"minimum": 30,
"delta": 0.0000005
},
"3": {
"minimum": 80,
"delta": 0.0000004
}
},
"options": [
{
"description": "mainnet",
Expand Down
18 changes: 18 additions & 0 deletions bootstrap/rpc/crds/cardanonodeport.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
{
"cost": {
"0": {
"minimum": 0,
"delta": 0
},
"1": {
"minimum": 0,
"delta": 0.000013889
},
"2": {
"minimum": 100,
"delta": 0.00000463
},
"3": {
"minimum": 200,
"delta": 0.000003472
}
},
"options": [
{
"description": "mainnet - stable (9.1.1)",
Expand Down
18 changes: 18 additions & 0 deletions bootstrap/rpc/crds/dbsyncport.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
{
"cost": {
"0": {
"minimum": 0,
"delta": 0
},
"1": {
"minimum": 0,
"delta": 0.000007407
},
"2": {
"minimum": 100,
"delta": 0.000006713
},
"3": {
"minimum": 300,
"delta": 0.000005556
}
},
"options": [
{
"description": "mainnet",
Expand Down
1 change: 1 addition & 0 deletions bootstrap/rpc/crds/frontends.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"cost": {},
"options": [],
"crd": {
"apiVersion": "apiextensions.k8s.io/v1",
Expand Down
18 changes: 18 additions & 0 deletions bootstrap/rpc/crds/kupoport.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
{
"cost": {
"0": {
"minimum": 0,
"delta": 0
},
"1": {
"minimum": 0,
"delta": 0.0000009
},
"2": {
"minimum": 50,
"delta": 0.0000008
},
"3": {
"minimum": 150,
"delta": 0.0000007
}
},
"options": [
{
"description": "mainnet",
Expand Down
1 change: 1 addition & 0 deletions bootstrap/rpc/crds/marloweport.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"cost": {},
"options": [
{
"description": "mainnet - patch6 (0.0.7)",
Expand Down
1 change: 1 addition & 0 deletions bootstrap/rpc/crds/mumakport.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"cost": {},
"options": [
{
"description": "mainnet",
Expand Down
18 changes: 18 additions & 0 deletions bootstrap/rpc/crds/ogmiosport.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
{
"cost": {
"0": {
"minimum": 0,
"delta": 0
},
"1": {
"minimum": 0,
"delta": 0.000002662
},
"2": {
"minimum": 100,
"delta": 0.000002315
},
"3": {
"minimum": 200,
"delta": 0.000001968
}
},
"options": [
{
"description": "mainnet",
Expand Down
1 change: 1 addition & 0 deletions bootstrap/rpc/crds/scrollsport.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"cost": {},
"options": [
{
"description": "mainnet",
Expand Down
18 changes: 18 additions & 0 deletions bootstrap/rpc/crds/submitapiport.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
{
"cost": {
"0": {
"minimum": 0,
"delta": 0
},
"1": {
"minimum": 0,
"delta": 0.000004
},
"2": {
"minimum": 200,
"delta": 0.0000036
},
"3": {
"minimum": 400,
"delta": 0.000003
}
},
"options": [
{
"description": "mainnet",
Expand Down
1 change: 1 addition & 0 deletions bootstrap/rpc/crds/utxorpcport.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"cost": {},
"options": [
{
"description": "mainnet",
Expand Down
2 changes: 1 addition & 1 deletion src/domain/metadata/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::Arc;
use super::{MetadataDriven, ResourceMetadata, Result};

pub async fn fetch(metadata: Arc<dyn MetadataDriven>) -> Result<Vec<ResourceMetadata>> {
metadata.find().await
metadata.find()
}

#[cfg(test)]
Expand Down
19 changes: 11 additions & 8 deletions src/domain/metadata/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::str::FromStr;
use std::{collections::HashMap, str::FromStr};

use k8s_openapi::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceDefinition;
use serde::{Deserialize, Serialize};
Expand All @@ -8,10 +8,9 @@ use super::{error::Error, Result};
pub mod command;

#[cfg_attr(test, mockall::automock)]
#[async_trait::async_trait]
pub trait MetadataDriven: Send + Sync {
async fn find(&self) -> Result<Vec<ResourceMetadata>>;
async fn find_by_kind(&self, kind: &str) -> Result<Option<ResourceMetadata>>;
fn find(&self) -> Result<Vec<ResourceMetadata>>;
fn find_by_kind(&self, kind: &str) -> Result<Option<ResourceMetadata>>;
fn render_hbs(&self, name: &str, spec: &str) -> Result<String>;
}

Expand All @@ -33,8 +32,15 @@ impl FromStr for KnownField {
}
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ResourceMetadataCost {
pub minimum: f64,
pub delta: f64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ResourceMetadata {
pub cost: HashMap<String, ResourceMetadataCost>,
pub options: serde_json::Value,
pub crd: CustomResourceDefinition,
}
Expand All @@ -50,10 +56,7 @@ pub mod tests {

impl Default for ResourceMetadata {
fn default() -> Self {
Self {
crd: serde_json::from_str(CARDANO_NODE_PORT_CRD).unwrap(),
options: serde_json::Value::default(),
}
serde_json::from_str(CARDANO_NODE_PORT_CRD).unwrap()
}
}
}
2 changes: 1 addition & 1 deletion src/domain/resource/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub async fn create(
return Err(Error::Unexpected("invalid random name, try again".into()));
}

let Some(metadata) = metadata.find_by_kind(&cmd.kind).await? else {
let Some(metadata) = metadata.find_by_kind(&cmd.kind)? else {
return Err(Error::CommandMalformed("kind not supported".into()));
};

Expand Down
6 changes: 3 additions & 3 deletions src/domain/usage/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::sync::Arc;

use crate::domain::{event::UsageCreated, Result};

use super::{Usage, UsageReport, UsageReportAggregated, UsageResource};
use super::{Usage, UsageReport, UsageResource};

#[cfg_attr(test, mockall::automock)]
#[async_trait::async_trait]
Expand All @@ -13,7 +13,7 @@ pub trait UsageDrivenCache: Send + Sync {
page: &u32,
page_size: &u32,
) -> Result<Vec<UsageReport>>;
async fn find_report_aggregated(&self, period: &str) -> Result<Vec<UsageReportAggregated>>;
async fn find_report_aggregated(&self, period: &str) -> Result<Vec<UsageReport>>;
async fn find_resouces(&self) -> Result<Vec<UsageResource>>;
async fn create(&self, usage: Vec<Usage>) -> Result<()>;
}
Expand All @@ -25,7 +25,7 @@ pub async fn create(cache: Arc<dyn UsageDrivenCache>, evt: UsageCreated) -> Resu
pub async fn find_report_aggregated(
cache: Arc<dyn UsageDrivenCache>,
period: &str,
) -> Result<Vec<UsageReportAggregated>> {
) -> Result<Vec<UsageReport>> {
cache.find_report_aggregated(period).await
}

Expand Down
Loading
Loading