Skip to content
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
11 changes: 0 additions & 11 deletions bootstrap/feature/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,6 @@ variable "metrics_delay" {
default = "30"
}

variable "dcu_per_request" {
type = map(string)
default = {
"mainnet" = "10"
"preprod" = "5"
"preview" = "5"
"sanchonet" = "5"
"vector-testnet" = "5"
}
}

variable "resources" {
type = object({
limits = object({
Expand Down
5 changes: 0 additions & 5 deletions bootstrap/feature/operator.tf
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ resource "kubernetes_deployment_v1" "operator" {
value = var.metrics_delay
}

env {
name = "DCU_PER_REQUEST"
value = "mainnet=${var.dcu_per_request["mainnet"]},preprod=${var.dcu_per_request["preprod"]},preview=${var.dcu_per_request["preview"]},vector-testnet=${var.dcu_per_request["vector-testnet"]}"
}

env {
name = "DEFAULT_SUBMITAPI_VERSION"
value = "stable"
Expand Down
1 change: 0 additions & 1 deletion bootstrap/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ module "submitapi_v1_feature" {
ingress_class = var.ingress_class
dns_zone = var.dns_zone
api_key_salt = var.api_key_salt
dcu_per_request = var.dcu_per_request
resources = var.operator_resources
}

Expand Down
11 changes: 0 additions & 11 deletions bootstrap/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,6 @@ variable "api_key_salt" {
type = string
}

variable "dcu_per_request" {
type = map(string)
default = {
"mainnet" = "10"
"preprod" = "5"
"preview" = "5"
"sanchonet" = "5"
"vector-testnet" = "5"
}
}

variable "metrics_delay" {
type = number
default = 60
Expand Down
1 change: 0 additions & 1 deletion operator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ This operator will create a key into the CRD to allow SubmitApi to be accessed e
| API_KEY_SALT | submitapi-salt |
| METRICS_DELAY | 40 |
| PROMETHEUS_URL | |
| DCU_PER_REQUEST | preview=5,preprod=5,mainnet=5 |
| DEFAULT_SUBMITAPI_VERSION | v3 |

## Port CRD
Expand Down
15 changes: 1 addition & 14 deletions operator/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use lazy_static::lazy_static;
use std::{collections::HashMap, env, time::Duration};
use std::{env, time::Duration};

lazy_static! {
static ref CONTROLLER_CONFIG: Config = Config::from_env();
Expand All @@ -16,7 +16,6 @@ pub struct Config {
pub api_key_salt: String,
pub metrics_delay: Duration,
pub prometheus_url: String,
pub dcu_per_request: HashMap<String, f64>,
pub default_submitapi_version: String,
}

Expand All @@ -33,18 +32,6 @@ impl Config {
.expect("METRICS_DELAY must be a number"),
),
prometheus_url: env::var("PROMETHEUS_URL").expect("PROMETHEUS_URL must be set"),
dcu_per_request: env::var("DCU_PER_REQUEST")
.expect("DCU_PER_REQUEST must be set")
.split(',')
.map(|pair| {
let parts: Vec<&str> = pair.split('=').collect();
let dcu = parts[1]
.parse::<f64>()
.expect("DCU_PER_REQUEST must be NETWORK=NUMBER");

(parts[0].into(), dcu)
})
.collect(),
default_submitapi_version: env::var("DEFAULT_SUBMITAPI_VERSION").unwrap_or("v3".into()),
}
}
Expand Down
42 changes: 1 addition & 41 deletions operator/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,13 @@ use crate::{get_config, Error, State, SubmitApiPort};

#[derive(Clone)]
pub struct Metrics {
pub dcu: IntCounterVec,
pub usage: IntCounterVec,
pub reconcile_failures: IntCounterVec,
pub metrics_failures: IntCounterVec,
}

impl Default for Metrics {
fn default() -> Self {
let dcu = IntCounterVec::new(
opts!("dmtr_consumed_dcus", "quantity of dcu consumed",),
&["project", "service", "service_type", "tenancy"],
)
.unwrap();

let usage = IntCounterVec::new(
opts!("usage", "Feature usage",),
&["feature", "project", "resource_name", "tier"],
Expand All @@ -53,7 +46,6 @@ impl Default for Metrics {
.unwrap();

Metrics {
dcu,
usage,
reconcile_failures,
metrics_failures,
Expand All @@ -65,7 +57,6 @@ impl Metrics {
pub fn register(self, registry: &Registry) -> Result<Self, prometheus::Error> {
registry.register(Box::new(self.reconcile_failures.clone()))?;
registry.register(Box::new(self.metrics_failures.clone()))?;
registry.register(Box::new(self.dcu.clone()))?;
registry.register(Box::new(self.usage.clone()))?;

Ok(self)
Expand All @@ -83,22 +74,6 @@ impl Metrics {
.inc()
}

pub fn count_dcu_consumed(&self, project: &str, network: &str, dcu: f64) {
let service = format!("{}-{}", SubmitApiPort::kind(&()), network);
let service_type = format!(
"{}.{}",
SubmitApiPort::plural(&()),
SubmitApiPort::group(&())
);
let tenancy = "proxy";

let dcu: u64 = dcu.ceil() as u64;

self.dcu
.with_label_values(&[project, &service, &service_type, tenancy])
.inc_by(dcu);
}

pub fn count_usage(&self, project: &str, resource_name: &str, tier: &str, value: f64) {
let feature = &SubmitApiPort::kind(&());
let value: u64 = value.ceil() as u64;
Expand Down Expand Up @@ -175,26 +150,11 @@ pub fn run_metrics_collector(state: Arc<State>) {
let project = project_captures.get(1).unwrap().as_str();
let resource_name = project_captures.get(2).unwrap().as_str();

let network = result.metric.network.unwrap();
let tier = result.metric.tier.unwrap();

let dcu_per_request = config.dcu_per_request.get(&network);
if dcu_per_request.is_none() {
let error = Error::ConfigError(format!(
"dcu_per_request not configured to {} network",
network
));
error!(error = error.to_string());
state.metrics.metrics_failure(&error);
continue;
}
let dcu_per_request = dcu_per_request.unwrap();

let dcu = result.value * dcu_per_request;
state.metrics.count_dcu_consumed(project, &network, dcu);
state
.metrics
.count_usage(project, resource_name, &tier, dcu);
.count_usage(project, resource_name, &tier, result.value);
}
}
});
Expand Down