Skip to content

Commit 0a2abeb

Browse files
committed
First commit
0 parents  commit 0a2abeb

File tree

7 files changed

+728
-0
lines changed

7 files changed

+728
-0
lines changed

.github/workflows/ci.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
---
2+
name: Rust
3+
4+
# yamllint disable-line rule:truthy
5+
on:
6+
push:
7+
branches:
8+
- main
9+
pull_request:
10+
workflow_dispatch:
11+
12+
env:
13+
RUSTFLAGS: -Dwarnings
14+
RUST_BACKTRACE: 1
15+
CARGO_TERM_COLOR: always
16+
17+
permissions:
18+
contents: read
19+
20+
jobs:
21+
clippy:
22+
name: Clippy
23+
runs-on: ubuntu-latest
24+
timeout-minutes: 45
25+
steps:
26+
- uses: actions/checkout@v4
27+
- uses: dtolnay/rust-toolchain@nightly
28+
with:
29+
components: clippy,rustc-dev
30+
- run: >
31+
cargo clippy --color always --verbose
32+
--workspace --all-targets
33+
--all-features --tests
34+
35+
fmt:
36+
name: Rust fmt
37+
runs-on: ubuntu-latest
38+
steps:
39+
- uses: actions/checkout@v4
40+
- uses: dtolnay/rust-toolchain@master
41+
with:
42+
toolchain: stable
43+
components: rustfmt
44+
- run: cargo fmt -- --check
45+
46+
doc:
47+
name: Documentation
48+
runs-on: ubuntu-latest
49+
timeout-minutes: 45
50+
env:
51+
RUSTDOCFLAGS: -Dwarnings
52+
steps:
53+
- uses: actions/checkout@v4
54+
- uses: dtolnay/rust-toolchain@master
55+
with:
56+
toolchain: stable
57+
components: rustfmt
58+
- run: cargo doc --color=always --verbose --no-deps
59+
60+
build:
61+
runs-on: ubuntu-latest
62+
timeout-minutes: 45
63+
steps:
64+
- uses: actions/checkout@v4
65+
- uses: dtolnay/rust-toolchain@master
66+
with:
67+
toolchain: stable
68+
components: rustc-dev
69+
- run: cargo check --benches --all-features --release
70+
71+
test:
72+
name: Tests
73+
needs: build
74+
runs-on: ubuntu-latest
75+
timeout-minutes: 45
76+
steps:
77+
- uses: actions/checkout@v4
78+
- uses: dtolnay/rust-toolchain@nightly
79+
with:
80+
components: llvm-tools, rustc-dev
81+
- run: >
82+
cargo test --all-features --release
83+
--tests --verbose --color always
84+
--workspace --no-fail-fast

