Skip to content

Commit

Permalink
Merge pull request #23 from ex0rcist/iter25
Browse files Browse the repository at this point in the history
Инкремент №25
  • Loading branch information
ex0rcist authored Dec 3, 2024
2 parents ecc73c5 + d5b7ab1 commit 3afa308
Show file tree
Hide file tree
Showing 80 changed files with 6,587 additions and 3,366 deletions.
2 changes: 2 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go 1.22.9
golang 1.22.9
22 changes: 20 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ SERVER_VERSION ?= 0.1.0
BUILD_DATE ?= $(shell date +%F\ %H:%M:%S)
BUILD_COMMIT ?= $(shell git rev-parse --short HEAD)

PROTO_SRC = api/proto
PROTO_FILES = health metrics
PROTO_DST = pkg/grpcapi

help: ## display this help screen
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: help
Expand All @@ -26,7 +30,7 @@ agent: ## build agent

server: ## build server
rm -rf $(API_DOCS)
swag init -g ./internal/httpserver/router.go --output docs/api
swag init -g ./internal/httpserver/backend.go --output docs/api

go build \
-ldflags "\
Expand Down Expand Up @@ -57,4 +61,18 @@ godoc: ### show public packages documentation using godoc
@echo "Project documentation is available at:"
@echo "http://127.0.0.1:3000/pkg/github.com/ex0rcist/metflix/pkg/\n"
@godoc -http=:3000 -play
.PHONY: godoc
.PHONY: godoc

proto: $(PROTO_FILES) ## generate gRPC protobuf bindings
.PHONY: proto

$(PROTO_FILES): %: $(PROTO_DST)/%

$(PROTO_DST)/%:
protoc \
--proto_path=$(PROTO_SRC) \
--go_out=$(PROTO_DST) \
--go_opt=paths=source_relative \
--go-grpc_out=$(PROTO_DST) \
--go-grpc_opt=paths=source_relative \
$(PROTO_SRC)/$(notdir $@).proto
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ $ make godoc
-k, --secret string a key to sign outgoing data
-f, --store-file string path to file to store metrics
-i, --store-interval int interval (s) for dumping metrics to the disk
-t, --trusted-subnet ipNet trusted subnet in CIDR notation
```

### Переменные окружения сервера
Expand All @@ -73,6 +74,12 @@ $ make godoc
# Адрес и порт для http-api:
export ADDRESS=0.0.0.0:8080

# Адрес и порт для grpc-api:
export GRPC_ADDRESS=0.0.0.0:8080

# Доверенная подсеть в CIDR нотации (по умолчанию не задана).
export TRUSTED_SUBNET=

# Интервал времени в секундах для сохранения метрик на диск
# (значение 0 — делает запись синхронной):
export STORE_INTERVAL=300
Expand Down Expand Up @@ -115,11 +122,12 @@ export CONFIG=

-a, --address string address:port for HTTP API requests (default "0.0.0.0:8080")
-c, --config string path to configuration file in JSON format
--crypto-key string path to public key to encrypt agent -> server communications
--crypto-key string path to public key to encrypt agent -> server communications
-p, --poll-interval int interval (s) for polling stats (default 2)
-l, --rate-limit int number of max simultaneous requests to server (default -1)
-r, --report-interval int interval (s) for polling stats (default 10)
-k, --secret string a key to sign outgoing data
-t, --transport string transport to use: http/grpc (default "http")
```

### Переменные окружения агента
Expand Down
10 changes: 10 additions & 0 deletions api/proto/health.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
syntax = "proto3";

package metflix.v1;
option go_package = "github.com/ex0rcist/metflix/grpcapi";

import "google/protobuf/empty.proto";

service Health {
rpc Ping(google.protobuf.Empty) returns (google.protobuf.Empty);
}
30 changes: 30 additions & 0 deletions api/proto/metrics.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
syntax = "proto3";

package metflix.v1;

option go_package = "github.com/ex0rcist/metflix/grpcapi";

message MetricExchange {
string id = 1;
string mtype = 2;
int64 delta = 3;
double value = 4;
string hash = 5;
}

message BatchUpdateRequest {
repeated MetricExchange data = 1;
}

message BatchUpdateEncryptedRequest {
bytes encrypted_data = 1;
}

message BatchUpdateResponse {
repeated MetricExchange data = 1;
}

service Metrics {
rpc BatchUpdate(BatchUpdateRequest) returns (BatchUpdateResponse);
rpc BatchUpdateEncrypted(BatchUpdateEncryptedRequest) returns (BatchUpdateResponse);
}
Binary file modified cmd/staticlint/staticlint
Binary file not shown.
2 changes: 1 addition & 1 deletion config/server.example.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"address": "localhost:8080",
"grpc_address": "localhost:50051",
"restore": true,
"store_interval": 1,
"store_file": "./metflix.db",

"crypto_key": "./example_key.pem"
}
Loading

0 comments on commit 3afa308

Please sign in to comment.