-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Collator protocol followup #1741
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,13 +53,28 @@ enum Error { | |
| RuntimeApi(RuntimeApiError), | ||
| #[from] | ||
| UtilError(util::Error), | ||
| #[from] | ||
| Prometheus(prometheus::PrometheusError), | ||
| } | ||
|
|
||
| type Result<T> = std::result::Result<T, Error>; | ||
|
|
||
| enum ProtocolSide { | ||
| Validator, | ||
| Collator(CollatorId), | ||
| Validator(validator_side::Metrics), | ||
| Collator(CollatorId, collator_side::Metrics), | ||
| } | ||
|
|
||
| /// Metrics. | ||
| #[derive(Clone, Default)] | ||
| pub struct Metrics; | ||
|
|
||
| // TODO: So how do we tie this to metrics in modules?. | ||
montekki marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| impl metrics::Metrics for Metrics { | ||
| fn try_register(_registry: &prometheus::Registry) | ||
| -> std::result::Result<Self, prometheus::PrometheusError> | ||
| { | ||
| Ok(Self) | ||
| } | ||
| } | ||
|
|
||
| /// The collator protocol subsystem. | ||
|
|
@@ -71,39 +86,39 @@ impl CollatorProtocolSubsystem { | |
| /// Start the collator protocol. | ||
| /// If `id` is `Some` this is a collator side of the protocol. | ||
| /// If `id` is `None` this is a validator side of the protocol. | ||
| pub fn new(id: Option<CollatorId>) -> Self { | ||
| /// Caller must provide a registry for prometheus metrics. | ||
| pub fn new(id: Option<CollatorId>, registry: &prometheus::Registry) | ||
|
||
| -> std::result::Result<Self, prometheus::PrometheusError> { | ||
| use metrics::Metrics; | ||
| let protocol_side = match id { | ||
| Some(id) => ProtocolSide::Collator(id), | ||
| None => ProtocolSide::Validator, | ||
| Some(id) => ProtocolSide::Collator(id, collator_side::Metrics::try_register(registry)?), | ||
| None => ProtocolSide::Validator(validator_side::Metrics::try_register(registry)?), | ||
| }; | ||
|
|
||
| Self { | ||
| Ok(Self { | ||
| protocol_side, | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| async fn run<Context>(self, ctx: Context) -> Result<()> | ||
| where | ||
| Context: SubsystemContext<Message = CollatorProtocolMessage>, | ||
| { | ||
| match self.protocol_side { | ||
| ProtocolSide::Validator => validator_side::run(ctx, REQUEST_TIMEOUT).await, | ||
| ProtocolSide::Collator(id) => collator_side::run(ctx, id).await, | ||
| ProtocolSide::Validator(metrics) => validator_side::run( | ||
| ctx, | ||
| REQUEST_TIMEOUT, | ||
| metrics, | ||
| ).await, | ||
| ProtocolSide::Collator(id, metrics) => collator_side::run( | ||
| ctx, | ||
| id, | ||
| metrics, | ||
| ).await, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Collator protocol metrics. | ||
| #[derive(Default, Clone)] | ||
| pub struct Metrics; | ||
|
|
||
| impl metrics::Metrics for Metrics { | ||
| fn try_register(_registry: &prometheus::Registry) | ||
| -> std::result::Result<Self, prometheus::PrometheusError> { | ||
| Ok(Metrics) | ||
| } | ||
| } | ||
|
|
||
| impl<Context> Subsystem<Context> for CollatorProtocolSubsystem | ||
| where | ||
| Context: SubsystemContext<Message = CollatorProtocolMessage> + Sync + Send, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.