.gitignore

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Generated by Cargo
2+
# will have compiled files and executables
3+
debug/
4+
target/
5+
6+
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
7+
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
8+
Cargo.lock
9+
10+
# These are backup files generated by rustfmt
11+
**/*.rs.bk
12+
13+
# MSVC Windows builds of rustc generate these, which store debugging information
14+
*.pdb
15+
16+
# Generated
17+
*.profraw
18+
*.json
19+
*.xml
20+
*.info
21+
*.html
22+
23+
# IDE files
24+
.vscode/*
25+
.history/
26+
.metadata
27+
bin/
28+
tmp/
29+
*.tmp
30+
*.bak
31+
*.swp
32+
*~.nib
33+
local.properties
34+
.settings/
35+
.loadpath
36+
.recommenders
37+
.idea
38+
out/
39+
40+
# OS files
41+
*.DS_Store
42+
43+
# Packages
44+
*.tar
45+
*.tar.gz
46+
*.tar.xz

Cargo.toml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[package]
2+
name = "prosa-fetcher"
3+
version = "0.1.0"
4+
authors = ["Jeremy HERGAULT"]
5+
license = "LGPL-3.0-or-later"
6+
edition = "2024"
7+
description = "ProSA processor to fetch information from remote systems"
8+
9+
[package.metadata.prosa.fetcher]
10+
proc = "proc::FetcherProc"
11+
settings = "proc::FetcherSettings"
12+
13+
[dependencies]
14+
bytes = "1"
15+
prosa = "0.2"
16+
prosa-utils = "0.2"
17+
serde = "1"
18+
tokio = "1"
19+
thiserror = "2"
20+
tracing = "0.1"
21+
url = { version = "2", features = ["serde"] }
22+
base64 = "0.22"
23+
hmac = "0.12"
24+
25+
hyper = { version = "1", features = ["full"] }
26+
http = "1"
27+
http-body-util = "0.1"
28+
hyper-util = { version = "0.1", features = ["full"] }

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# ProSA Fetcher
2+
3+
[ProSA](https://github.com/worldline/ProSA) processor to fetch information from remote systems.
4+
5+
The main goal of this processor is to retrieve metrics periodically from remote systems.
6+
7+
## Configuration
8+
9+
For configuration, you can set either the `target`, or the `service_name` (or both), depending on your fetcher type.
10+
11+
The `target` uses ProSA's [`TargetSetting`](https://docs.rs/prosa/latest/prosa/io/stream/struct.TargetSetting.html) to define all connection information.
12+
If you need to authenticate, you will have to set the user and password in the [url](https://docs.rs/url/latest/url/struct.Url.html#method.password).
13+
14+
If you want to fetch an internal service, you only have to specify its name with `service_name`.
15+
16+
An `auth_method` can also be set (not present in the following example), but generally, the auth method is known by the adaptor and will be set by it.
17+
18+
The last two parameters, `period` and `timeout`, configure the interval between fetches and the timeout for each fetch, respectively.
19+
The timeout should be less than the period to ensure that only one fetch runs at a time.
20+
21+
```yaml
22+
fetcher:
23+
target:
24+
url: "http://localhost"
25+
service_name: "output_service"
26+
period:
27+
secs: 60
28+
nanos: 0
29+
timeout:
30+
secs: 10
31+
nanos: 0
32+
```

src/adaptor.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
use std::{convert::Infallible, future::ready};
2+
3+
use http::Request;
4+
use http_body_util::combinators::BoxBody;
5+
use hyper::{
6+
Response,
7+
body::{Bytes, Incoming},
8+
};
9+
use prosa::core::adaptor::Adaptor;
10+
11+
use crate::proc::{FetchAction, FetcherError, FetcherProc};
12+
13+
/// Trait adaptor for the Fetcher processor.
14+
pub trait FetcherAdaptor<M>: Adaptor
15+
where
16+
M: 'static
17+
+ std::marker::Send
18+
+ std::marker::Sync
19+
+ std::marker::Sized
20+
+ std::clone::Clone
21+
+ std::fmt::Debug
22+
+ prosa_utils::msg::tvf::Tvf
23+
+ std::default::Default,
24+
{
25+
/// Method called when the processor spawns
26+
/// This method is called only once so the processing will be thread safe
27+
fn new(proc: &FetcherProc<M>) -> Result<Self, FetcherError<M>>
28+
where
29+
Self: std::marker::Sized;
30+
31+
/// Method that indicate what should be done to fetch informations from the remote system
32+
fn fetch(&mut self) -> Result<FetchAction<M>, FetcherError<M>>;
33+
34+
/// Create an HTTP request to fetch information
35+
fn create_http_request(
36+
&self,
37+
request_builder: http::request::Builder,
38+
) -> Result<Request<BoxBody<Bytes, Infallible>>, FetcherError<M>>;
39+
40+
/// Process http response
41+
fn process_http_response(
42+
&mut self,
43+
_response: Response<Incoming>,
44+
) -> impl std::future::Future<Output = Result<FetchAction<M>, FetcherError<M>>> + Send {
45+
ready(Ok(FetchAction::None))
46+
}
47+
48+
/// Process service response
49+
fn process_service_response(
50+
&mut self,
51+
_response: prosa::core::msg::ResponseMsg<M>,
52+
) -> Result<FetchAction<M>, FetcherError<M>> {
53+
Ok(FetchAction::None)
54+
}
55+
56+
/// Method to process incomings error received by the processor
57+
fn process_service_error(
58+
&self,
59+
_error: prosa::core::msg::ErrorMsg<M>,
60+
) -> Result<FetchAction<M>, FetcherError<M>> {
61+
Ok(FetchAction::None)
62+
}
63+
}

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pub mod adaptor;
2+
pub mod proc;

0 commit comments

Comments
 (0)