diff --git a/Cargo.toml b/Cargo.toml index b8d8b6b1..6c1abd13 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,7 +35,6 @@ members = [ "crates/kiss/manager", "crates/kiss/monitor", "crates/kiss/operator", - "crates/kubegraph/analyzer/llm", "crates/kubegraph/api", "crates/kubegraph/connector/fake", "crates/kubegraph/connector/local", @@ -137,7 +136,7 @@ kube = { version = "0.91", default-features = false } lalrpop = { version = "0.20" } lalrpop-util = { version = "0.20", features = ["lexer", "unicode"] } lancedb = { version = "0.5", default-features = false } -langchain-rust = { version = "4.1", default-features = false } +# langchain-rust = { version = "4.1", default-features = false } mime = { version = "0.3" } # FIXME: push a PR: rustls-tls feature support minio = { git = "https://github.com/ulagbulag/minio-rs.git", version = "0.2.0-alpha", default-features = false, features = [ @@ -176,10 +175,10 @@ or-tools = { git = "https://github.com/ulagbulag/or-tools-rs", version = "0.1", "build-native", "solver-all", ] } -ort-sys = { version = "2.0.0-rc.2", features = [ - "download-binaries", - "load-dynamic", -] } +# ort-sys = { version = "2.0.0-rc.2", features = [ # add onnxruntime library support for `langchain-rust` crate +# "download-binaries", +# "load-dynamic", +# ] } ordered-float = { version = "4.2", default-features = false, features = [ "bytemuck", "schemars", diff --git a/crates/kubegraph/analyzer/llm/Cargo.toml b/crates/kubegraph/analyzer/llm/Cargo.toml deleted file mode 100644 index 17434040..00000000 --- a/crates/kubegraph/analyzer/llm/Cargo.toml +++ /dev/null @@ -1,42 +0,0 @@ -[package] -name = "kubegraph-analyzer-llm" - -authors = { workspace = true } -description = { workspace = true } -documentation = { workspace = true } -edition = { workspace = true } -include = { workspace = true } -keywords = { workspace = true } -license = { workspace = true } -readme = { workspace = true } -rust-version = { workspace = true } -homepage = { workspace = true } -repository = { workspace = true } -version = { workspace = true } - -[lints] -workspace = true - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[features] -default = ["full"] -full = ["df-full"] - -# DataFrame -df-full = ["df-polars"] -df-polars = ["kubegraph-api/df-polars"] - -[dependencies] -ark-core = { path = "../../../ark/core", features = ["signal"] } -kubegraph-api = { path = "../../api" } - -anyhow = { workspace = true } -async-trait = { workspace = true } -clap = { workspace = true } -futures = { workspace = true } -langchain-rust = { workspace = true } -ort-sys = { workspace = true } # add onnxruntime library support for `langchain-rust` crate -schemars = { workspace = true } -serde = { workspace = true } -tracing = { workspace = true } diff --git a/crates/kubegraph/analyzer/llm/src/lib.rs b/crates/kubegraph/analyzer/llm/src/lib.rs deleted file mode 100644 index 83b75fc3..00000000 --- a/crates/kubegraph/analyzer/llm/src/lib.rs +++ /dev/null @@ -1,139 +0,0 @@ -mod llm_model; -mod prompt; - -use anyhow::{bail, Result}; -use ark_core::signal::FunctionSignal; -use async_trait::async_trait; -use clap::Parser; -use kubegraph_api::{ - analyzer::{ - llm::VirtualProblemAnalyzerLLM, VirtualProblemAnalyzer, VirtualProblemAnalyzerType, - }, - component::NetworkComponent, - frame::LazyFrame, - graph::{Graph, GraphMetadataPinned, GraphMetadataRaw}, - problem::VirtualProblem, -}; -use langchain_rust::language_models::llm::LLM; -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; -use tracing::{instrument, Level}; - -#[derive( - Copy, - Clone, - Debug, - Default, - PartialEq, - Eq, - PartialOrd, - Ord, - Hash, - Serialize, - Deserialize, - JsonSchema, - Parser, -)] -#[clap(rename_all = "kebab-case")] -#[serde(rename_all = "camelCase")] -pub struct NetworkAnalyzerArgs {} - -#[derive(Clone)] -pub struct NetworkAnalyzer { - llm: M, - prompt: self::prompt::PromptLoader, -} - -#[async_trait] -impl NetworkComponent for NetworkAnalyzer { - type Args = NetworkAnalyzerArgs; - - #[instrument(level = Level::INFO)] - async fn try_new(args: ::Args, _: &FunctionSignal) -> Result { - let NetworkAnalyzerArgs {} = args; - Ok(Self { - llm: self::llm_model::GenericLLM::default(), - prompt: self::prompt::PromptLoader::try_default().await?, - }) - } -} - -#[async_trait] -impl ::kubegraph_api::analyzer::NetworkAnalyzer for NetworkAnalyzer -where - M: LLM, -{ - type Spec = VirtualProblemAnalyzerLLM; - - #[instrument(level = Level::INFO, skip(self, problem, graph))] - async fn pin_graph_raw( - &self, - problem: &VirtualProblem, - graph: Graph, - ) -> Result> { - let VirtualProblemAnalyzer { - original_metadata: map_from, - r#type: VirtualProblemAnalyzerLLM {}, - } = problem.analyzer.clone().try_into_llm()?; - let map_to = problem.spec.metadata.clone(); - - // TODO: to be implemented - let Graph { - data, - metadata, - scope, - } = graph; - Ok(Graph { - data: data.cast(&map_from, &map_to), - metadata: map_to, - scope, - }) - } - - #[instrument(level = Level::INFO, skip(self, metadata))] - async fn pin_graph_metadata_raw( - &self, - metadata: GraphMetadataRaw, - ) -> Result<(VirtualProblemAnalyzer, GraphMetadataPinned)> { - // TODO: to be implemented - // let prompt = self.prompt.build(&metadata)?; - // let response = self - // .llm - // .invoke(&prompt) - // .await - // .map_err(|error| anyhow!("failed to execute LLM: {error}"))?; - // println!("{response}"); - - let analyzer = VirtualProblemAnalyzer { - original_metadata: metadata, - r#type: VirtualProblemAnalyzerType::LLM(VirtualProblemAnalyzerLLM {}), - }; - - let metadata = GraphMetadataPinned::default(); - Ok((analyzer, metadata)) - } -} - -trait VirtualProblemAnalyzerExt { - fn try_into_llm(self) -> Result>; -} - -impl VirtualProblemAnalyzerExt for VirtualProblemAnalyzer { - fn try_into_llm(self) -> Result> { - let Self { - original_metadata, - r#type, - } = self; - - match r#type { - VirtualProblemAnalyzerType::LLM(r#type) => Ok(VirtualProblemAnalyzer { - original_metadata, - r#type, - }), - analyzer => { - let name = analyzer.name(); - bail!("unexpected analyzer: {name}") - } - } - } -} diff --git a/crates/kubegraph/analyzer/llm/src/llm_model.rs b/crates/kubegraph/analyzer/llm/src/llm_model.rs deleted file mode 100644 index a78440de..00000000 --- a/crates/kubegraph/analyzer/llm/src/llm_model.rs +++ /dev/null @@ -1,75 +0,0 @@ -use std::pin::Pin; - -use async_trait::async_trait; -use futures::Stream; -use langchain_rust::{ - language_models::{llm::LLM, options::CallOptions, GenerateResult, LLMError}, - llm::{OpenAI, OpenAIConfig}, - schemas::{Message, StreamData}, -}; -use tracing::{instrument, Level}; - -#[derive(Clone)] -pub struct GenericLLM { - openai: OpenAI, -} - -impl Default for GenericLLM { - fn default() -> Self { - Self { - openai: OpenAI::default() - .with_config(OpenAIConfig::default()) - // .with_model(OpenAIModel::Gpt4.to_string()); - .with_model("gpt-4o") - .with_options(default_options()), - } - } -} - -impl GenericLLM { - fn get_default(&self) -> &impl LLM { - &self.openai - } - - fn get_default_mut(&mut self) -> &mut impl LLM { - &mut self.openai - } -} - -#[async_trait] -impl LLM for GenericLLM { - #[instrument(level = Level::INFO, skip(self, messages))] - async fn generate(&self, messages: &[Message]) -> Result { - self.get_default().generate(messages).await - } - - #[instrument(level = Level::INFO, skip(self, prompt))] - async fn invoke(&self, prompt: &str) -> Result { - self.get_default().invoke(prompt).await - } - - #[instrument(level = Level::INFO, skip(self, messages))] - async fn stream( - &self, - messages: &[Message], - ) -> Result> + Send>>, LLMError> { - self.get_default().stream(messages).await - } - - fn add_options(&mut self, options: CallOptions) { - self.get_default_mut().add_options(options) - } - - //This is usefull when using non chat models - fn messages_to_string(&self, messages: &[Message]) -> String { - self.get_default().messages_to_string(messages) - } -} - -fn default_options() -> CallOptions { - CallOptions { - seed: Some(980904), - temperature: Some(0.0), - ..Default::default() - } -} diff --git a/crates/kubegraph/analyzer/llm/src/prompt.rs b/crates/kubegraph/analyzer/llm/src/prompt.rs deleted file mode 100644 index 2f7c83f6..00000000 --- a/crates/kubegraph/analyzer/llm/src/prompt.rs +++ /dev/null @@ -1,15 +0,0 @@ -use anyhow::Result; -use kubegraph_api::graph::GraphMetadataRaw; - -#[derive(Clone)] -pub(crate) struct PromptLoader {} - -impl PromptLoader { - pub(crate) async fn try_default() -> Result { - Ok(Self {}) - } - - pub(crate) fn build(&self, metadata: &GraphMetadataRaw) -> Result { - Ok(format!("hello world")) - } -} diff --git a/crates/kubegraph/api/Cargo.toml b/crates/kubegraph/api/Cargo.toml index e2ed9100..45056d5f 100644 --- a/crates/kubegraph/api/Cargo.toml +++ b/crates/kubegraph/api/Cargo.toml @@ -22,11 +22,7 @@ workspace = true [features] default = ["minimal"] minimal = ["connector-fake", "connector-local", "df-polars", "function-dummy"] -full = ["analyzer-full", "connector-full", "df-full", "function-full"] - -# Analyzers -analyzer-full = ["analyzer-llm"] -analyzer-llm = [] +full = ["connector-full", "df-full", "function-full"] # Connectors connector-full = ["connector-fake", "connector-local", "connector-prometheus"] diff --git a/crates/kubegraph/api/src/analyzer/empty.rs b/crates/kubegraph/api/src/analyzer/empty.rs deleted file mode 100644 index dfa50e48..00000000 --- a/crates/kubegraph/api/src/analyzer/empty.rs +++ /dev/null @@ -1,6 +0,0 @@ -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; - -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)] -#[serde(rename_all = "camelCase")] -pub struct VirtualProblemAnalyzerEmpty {} diff --git a/crates/kubegraph/api/src/analyzer/llm.rs b/crates/kubegraph/api/src/analyzer/llm.rs deleted file mode 100644 index c457c9a0..00000000 --- a/crates/kubegraph/api/src/analyzer/llm.rs +++ /dev/null @@ -1,6 +0,0 @@ -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; - -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)] -#[serde(rename_all = "camelCase")] -pub struct VirtualProblemAnalyzerLLM {} diff --git a/crates/kubegraph/api/src/analyzer/mod.rs b/crates/kubegraph/api/src/analyzer/mod.rs deleted file mode 100644 index 8ef78b4f..00000000 --- a/crates/kubegraph/api/src/analyzer/mod.rs +++ /dev/null @@ -1,166 +0,0 @@ -#[cfg(feature = "analyzer-llm")] -pub mod llm; - -use anyhow::Result; -use async_trait::async_trait; -use futures::{stream::FuturesUnordered, TryStreamExt}; -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; -use tracing::{instrument, Level}; - -use crate::{ - frame::LazyFrame, - graph::{ - Graph, GraphFilter, GraphMetadata, GraphMetadataExt, GraphMetadataPinned, GraphMetadataRaw, - GraphScope, - }, - problem::{NetworkProblemCrd, ProblemSpec, VirtualProblem}, - resource::NetworkResourceCollectionDB, -}; - -#[async_trait] -pub trait NetworkAnalyzerExt -where - Self: NetworkAnalyzer, -{ - #[instrument(level = Level::INFO, skip(self, resource_db))] - async fn inspect( - &self, - resource_db: &dyn NetworkResourceCollectionDB, - ) -> Result> { - // TODO: to be implemented (aggregating other problems) - let problems = resource_db.list(()).await; - - match problems { - Some(problems) if !problems.is_empty() => { - problems - .into_iter() - .map(pin_problem) - .map(|problem| self.pin_virtual_problem(problem)) - .collect::>() - .try_collect() - .await - } - Some(_) | None => return Ok(Vec::default()), - } - } - - #[instrument(level = Level::INFO, skip(self, problem, graph))] - async fn pin_graph( - &self, - problem: &VirtualProblem, - graph: Graph, - ) -> Result> { - let Graph { - data, - metadata, - scope, - } = graph; - match metadata { - GraphMetadata::Raw(metadata) => { - let graph = Graph { - data, - metadata, - scope, - }; - self.pin_graph_raw(problem, graph).await - } - GraphMetadata::Pinned(metadata) => Ok(Graph { - data, - metadata, - scope, - }), - GraphMetadata::Standard(metadata) => Ok(Graph { - data, - metadata: metadata.to_pinned(), - scope, - }), - } - } - - #[instrument(level = Level::INFO, skip(self, problem))] - async fn pin_virtual_problem( - &self, - problem: VirtualProblem<(), GraphMetadataRaw>, - ) -> Result { - let VirtualProblem { - analyzer: (), - filter, - scope, - spec: ProblemSpec { metadata, verbose }, - } = problem; - - let (analyzer, metadata) = self.pin_graph_metadata_raw(metadata).await?; - - Ok(VirtualProblem { - analyzer, - filter, - scope, - spec: ProblemSpec { metadata, verbose }, - }) - } -} - -#[async_trait] -impl NetworkAnalyzerExt for T where Self: NetworkAnalyzer {} - -#[async_trait] -pub trait NetworkAnalyzer -where - Self: Sync, -{ - type Spec: Send; - - async fn pin_graph_raw( - &self, - problem: &VirtualProblem, - graph: Graph, - ) -> Result>; - - async fn pin_graph_metadata_raw( - &self, - metadata: GraphMetadataRaw, - ) -> Result<(VirtualProblemAnalyzer, GraphMetadataPinned)>; -} - -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)] -#[serde(rename_all = "camelCase")] -pub struct VirtualProblemAnalyzer { - pub original_metadata: GraphMetadataRaw, - pub r#type: T, -} - -impl VirtualProblemAnalyzer { - pub const fn name(&self) -> &'static str { - self.r#type.name() - } -} - -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)] -#[serde(rename_all = "camelCase")] -pub enum VirtualProblemAnalyzerType { - Empty, - #[cfg(feature = "analyzer-llm")] - LLM(self::llm::VirtualProblemAnalyzerLLM), -} - -impl VirtualProblemAnalyzerType { - pub const fn name(&self) -> &'static str { - match self { - Self::Empty => "empty", - #[cfg(feature = "analyzer-llm")] - Self::LLM(_) => "llm", - } - } -} - -fn pin_problem(problem: NetworkProblemCrd) -> VirtualProblem<(), GraphMetadataRaw> { - let scope = GraphScope::from_resource(&problem); - - VirtualProblem { - analyzer: (), - filter: GraphFilter::all(scope.namespace.clone()), - scope, - spec: problem.spec, - } -} diff --git a/crates/kubegraph/api/src/dependency.rs b/crates/kubegraph/api/src/dependency.rs index 46b78156..52cb6d56 100644 --- a/crates/kubegraph/api/src/dependency.rs +++ b/crates/kubegraph/api/src/dependency.rs @@ -1,26 +1,20 @@ -use std::collections::BTreeMap; - use anyhow::Result; use async_trait::async_trait; use crate::{ - analyzer::{NetworkAnalyzer, VirtualProblemAnalyzer}, frame::LazyFrame, function::NetworkFunctionCrd, - graph::{Graph, GraphData, GraphEdges, GraphMetadataPinned, GraphScope}, + graph::{Graph, GraphData, GraphEdges}, problem::VirtualProblem, }; #[async_trait] pub trait NetworkDependencySolver { - async fn build_pipeline( + async fn build_pipeline( &self, - analyzer: &A, problem: &VirtualProblem, spec: NetworkDependencySolverSpec, - ) -> Result, A>> - where - A: NetworkAnalyzer; + ) -> Result>>; } pub struct NetworkDependencySolverSpec { @@ -28,12 +22,7 @@ pub struct NetworkDependencySolverSpec { pub graphs: Vec>, } -pub type NetworkDependencyPipeline = - NetworkDependencyPipelineTemplate::Spec>>; - -pub struct NetworkDependencyPipelineTemplate -{ +pub struct NetworkDependencyPipeline { pub graph: G, - pub problem: VirtualProblem, pub static_edges: Option>, } diff --git a/crates/kubegraph/api/src/lib.rs b/crates/kubegraph/api/src/lib.rs index efda577f..2cca27ee 100644 --- a/crates/kubegraph/api/src/lib.rs +++ b/crates/kubegraph/api/src/lib.rs @@ -1,7 +1,6 @@ #[cfg(feature = "df-polars")] extern crate polars as pl; -pub mod analyzer; pub mod component; pub mod connector; pub mod dependency; diff --git a/crates/kubegraph/api/src/problem.rs b/crates/kubegraph/api/src/problem.rs index 1d2f8231..c8473054 100644 --- a/crates/kubegraph/api/src/problem.rs +++ b/crates/kubegraph/api/src/problem.rs @@ -3,25 +3,21 @@ use schemars::JsonSchema; use serde::{de::DeserializeOwned, Deserialize, Serialize}; use crate::{ - analyzer::VirtualProblemAnalyzer, - graph::{GraphFilter, GraphMetadataPinned, GraphMetadataRaw, GraphScope}, + graph::{GraphFilter, GraphMetadataPinned, GraphScope}, resource::NetworkResource, }; #[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)] #[schemars(bound = " - A: JsonSchema, M: Default + JsonSchema, ")] #[serde( rename_all = "camelCase", bound = " - A: Serialize + DeserializeOwned, M: Default + Serialize + DeserializeOwned, " )] -pub struct VirtualProblem { - pub analyzer: A, +pub struct VirtualProblem { pub filter: GraphFilter, #[serde(flatten)] pub scope: GraphScope, @@ -67,7 +63,7 @@ pub struct VirtualProblem { rename_all = "camelCase", bound = "M: Default + Serialize + DeserializeOwned" )] -pub struct ProblemSpec { +pub struct ProblemSpec { #[serde(default)] pub metadata: M, diff --git a/crates/kubegraph/api/src/vm.rs b/crates/kubegraph/api/src/vm.rs index 89364290..19469fd8 100644 --- a/crates/kubegraph/api/src/vm.rs +++ b/crates/kubegraph/api/src/vm.rs @@ -20,19 +20,15 @@ use tokio::time::{sleep, Instant}; use tracing::{error, info, instrument, warn, Level}; use crate::{ - analyzer::{NetworkAnalyzer, NetworkAnalyzerExt}, component::{NetworkComponent, NetworkComponentExt}, - dependency::{ - NetworkDependencyPipeline, NetworkDependencyPipelineTemplate, NetworkDependencySolver, - NetworkDependencySolverSpec, - }, + dependency::{NetworkDependencyPipeline, NetworkDependencySolver, NetworkDependencySolverSpec}, frame::LazyFrame, graph::{ - Graph, GraphData, GraphMetadata, GraphScope, NetworkGraphDB, NetworkGraphDBExt, - ScopedNetworkGraphDBContainer, + Graph, GraphData, GraphFilter, GraphMetadata, GraphScope, NetworkGraphDB, + NetworkGraphDBExt, ScopedNetworkGraphDBContainer, }, ops::{And, Eq, Ge, Gt, Le, Lt, Max, Min, Ne, Or}, - problem::{ProblemSpec, VirtualProblem}, + problem::{NetworkProblemCrd, ProblemSpec, VirtualProblem}, resource::{NetworkResourceCollectionDB, NetworkResourceDB}, runner::NetworkRunner, solver::NetworkSolver, @@ -173,7 +169,7 @@ where state: self::sealed::NetworkVirtualMachineState, ) -> Result { // Define-or-Reuse a converged problem - let problems = self.analyzer().inspect(self.resource_db()).await?; + let problems = self.pull_problems().await?; if problems.is_empty() { return Ok(self::sealed::NetworkVirtualMachineState::Ready); } @@ -194,14 +190,13 @@ where problem: VirtualProblem, ) -> Result { // Step 1. Pull & Convert graphs - let NetworkDependencyPipelineTemplate { + let NetworkDependencyPipeline { graph: Graph { data, metadata, scope, }, - problem, static_edges, } = match self.pull_graph(&problem).await? { Some(pipeline) => match state { @@ -238,13 +233,31 @@ where Ok(self::sealed::NetworkVirtualMachineState::Completed) } + #[instrument(level = Level::INFO, skip(self))] + async fn pull_problems(&self) -> Result> { + Ok(self + .resource_db() + .list(()) + .await + .unwrap_or_default() + .into_iter() + .map(|cr: NetworkProblemCrd| { + let scope = GraphScope::from_resource(&cr); + VirtualProblem { + filter: GraphFilter::all(scope.namespace.clone()), + scope, + spec: cr.spec, + } + }) + .collect()) + } + #[instrument(level = Level::INFO, skip(self, problem))] async fn pull_graph( &self, problem: &VirtualProblem, - ) -> Result, Self::Analyzer>>> { + ) -> Result>>> { let VirtualProblem { - analyzer: _, filter, scope, spec: ProblemSpec { @@ -273,16 +286,15 @@ where // Step 3. Solve the dependencies let spec = NetworkDependencySolverSpec { functions, graphs }; - let NetworkDependencyPipelineTemplate { + let NetworkDependencyPipeline { graph: data, - problem, static_edges, } = self .dependency_solver() - .build_pipeline(self.analyzer(), &problem, spec) + .build_pipeline(problem, spec) .await?; - Ok(Some(NetworkDependencyPipelineTemplate { + Ok(Some(NetworkDependencyPipeline { graph: Graph { data, metadata: GraphMetadata::Pinned(metadata.clone()), @@ -291,7 +303,6 @@ where name: GraphScope::NAME_GLOBAL.into(), }, }, - problem, static_edges, })) } @@ -332,7 +343,6 @@ pub trait NetworkVirtualMachine where Self: Send + Sync, { - type Analyzer: NetworkComponent + NetworkAnalyzer; type DependencySolver: NetworkComponent + NetworkDependencySolver; type ResourceDB: 'static + Send + Clone + NetworkComponent + NetworkResourceCollectionDB; type GraphDB: 'static + Send + Clone + NetworkComponent + NetworkGraphDB; @@ -341,8 +351,6 @@ where + NetworkSolver, Output = GraphData>; type Visualizer: NetworkComponent + NetworkVisualizer; - fn analyzer(&self) -> &::Analyzer; - fn dependency_solver(&self) -> &::DependencySolver; fn graph_db(&self) -> &::GraphDB; @@ -371,7 +379,6 @@ impl NetworkVirtualMachine for Arc where T: ?Sized + NetworkVirtualMachine, { - type Analyzer = ::Analyzer; type DependencySolver = ::DependencySolver; type GraphDB = ::GraphDB; type ResourceDB = ::ResourceDB; @@ -379,10 +386,6 @@ where type Solver = ::Solver; type Visualizer = ::Visualizer; - fn analyzer(&self) -> &::Analyzer { - ::analyzer(&**self) - } - fn dependency_solver(&self) -> &::DependencySolver { ::dependency_solver(&**self) } diff --git a/crates/kubegraph/dependency/solver/src/lib.rs b/crates/kubegraph/dependency/solver/src/lib.rs index 31262e1f..09aa5efb 100644 --- a/crates/kubegraph/dependency/solver/src/lib.rs +++ b/crates/kubegraph/dependency/solver/src/lib.rs @@ -7,7 +7,6 @@ use std::{ use anyhow::{anyhow, bail, Result}; use async_trait::async_trait; use kubegraph_api::{ - analyzer::NetworkAnalyzer, dependency::{NetworkDependencyPipeline, NetworkDependencySolverSpec}, frame::LazyFrame, function::{ @@ -32,15 +31,11 @@ pub struct NetworkDependencyGraph {} #[async_trait] impl ::kubegraph_api::dependency::NetworkDependencySolver for NetworkDependencyGraph { - async fn build_pipeline( + async fn build_pipeline( &self, - _analyzer: &A, problem: &VirtualProblem, spec: NetworkDependencySolverSpec, - ) -> Result, A>> - where - A: NetworkAnalyzer, - { + ) -> Result>> { // Step 1. Register all available functions let graph = spec .functions @@ -168,16 +163,8 @@ impl ::kubegraph_api::dependency::NetworkDependencySolver for NetworkDependencyG println!(); } - Ok(NetworkDependencyPipeline::, A> { + Ok(NetworkDependencyPipeline { graph, - problem: VirtualProblem { - // TODO: to be implemented - // TODO: 여기부터 시작 (그냥 없앨까..? 아니면 함수 복원용으로..?) - analyzer: BTreeMap::default(), - filter: problem.filter.clone(), - scope: problem.scope.clone(), - spec: problem.spec.clone(), - }, static_edges: Some(static_edges), }) } @@ -293,7 +280,7 @@ struct Function { } impl Function { - fn new(cr: NetworkFunctionCrd, problem: &VirtualProblem) -> Result + fn new(cr: NetworkFunctionCrd, problem: &VirtualProblem) -> Result where M: GraphMetadataExt, { diff --git a/crates/kubegraph/gateway/Cargo.toml b/crates/kubegraph/gateway/Cargo.toml index f6cc0319..b07b5a2c 100644 --- a/crates/kubegraph/gateway/Cargo.toml +++ b/crates/kubegraph/gateway/Cargo.toml @@ -36,13 +36,6 @@ full = [ "visualizer-full", ] -# Configure Analyzers -analyzer-full = ["analyzer-llm"] -analyzer-llm = [ - "kubegraph-api/analyzer-llm", - "kubegraph-vm-local?/analyzer-llm", -] - # Configure Connectors connector-full = ["connector-fake", "connector-prometheus", "connector-local"] connector-fake = [ diff --git a/crates/kubegraph/simulator/Cargo.toml b/crates/kubegraph/simulator/Cargo.toml index 1a74e269..356c4395 100644 --- a/crates/kubegraph/simulator/Cargo.toml +++ b/crates/kubegraph/simulator/Cargo.toml @@ -23,10 +23,6 @@ workspace = true default = ["full"] full = ["solver-full"] -# Configure Analyzers -analyzer-full = ["analyzer-llm"] -analyzer-llm = ["kubegraph-api/analyzer-llm", "kubegraph-vm-local/analyzer-llm"] - # Configure Solvers solver-full = ["solver-ortools"] solver-ortools = ["kubegraph-vm-local/solver-ortools"] diff --git a/crates/kubegraph/vm/lazy/src/function.rs b/crates/kubegraph/vm/lazy/src/function.rs index 054825f8..8f15f78e 100644 --- a/crates/kubegraph/vm/lazy/src/function.rs +++ b/crates/kubegraph/vm/lazy/src/function.rs @@ -246,8 +246,7 @@ mod tests { function: NetworkFunctionTemplate<&'static str>, ) -> ::polars::frame::DataFrame { use kubegraph_api::{ - analyzer::{VirtualProblemAnalyzer, VirtualProblemAnalyzerType}, - graph::{GraphFilter, GraphMetadataRaw, GraphScope}, + graph::{GraphFilter, GraphScope}, problem::ProblemSpec, }; @@ -261,10 +260,6 @@ mod tests { // Step 2. Define a problem let problem = VirtualProblem { - analyzer: VirtualProblemAnalyzer { - original_metadata: GraphMetadataRaw::default(), - r#type: VirtualProblemAnalyzerType::Empty, - }, filter: GraphFilter::all("default".into()), scope: GraphScope { namespace: "default".into(), diff --git a/crates/kubegraph/vm/lazy/src/lib.rs b/crates/kubegraph/vm/lazy/src/lib.rs index 9f8695b8..610930d9 100644 --- a/crates/kubegraph/vm/lazy/src/lib.rs +++ b/crates/kubegraph/vm/lazy/src/lib.rs @@ -55,7 +55,7 @@ mod impl_call { }, }; - use crate::function::NetworkFunctionInferType; + use super::function::NetworkFunctionInferType; impl super::LazyVirtualMachine { pub fn call( diff --git a/crates/kubegraph/vm/local/Cargo.toml b/crates/kubegraph/vm/local/Cargo.toml index 1318d6fc..b91b9a78 100644 --- a/crates/kubegraph/vm/local/Cargo.toml +++ b/crates/kubegraph/vm/local/Cargo.toml @@ -22,10 +22,6 @@ workspace = true [features] default = [] -# Configure Analyzers -analyzer-full = ["analyzer-llm"] -analyzer-llm = ["kubegraph-analyzer-llm", "kubegraph-api/analyzer-llm"] - # Configure Connectors connector-full = ["connector-fake", "connector-local", "connector-prometheus"] connector-fake = [ @@ -50,7 +46,6 @@ connector-prometheus = [ # Configure DataFrame df-full = ["df-polars"] df-polars = [ - "kubegraph-analyzer-llm?/df-polars", "kubegraph-api/df-polars", "kubegraph-dependency-solver/df-polars", "kubegraph-runner-simulator?/df-polars", @@ -85,7 +80,6 @@ visualizer-auto = ["visualizer-egui"] visualizer-egui = ["kubegraph-visualizer-egui"] [dependencies] -kubegraph-analyzer-llm = { path = "../../analyzer/llm", optional = true, default-features = false } kubegraph-api = { path = "../../api" } kubegraph-connector-fake = { path = "../../connector/fake", optional = true, default-features = false } kubegraph-connector-local = { path = "../../connector/local", optional = true, default-features = false } diff --git a/crates/kubegraph/vm/local/src/analyzer.rs b/crates/kubegraph/vm/local/src/analyzer.rs deleted file mode 100644 index 1276174b..00000000 --- a/crates/kubegraph/vm/local/src/analyzer.rs +++ /dev/null @@ -1,162 +0,0 @@ -use anyhow::Result; -use ark_core::signal::FunctionSignal; -use async_trait::async_trait; -use clap::{Parser, ValueEnum}; -use kubegraph_api::{ - analyzer::{VirtualProblemAnalyzer, VirtualProblemAnalyzerType}, - component::NetworkComponent, - frame::LazyFrame, - graph::{Graph, GraphMetadataPinned, GraphMetadataRaw}, - problem::VirtualProblem, -}; -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; -use tracing::{instrument, Level}; - -#[derive( - Copy, - Clone, - Debug, - Default, - PartialEq, - Eq, - PartialOrd, - Ord, - Hash, - Serialize, - Deserialize, - JsonSchema, - Parser, -)] -#[clap(rename_all = "kebab-case")] -#[serde(rename_all = "camelCase")] -pub struct NetworkAnalyzerArgs { - #[arg( - long, - env = "KUBEGRAPH_ANALYZER", - value_enum, - value_name = "IMPL", - default_value_t = NetworkAnalyzerType::default(), - )] - #[serde(default)] - pub analyzer: NetworkAnalyzerType, - - #[cfg(feature = "analyzer-llm")] - #[command(flatten)] - #[serde(default)] - pub llm: <::kubegraph_analyzer_llm::NetworkAnalyzer as NetworkComponent>::Args, -} - -#[derive( - Copy, - Clone, - Debug, - Default, - PartialEq, - Eq, - PartialOrd, - Ord, - Hash, - Serialize, - Deserialize, - JsonSchema, - ValueEnum, -)] -#[clap(rename_all = "kebab-case")] -#[serde(rename_all = "kebab-case")] -pub enum NetworkAnalyzerType { - #[cfg_attr(not(feature = "analyzer-llm"), default)] - Disabled, - #[cfg(feature = "analyzer-llm")] - #[default] - LLM, -} - -#[derive(Clone)] -pub enum NetworkAnalyzer { - Disabled, - #[cfg(feature = "analyzer-llm")] - LLM(::kubegraph_analyzer_llm::NetworkAnalyzer), -} - -#[async_trait] -impl NetworkComponent for NetworkAnalyzer { - type Args = NetworkAnalyzerArgs; - - #[instrument(level = Level::INFO)] - async fn try_new( - args: ::Args, - signal: &FunctionSignal, - ) -> Result { - let NetworkAnalyzerArgs { - analyzer, - #[cfg(feature = "analyzer-llm")] - llm, - } = args; - - match analyzer { - NetworkAnalyzerType::Disabled => { - let _ = signal; - Ok(Self::Disabled) - } - #[cfg(feature = "analyzer-llm")] - NetworkAnalyzerType::LLM => Ok(Self::LLM( - ::kubegraph_analyzer_llm::NetworkAnalyzer::try_new(llm, signal).await?, - )), - } - } -} - -#[async_trait] -impl ::kubegraph_api::analyzer::NetworkAnalyzer for NetworkAnalyzer { - type Spec = VirtualProblemAnalyzer; - - #[instrument(level = Level::INFO, skip(self, problem, graph))] - async fn pin_graph_raw( - &self, - problem: &VirtualProblem, - graph: Graph, - ) -> Result> { - match self { - Self::Disabled => { - let Graph { - data, - metadata: _, - scope, - } = graph; - let map_from = &problem.analyzer.original_metadata; - let map_to = problem.spec.metadata.clone(); - - Ok(Graph { - data: data.cast(map_from, &map_to), - metadata: map_to, - scope, - }) - } - #[cfg(feature = "analyzer-llm")] - Self::LLM(runtime) => runtime.pin_graph_raw(problem, graph).await, - } - } - - #[instrument(level = Level::INFO, skip(self, metadata))] - async fn pin_graph_metadata_raw( - &self, - metadata: GraphMetadataRaw, - ) -> Result<(VirtualProblemAnalyzer, GraphMetadataPinned)> { - match self { - Self::Disabled => { - let analyzer = VirtualProblemAnalyzer { - original_metadata: metadata, - r#type: VirtualProblemAnalyzerType::Empty, - }; - let metadata = { - let _ = metadata; - GraphMetadataPinned::default() - }; - Ok((analyzer, metadata)) - } - #[cfg(feature = "analyzer-llm")] - Self::LLM(runtime) => runtime.pin_graph_metadata_raw(metadata).await, - } - } -} diff --git a/crates/kubegraph/vm/local/src/args.rs b/crates/kubegraph/vm/local/src/args.rs index eab0972e..9bf1dacf 100644 --- a/crates/kubegraph/vm/local/src/args.rs +++ b/crates/kubegraph/vm/local/src/args.rs @@ -13,10 +13,6 @@ use serde::{Deserialize, Serialize}; #[clap(rename_all = "kebab-case")] #[serde(rename_all = "camelCase")] pub struct NetworkArgs { - #[command(flatten)] - #[serde(default)] - pub analyzer: <::Analyzer as NetworkComponent>::Args, - #[command(flatten)] #[serde(default)] pub dependency_graph: <::DependencySolver as NetworkComponent>::Args, diff --git a/crates/kubegraph/vm/local/src/lib.rs b/crates/kubegraph/vm/local/src/lib.rs index 745f9c7a..9661b70c 100644 --- a/crates/kubegraph/vm/local/src/lib.rs +++ b/crates/kubegraph/vm/local/src/lib.rs @@ -1,7 +1,6 @@ #[cfg(feature = "df-polars")] extern crate polars as pl; -mod analyzer; mod args; mod dependency; mod graph; @@ -29,7 +28,6 @@ use tracing::{instrument, Level}; #[derive(Clone)] pub struct NetworkVirtualMachine { - analyzer: self::analyzer::NetworkAnalyzer, dependency_graph: self::dependency::NetworkDependencyGraph, args: self::args::NetworkVirtualMachineArgs, graph_db: self::graph::NetworkGraphDB, @@ -52,7 +50,6 @@ impl NetworkComponent for NetworkVirtualMachine { ) -> Result { // Step 1. Initialize components let self::args::NetworkArgs { - analyzer, dependency_graph, graph_db, resource_db, @@ -62,7 +59,6 @@ impl NetworkComponent for NetworkVirtualMachine { vm, } = args; let vm = Self { - analyzer: self::analyzer::NetworkAnalyzer::try_new(analyzer, signal).await?, args: vm, dependency_graph: self::dependency::NetworkDependencyGraph::try_new( dependency_graph, @@ -93,7 +89,6 @@ impl NetworkComponent for NetworkVirtualMachine { #[async_trait] impl ::kubegraph_api::vm::NetworkVirtualMachine for NetworkVirtualMachine { - type Analyzer = self::analyzer::NetworkAnalyzer; type DependencySolver = self::dependency::NetworkDependencyGraph; type ResourceDB = self::resource::NetworkResourceDB; type GraphDB = self::graph::NetworkGraphDB; @@ -101,10 +96,6 @@ impl ::kubegraph_api::vm::NetworkVirtualMachine for NetworkVirtualMachine { type Solver = self::solver::NetworkSolver; type Visualizer = self::visualizer::NetworkVisualizer; - fn analyzer(&self) -> &::Analyzer { - &self.analyzer - } - fn dependency_solver( &self, ) -> &::DependencySolver { @@ -181,11 +172,7 @@ mod tests { #[::tokio::test] async fn simulate_simple_with_edges() { use kubegraph_api::{ - analyzer::{VirtualProblemAnalyzer, VirtualProblemAnalyzerType}, - graph::{ - Graph, GraphData, GraphFilter, GraphMetadata, GraphMetadataRaw, GraphScope, - NetworkGraphDB, - }, + graph::{Graph, GraphData, GraphFilter, GraphMetadata, GraphScope, NetworkGraphDB}, problem::{ProblemSpec, VirtualProblem}, }; @@ -248,10 +235,6 @@ mod tests { // Step 4. Add cost & value function (heuristic) let problem = VirtualProblem { - analyzer: VirtualProblemAnalyzer { - original_metadata: GraphMetadataRaw::default(), - r#type: VirtualProblemAnalyzerType::Empty, - }, filter: GraphFilter::all("default".into()), scope: GraphScope { namespace: "default".into(), @@ -329,16 +312,12 @@ mod tests { async fn simulate_simple_with_function() { use kube::api::ObjectMeta; use kubegraph_api::{ - analyzer::{VirtualProblemAnalyzer, VirtualProblemAnalyzerType}, frame::{DataFrame, LazyFrame}, function::{ dummy::NetworkFunctionDummySpec, NetworkFunctionCrd, NetworkFunctionKind, NetworkFunctionSpec, NetworkFunctionTemplate, }, - graph::{ - Graph, GraphData, GraphFilter, GraphMetadata, GraphMetadataRaw, GraphScope, - NetworkGraphDB, - }, + graph::{Graph, GraphData, GraphFilter, GraphMetadata, GraphScope, NetworkGraphDB}, problem::{ProblemSpec, VirtualProblem}, resource::NetworkResourceDB, }; @@ -416,10 +395,6 @@ mod tests { // Step 5. Add cost & value function (heuristic) let problem = VirtualProblem { - analyzer: VirtualProblemAnalyzer { - original_metadata: GraphMetadataRaw::default(), - r#type: VirtualProblemAnalyzerType::Empty, - }, filter: GraphFilter::all("default".into()), scope: GraphScope { namespace: "default".into(),