Skip to content

Commit 73fe216

Browse files
[#123]: fixed logging and typos in agent-api- Updated the service type to a NodePort.Fixed typos in Dockerfile
1 parent f38ff15 commit 73fe216

File tree

5 files changed

+31
-9
lines changed

5 files changed

+31
-9
lines changed

core/api/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ identity = { path = "../src/components/identity" }
1515
tonic-reflection = "0.14.0"
1616
tonic-build = "0.14.0"
1717
dotenv = "0.15.0"
18+
tracing-subscriber = "0.3.19"
1819

1920
[build-dependencies]
2021
tonic-build = "0.14.0"

core/api/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ COPY --from=builder /usr/src/app/agent/target/release/identity /usr/local/bin/id
5050
COPY conntracker /usr/src/cortexbrain-agent/conntracker
5151

5252
# Set env vars for your app
53-
ENV BPF_PATH="/usr/src/cortexbrain-identity-service/conntracker"
53+
ENV BPF_PATH="/usr/src/cortexbrain-agent/conntracker"
5454
ENV PIN_MAP_PATH="/sys/fs/bpf/cortexbrain-identity-service/"
5555

5656
# Default command

core/api/src/api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const BPF_PATH: &str = "BPF_PATH";
3535
impl Default for AgentApi {
3636
fn default() -> Self {
3737
let bpf_path = std::env::var(BPF_PATH).context("BPF_PATH variable not found").unwrap();
38-
let data = fs::read(Path::new(&bpf_path)).context("Cannot load load from path").unwrap();
38+
let data = fs::read(Path::new(&bpf_path)).context("Cannot load data from path").unwrap();
3939

4040
AgentApi {
4141
name: "CortexFlow-Agent".to_string(),

core/api/src/main.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// module imports
22
use tonic::transport::{Error, Server};
3+
use tracing_subscriber::{fmt::format::FmtSpan, EnvFilter};
34

45
mod agent;
56
mod api;
@@ -14,32 +15,49 @@ use crate::agent::agent_server::AgentServer;
1415
use crate::api::AgentApi; //api implementations //from tonic. generated from agent.proto
1516

1617
use tokio::main;
18+
use tracing::{error, info};
1719

1820
#[main]
1921
async fn main() -> Result<(), Error> {
20-
let address = "127.0.0.1:9090".parse().unwrap();
22+
//init tracing subscriber
23+
tracing_subscriber::fmt()
24+
.with_max_level(tracing::Level::INFO)
25+
.with_target(false)
26+
.with_level(true)
27+
.with_span_events(FmtSpan::NONE)
28+
.with_file(false)
29+
.pretty()
30+
.with_env_filter(EnvFilter::new("info"))
31+
.with_line_number(false)
32+
.init();
33+
34+
info!("Starting agent server...");
35+
info!("fetching data");
36+
37+
//FIXME: binding on 0.0.0.0 address is not ideal for a production environment. This will need future fixes
38+
let address = "0.0.0.0:9090".parse().unwrap();
2139
let api = AgentApi::default();
2240

2341
match tonic_reflection::server::Builder::configure()
2442
.register_encoded_file_descriptor_set(agent_proto::AGENT_DESCRIPTOR)
2543
.build_v1()
2644
{
2745
Ok(reflection_server) => {
28-
print!("reflection server started correctly");
46+
info!("reflection server started correctly");
2947
match Server::builder()
3048
.add_service(AgentServer::new(api))
3149
.add_service(reflection_server)
3250
.serve(address)
3351
.await
3452
{
35-
Ok(_) => println!("Server started with no errors"),
36-
Err(e) => eprintln!(
53+
Ok(_) => info!("Server started with no errors"),
54+
Err(e) => error!(
3755
"An error occured during the Server::builder processe. Error {}",
3856
e
3957
),
4058
}
4159
}
42-
Err(e) => eprintln!(
60+
Err(e) => error!(
4361
"An error occured during the starting of the reflection server. Error {}",
4462
e
4563
),

core/src/testing/agent.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@ spec:
3434
echo "checking privileges"
3535
ls -ld /sys/fs/bpf
3636
37+
echo "checking if conntracker path"
38+
ls -l /usr/src/cortexbrain-agent/conntracker
39+
3740
echo "Running application..."
38-
exec /usr/local/bin/cortexflow-agent || echo "Application exited with code $?"
41+
exec /usr/local/bin/agent-api || echo "Application exited with code $?"
3942
volumeMounts:
4043
- name: bpf
4144
mountPath: /sys/fs/bpf
@@ -84,5 +87,5 @@ spec:
8487
name: agent-server-port
8588
port: 9090
8689
targetPort: 9090
87-
type: ClusterIP
90+
type: NodePort
8891
---

0 commit comments

Comments
 (0)