Skip to content

Commit

Permalink
ref(processor): Add PartialDsn ctor for outbound requests (#2808)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dav1dde authored Dec 1, 2023
1 parent 8a75b10 commit a0c44d5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 24 deletions.
9 changes: 1 addition & 8 deletions relay-server/src/actors/envelopes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,14 +311,7 @@ impl EnvelopeManagerService {
} = message;

let upstream = self.config.upstream_descriptor();
let dsn = PartialDsn {
scheme: upstream.scheme(),
public_key: scoping.project_key,
host: upstream.host().to_owned(),
port: upstream.port(),
path: "".to_owned(),
project_id: Some(scoping.project_id),
};
let dsn = PartialDsn::outbound(&scoping, upstream);

let mut envelope = Envelope::from_request(None, RequestMeta::outbound(dsn));
for client_report in client_reports {
Expand Down
19 changes: 3 additions & 16 deletions relay-server/src/actors/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1505,14 +1505,8 @@ impl EnvelopeProcessorService {
let max_batch_size_bytes = self.inner.config.metrics_max_batch_size_bytes();

let upstream = self.inner.config.upstream_descriptor();
let dsn = PartialDsn {
scheme: upstream.scheme(),
public_key: scoping.project_key,
host: upstream.host().to_owned(),
port: upstream.port(),
path: "".to_owned(),
project_id: Some(scoping.project_id),
};
let dsn = PartialDsn::outbound(&scoping, upstream);

for (partition_key, buckets) in partition_buckets(scoping.project_key, buckets, partitions)
{
let mut num_batches = 0;
Expand Down Expand Up @@ -1556,14 +1550,7 @@ impl EnvelopeProcessorService {
let EncodeMetricMeta { scoping, meta } = message;

let upstream = self.inner.config.upstream_descriptor();
let dsn = crate::extractors::PartialDsn {
scheme: upstream.scheme(),
public_key: scoping.project_key,
host: upstream.host().to_owned(),
port: upstream.port(),
path: "".to_owned(),
project_id: Some(scoping.project_id),
};
let dsn = PartialDsn::outbound(&scoping, upstream);

let mut item = Item::new(ItemType::MetricMeta);
item.set_payload(ContentType::Json, serde_json::to_vec(&meta).unwrap());
Expand Down
13 changes: 13 additions & 0 deletions relay-server/src/extractors/request_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use axum::RequestPartsExt;
use data_encoding::BASE64;
use relay_base_schema::project::{ParseProjectKeyError, ProjectId, ProjectKey};
use relay_common::{Auth, Dsn, ParseAuthError, ParseDsnError, Scheme};
use relay_config::UpstreamDescriptor;
use relay_event_normalization::{ClientHints, RawUserAgentInfo};
use relay_quotas::Scoping;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -112,6 +113,18 @@ impl PartialDsn {
})
}

/// Creates a new [`PartialDsn`] for a Relay outbound request.
pub fn outbound(scoping: &Scoping, upstream: &UpstreamDescriptor<'_>) -> Self {
Self {
scheme: upstream.scheme(),
public_key: scoping.project_key,
host: upstream.host().to_owned(),
port: upstream.port(),
path: "".to_owned(),
project_id: Some(scoping.project_id),
}
}

/// Returns the project identifier that the DSN points to.
pub fn project_id(&self) -> Option<ProjectId> {
self.project_id
Expand Down

0 comments on commit a0c44d5

Please sign in to comment.