diff --git a/controller/internal/grpcserver/data_server.go b/controller/internal/grpcserver/data_server.go index 15ddc7e..98ddae7 100644 --- a/controller/internal/grpcserver/data_server.go +++ b/controller/internal/grpcserver/data_server.go @@ -9,7 +9,6 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" "google.golang.org/protobuf/proto" - "google.golang.org/protobuf/types/known/emptypb" "github.com/moevm/grpc_server/internal/service/service" ) @@ -108,9 +107,3 @@ func (s *DataServer) Classify(ctx context.Context, req *pb.ClassifyRequest) (*pb TrustLevel: 0, }, nil } - -func (s *DataServer) SendStats(ctx context.Context, report *pb.StatsReport) (*emptypb.Empty, error) { - log.Printf("gRPC Stats from worker %d: blocked=%d allowed=%d", - report.WorkerId, report.TotalBlocked, report.TotalAllowed) - return &emptypb.Empty{}, nil -} diff --git a/controller/pkg/proto/communication/communication.proto b/controller/pkg/proto/communication/communication.proto index 204d318..5a2fddb 100644 --- a/controller/pkg/proto/communication/communication.proto +++ b/controller/pkg/proto/communication/communication.proto @@ -6,7 +6,6 @@ import "google/protobuf/empty.proto"; service DataService { rpc GetPolicy(GetPolicyRequest) returns (GetPolicyResponse); rpc Classify(ClassifyRequest) returns (ClassifyResponse); - rpc SendStats(StatsReport) returns (google.protobuf.Empty); } message GetPolicyRequest { @@ -49,17 +48,3 @@ message ClassifyResponse { repeated string categories = 1; int32 trust_level = 2; } - -message ResourceStats { - string domain = 1; - uint64 blocked = 2; - uint64 allowed = 3; -} - -message StatsReport { - uint64 worker_id = 1; - uint64 time = 2; - uint64 total_blocked = 3; - uint64 total_allowed = 4; - repeated ResourceStats resources = 5; -} \ No newline at end of file diff --git a/controller/test/worker_test.go b/controller/test/worker_test.go index 87120bf..40cf78d 100644 --- a/controller/test/worker_test.go +++ b/controller/test/worker_test.go @@ -12,7 +12,6 @@ import ( pb "github.com/moevm/grpc_server/pkg/proto/communication" "github.com/stretchr/testify/assert" "google.golang.org/grpc" - "google.golang.org/protobuf/types/known/emptypb" ) type MockController struct { @@ -37,11 +36,6 @@ func (m *MockController) Classify(ctx context.Context, req *pb.ClassifyRequest) }, nil } -func (m *MockController) SendStats(ctx context.Context, req *pb.StatsReport) (*emptypb.Empty, error) { - m.t.Logf("SendStats called: worker_id=%d", req.WorkerId) - return &emptypb.Empty{}, nil -} - func StartMockController(t *testing.T, policy *pb.WorkerPolicy) (string, func()) { listenAddr := os.Getenv("TEST_CONTROLLER_ADDR") if listenAddr == "" { @@ -174,35 +168,3 @@ func TestWorkerClassify(t *testing.T) { assert.NoError(t, err, "Worker failed: %s", string(output)) assert.Contains(t, outputStr, "Target 'example.com' classified as categories [news, technology] with trust level 3") } - -func TestWorkerSendStats(t *testing.T) { - root := findProjectRoot() - workerBin := filepath.Join(root, "worker", "bazel-bin", "worker") - - if _, err := os.Stat(workerBin); err != nil { - t.Skipf("Worker binary not found: %v", err) - } - - addr, cleanup := StartMockController(t, nil) - defer cleanup() - - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - defer cancel() - - worker := exec.CommandContext(ctx, workerBin) - worker.Env = []string{ - "WORKER_ID=1", - "CONTROLLER_GRPC_ADDR=" + addr, - "METRICS_GATEWAY_ADDRESS=localhost", - "METRICS_GATEWAY_PORT=9091", - "TEST_STATS=true", - } - - output, err := worker.CombinedOutput() - assert.NoError(t, err, "Worker failed: %s", string(output)) - - outputStr := string(output) - - assert.Contains(t, outputStr, "Stats sent successfully") - -} diff --git a/worker/communication.proto b/worker/communication.proto index 9ad73f9..5a2fddb 100644 --- a/worker/communication.proto +++ b/worker/communication.proto @@ -6,7 +6,6 @@ import "google/protobuf/empty.proto"; service DataService { rpc GetPolicy(GetPolicyRequest) returns (GetPolicyResponse); rpc Classify(ClassifyRequest) returns (ClassifyResponse); - rpc SendStats(StatsReport) returns (google.protobuf.Empty); } message GetPolicyRequest { @@ -49,17 +48,3 @@ message ClassifyResponse { repeated string categories = 1; int32 trust_level = 2; } - -message ResourceStats { - string domain = 1; - uint64 blocked = 2; - uint64 allowed = 3; -} - -message StatsReport { - uint64 worker_id = 1; - uint64 time = 2; - uint64 total_blocked = 3; - uint64 total_allowed = 4; - repeated ResourceStats resources = 5; -} diff --git a/worker/include/worker.hpp b/worker/include/worker.hpp index b0d5740..7516a0a 100644 --- a/worker/include/worker.hpp +++ b/worker/include/worker.hpp @@ -27,10 +27,6 @@ extern "C" { #define MIN_POLICY_TIME 30 #define MAX_POLICY_TIME 45 -#define EXPECTED_STATS_TIME 60 -#define MIN_STATS_TIME 30 -#define MAX_STATS_TIME 45 - enum class WorkerState { FREE, // Ожидает задачи SHUTTING_DOWN, // Завершение работы @@ -41,10 +37,8 @@ class Worker { uint64_t current_config_version = 0; std::chrono::time_point last_policy_time; - std::chrono::time_point last_stats_time; int64_t policy_interval = MIN_POLICY_TIME; - int64_t stats_interval = MIN_STATS_TIME; std::atomic enable{true}; struct net_port *port_in = nullptr; diff --git a/worker/src/worker.cpp b/worker/src/worker.cpp index 4cdea6e..c6d4526 100644 --- a/worker/src/worker.cpp +++ b/worker/src/worker.cpp @@ -414,8 +414,6 @@ void Worker::MainLoop() { using namespace std::chrono; last_policy_time = steady_clock::now(); - last_stats_time = steady_clock::now(); - last_metrics_push_time = steady_clock::now(); struct rte_mbuf *pkts[32]; uint16_t nb_pkts = 32;