Skip to content

Commit

Permalink
tweaks to accommodate updated proto
Browse files Browse the repository at this point in the history
  • Loading branch information
andymck committed Nov 6, 2024
1 parent f086c18 commit 0698241
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 22 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

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

36 changes: 32 additions & 4 deletions file_store/src/usage_counts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ pub struct HexUsageCountsReq {
pub service_provider_subscriber_avg_count: u64,
pub disco_mapping_avg_count: u64,
pub offload_avg_count: u64,
pub epoch_start_timestamp: DateTime<Utc>,
pub epoch_end_timestamp: DateTime<Utc>,
pub timestamp: DateTime<Utc>,
pub carrier_mapping_key: PublicKeyBinary,
}
Expand All @@ -31,6 +33,10 @@ pub struct RadioUsageCountsReq {
pub service_provider_subscriber_avg_count: u64,
pub disco_mapping_avg_count: u64,
pub offload_avg_count: u64,
pub service_provider_transfer_bytes: u64,
pub offload_transfer_bytes: u64,
pub epoch_start_timestamp: DateTime<Utc>,
pub epoch_end_timestamp: DateTime<Utc>,
pub timestamp: DateTime<Utc>,
pub carrier_mapping_key: PublicKeyBinary,
}
Expand All @@ -45,32 +51,34 @@ impl MsgDecode for RadioUsageCountsReq {

impl MsgTimestamp<Result<DateTime<Utc>>> for HexUsageCountsReqV1 {
fn timestamp(&self) -> Result<DateTime<Utc>> {
self.timestamp.to_timestamp()
self.timestamp.to_timestamp_millis()
}
}

impl MsgTimestamp<u64> for HexUsageCountsReq {
fn timestamp(&self) -> u64 {
self.timestamp.encode_timestamp()
self.timestamp.encode_timestamp_millis()
}
}

impl MsgTimestamp<Result<DateTime<Utc>>> for RadioUsageCountsReqV1 {
fn timestamp(&self) -> Result<DateTime<Utc>> {
self.timestamp.to_timestamp()
self.timestamp.to_timestamp_millis()
}
}

impl MsgTimestamp<u64> for RadioUsageCountsReq {
fn timestamp(&self) -> u64 {
self.timestamp.encode_timestamp()
self.timestamp.encode_timestamp_millis()
}
}

impl TryFrom<HexUsageCountsReqV1> for HexUsageCountsReq {
type Error = Error;
fn try_from(v: HexUsageCountsReqV1) -> Result<Self> {
let timestamp = v.timestamp()?;
let epoch_start_timestamp = v.epoch_start_timestamp.to_timestamp_millis()?;
let epoch_end_timestamp = v.epoch_end_timestamp.to_timestamp_millis()?;
let hex = CellIndex::try_from(v.hex).map_err(|_| {
DecodeError::FileStreamTryDecode(format!("invalid CellIndex {}", v.hex))
})?;
Expand All @@ -79,6 +87,8 @@ impl TryFrom<HexUsageCountsReqV1> for HexUsageCountsReq {
service_provider_subscriber_avg_count: v.service_provider_subscriber_avg_count,
disco_mapping_avg_count: v.disco_mapping_avg_count,
offload_avg_count: v.offload_avg_count,
epoch_start_timestamp,
epoch_end_timestamp,
timestamp,
carrier_mapping_key: v.carrier_mapping_key.into(),
})
Expand All @@ -88,11 +98,16 @@ impl TryFrom<HexUsageCountsReqV1> for HexUsageCountsReq {
impl From<HexUsageCountsReq> for HexUsageCountsReqV1 {
fn from(v: HexUsageCountsReq) -> Self {
let timestamp = v.timestamp();
let epoch_start_timestamp = v.epoch_start_timestamp.encode_timestamp_millis();
let epoch_end_timestamp = v.epoch_end_timestamp.encode_timestamp_millis();

HexUsageCountsReqV1 {
hex: v.hex.into(),
service_provider_subscriber_avg_count: v.service_provider_subscriber_avg_count,
disco_mapping_avg_count: v.disco_mapping_avg_count,
offload_avg_count: v.offload_avg_count,
epoch_start_timestamp,
epoch_end_timestamp,
timestamp,
carrier_mapping_key: v.carrier_mapping_key.into(),
signature: vec![],
Expand All @@ -104,12 +119,18 @@ impl TryFrom<RadioUsageCountsReqV1> for RadioUsageCountsReq {
type Error = Error;
fn try_from(v: RadioUsageCountsReqV1) -> Result<Self> {
let timestamp = v.timestamp()?;
let epoch_start_timestamp = v.epoch_start_timestamp.to_timestamp_millis()?;
let epoch_end_timestamp = v.epoch_end_timestamp.to_timestamp_millis()?;
Ok(Self {
hotspot_pubkey: v.hotspot_pubkey.into(),
cbsd_id: v.cbsd_id,
service_provider_subscriber_avg_count: v.service_provider_subscriber_avg_count,
disco_mapping_avg_count: v.disco_mapping_avg_count,
offload_avg_count: v.offload_avg_count,
service_provider_transfer_bytes: v.service_provider_transfer_bytes,
offload_transfer_bytes: v.offload_transfer_bytes,
epoch_start_timestamp,
epoch_end_timestamp,
timestamp,
carrier_mapping_key: v.carrier_mapping_key.into(),
})
Expand All @@ -119,12 +140,19 @@ impl TryFrom<RadioUsageCountsReqV1> for RadioUsageCountsReq {
impl From<RadioUsageCountsReq> for RadioUsageCountsReqV1 {
fn from(v: RadioUsageCountsReq) -> Self {
let timestamp = v.timestamp();
let epoch_start_timestamp = v.epoch_start_timestamp.encode_timestamp_millis();
let epoch_end_timestamp = v.epoch_end_timestamp.encode_timestamp_millis();

RadioUsageCountsReqV1 {
hotspot_pubkey: v.hotspot_pubkey.into(),
cbsd_id: v.cbsd_id,
service_provider_subscriber_avg_count: v.service_provider_subscriber_avg_count,
disco_mapping_avg_count: v.disco_mapping_avg_count,
offload_avg_count: v.offload_avg_count,
service_provider_transfer_bytes: v.service_provider_transfer_bytes,
offload_transfer_bytes: v.offload_transfer_bytes,
epoch_start_timestamp,
epoch_end_timestamp,
timestamp,
carrier_mapping_key: v.carrier_mapping_key.into(),
signature: vec![],
Expand Down
6 changes: 0 additions & 6 deletions ingest/src/server_mobile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,9 @@ use helium_proto::services::poc_mobile::{
DataTransferSessionIngestReportV1, DataTransferSessionReqV1, DataTransferSessionRespV1,
HexUsageCountsIngestReportV1, HexUsageCountsReqV1, HexUsageCountsResV1,
InvalidatedRadioThresholdIngestReportV1, InvalidatedRadioThresholdReportReqV1,
<<<<<<< HEAD
InvalidatedRadioThresholdReportRespV1, RadioThresholdIngestReportV1, RadioThresholdReportReqV1,
RadioThresholdReportRespV1, ServiceProviderBoostedRewardsBannedRadioIngestReportV1,
=======
InvalidatedRadioThresholdReportRespV1, PromotionRewardIngestReportV1, PromotionRewardReqV1,
PromotionRewardRespV1, RadioThresholdIngestReportV1, RadioThresholdReportReqV1,
RadioThresholdReportRespV1, RadioUsageCountsIngestReportV1, RadioUsageCountsReqV1,
RadioUsageCountsResV1, ServiceProviderBoostedRewardsBannedRadioIngestReportV1,
>>>>>>> 492d7e05 (support hex and hotspot usage reports at filestore and ingestor)
ServiceProviderBoostedRewardsBannedRadioReqV1, ServiceProviderBoostedRewardsBannedRadioRespV1,
SpeedtestIngestReportV1, SpeedtestReqV1, SpeedtestRespV1, SubscriberLocationIngestReportV1,
SubscriberLocationReqV1, SubscriberLocationRespV1,
Expand Down
9 changes: 9 additions & 0 deletions ingest/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ impl TestClient {
service_provider_subscriber_avg_count,
disco_mapping_avg_count,
offload_avg_count,
epoch_start_timestamp: 0,
epoch_end_timestamp: 0,
timestamp: 0,
carrier_mapping_key: self.key_pair.public_key().to_vec(),
signature: vec![],
Expand All @@ -266,20 +268,27 @@ impl TestClient {
Ok(res.into_inner())
}

#[allow(clippy::too_many_arguments)]
pub async fn submit_radio_usage_req(
&mut self,
hotspot_pubkey: PublicKeyBinary,
cbsd_id: String,
service_provider_subscriber_avg_count: u64,
disco_mapping_avg_count: u64,
offload_avg_count: u64,
service_provider_transfer_bytes: u64,
offload_transfer_bytes: u64,
) -> anyhow::Result<RadioUsageCountsResV1> {
let mut req = RadioUsageCountsReqV1 {
hotspot_pubkey: hotspot_pubkey.into(),
cbsd_id,
service_provider_subscriber_avg_count,
disco_mapping_avg_count,
offload_avg_count,
service_provider_transfer_bytes,
offload_transfer_bytes,
epoch_start_timestamp: 0,
epoch_end_timestamp: 0,
timestamp: 0,
carrier_mapping_key: self.key_pair.public_key().to_vec(),
signature: vec![],
Expand Down
27 changes: 18 additions & 9 deletions ingest/tests/mobile_ingest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,21 @@ async fn submit_radio_usage_report() -> anyhow::Result<()> {

let hotspot_pubkey = PublicKeyBinary::from_str(PUBKEY1)?;
let cbsd_id = "cbsd_id".to_string();
const SERVICE_PROVIDER_SUBSCRIBER_AVG_COUNT: u64 = 10;
const DISCO_MAPPING_AVG_COUNT: u64 = 11;
const OFFLOAD_AVG_COUNT: u64 = 12;
const SERVICE_PROVIDER_SUBSCRIBER_COUNT: u64 = 10;
const DISCO_MAPPING_COUNT: u64 = 11;
const OFFLOAD_COUNT: u64 = 12;
const SERVICE_PROVIDER_TRANSFER_BYTES: u64 = 13;
const OFFLOAD_TRANSFER_BYTES: u64 = 14;

let res = client
.submit_radio_usage_req(
hotspot_pubkey.clone(),
cbsd_id.clone(),
SERVICE_PROVIDER_SUBSCRIBER_AVG_COUNT,
DISCO_MAPPING_AVG_COUNT,
OFFLOAD_AVG_COUNT,
SERVICE_PROVIDER_SUBSCRIBER_COUNT,
DISCO_MAPPING_COUNT,
OFFLOAD_COUNT,
SERVICE_PROVIDER_TRANSFER_BYTES,
OFFLOAD_TRANSFER_BYTES,
)
.await;

Expand All @@ -119,11 +123,16 @@ async fn submit_radio_usage_report() -> anyhow::Result<()> {
assert_eq!(hotspot_pubkey.as_ref(), event.hotspot_pubkey);
assert_eq!(cbsd_id, event.cbsd_id);
assert_eq!(
SERVICE_PROVIDER_SUBSCRIBER_AVG_COUNT,
SERVICE_PROVIDER_SUBSCRIBER_COUNT,
event.service_provider_subscriber_avg_count
);
assert_eq!(DISCO_MAPPING_AVG_COUNT, event.disco_mapping_avg_count);
assert_eq!(OFFLOAD_AVG_COUNT, event.offload_avg_count);
assert_eq!(DISCO_MAPPING_COUNT, event.disco_mapping_avg_count);
assert_eq!(OFFLOAD_COUNT, event.offload_avg_count);
assert_eq!(
SERVICE_PROVIDER_TRANSFER_BYTES,
event.service_provider_transfer_bytes
);
assert_eq!(OFFLOAD_TRANSFER_BYTES, event.offload_transfer_bytes);
}
}
}
Expand Down

0 comments on commit 0698241

Please sign in to comment.