Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions controller/internal/grpcserver/data_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
}
15 changes: 0 additions & 15 deletions controller/pkg/proto/communication/communication.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
38 changes: 0 additions & 38 deletions controller/test/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 == "" {
Expand Down Expand Up @@ -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")

}
15 changes: 0 additions & 15 deletions worker/communication.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
6 changes: 0 additions & 6 deletions worker/include/worker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, // Завершение работы
Expand All @@ -41,10 +37,8 @@ class Worker {

uint64_t current_config_version = 0;
std::chrono::time_point<std::chrono::steady_clock> last_policy_time;
std::chrono::time_point<std::chrono::steady_clock> last_stats_time;

int64_t policy_interval = MIN_POLICY_TIME;
int64_t stats_interval = MIN_STATS_TIME;

std::atomic<bool> enable{true};
struct net_port *port_in = nullptr;
Expand Down
2 changes: 0 additions & 2 deletions worker/src/worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading