Skip to content

Commit

Permalink
Remove the weird RetryCnt and RetryDelay from services as unused
Browse files Browse the repository at this point in the history
  • Loading branch information
tjayrush committed Jan 1, 2025
1 parent 0d78238 commit 5500d6d
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 160 deletions.
8 changes: 0 additions & 8 deletions book/src/user_man/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,11 @@ services:
enabled: true
sleep: 60 # Time (in seconds) between scraping operations
batch_size: 500 # Number of blocks processed in each batch (50-10,000)
retry_cnt: 3 # Number of retries for failed operations
retry_delay: 10 # Delay (in seconds) between retries
- name: "monitor"
enabled: true
sleep: 60 # Time (in seconds) between updates
batch_size: 500 # Number of blocks processed in each batch (50-10,000)
retry_cnt: 3 # Number of retries for failed operations
retry_delay: 10 # Delay (in seconds) between retries
- name: "ipfs"
enabled: true
Expand Down Expand Up @@ -146,8 +142,6 @@ Defines various services provided by Khedra. Supported services:
- **Scraper** and **Monitor**:
- **`sleep`**: Duration (seconds) between operations.
- **`batch_size`**: Number of blocks to process in each operation (50-10,000).
- **`retry_cnt`**: Number of retry attempts for failures.
- **`retry_delay`**: Time (seconds) between retries.
- **IPFS**:
- Requires `port` to be specified.

Expand Down Expand Up @@ -186,8 +180,6 @@ The configuration file and environment variables are validated on load with the
- `port`: For API and IPFS services, must be between 1024 and 65535.
- `sleep`: Must be non-negative.
- `batch_size`: Must be between 50 and 10,000.
- `retry_cnt`: Must be at least 1.
- `retry_delay`: Must be at least 1.
### Logging
Expand Down
4 changes: 0 additions & 4 deletions config.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,11 @@ services:
enabled: true
sleep: 60 # In seconds
batch_size: 500
retry_cnt: 3
retry_delay: 10 # In seconds

- name: "monitor"
enabled: true
sleep: 60 # In seconds
batch_size: 500
retry_cnt: 3
retry_delay: 10 # In seconds

- name: "ipfs"
enabled: true
Expand Down
32 changes: 13 additions & 19 deletions pkg/config/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,28 @@ package config
import "log"

type Service struct {
Name string `koanf:"name" validate:"required,oneof=api scraper monitor ipfs"` // Must be non-empty
Enabled bool `koanf:"enabled"` // Defaults to false if not specified
Port int `koanf:"port,omitempty" validate:"opt_min=1024,opt_max=65535"` // Must be between 1024 and 65535
Sleep int `koanf:"sleep,omitempty"` // Must be non-negative
BatchSize int `koanf:"batch_size,omitempty" validate:"opt_min=50,opt_max=10000"` // Must be between 50 and 10000
RetryCnt int `koanf:"retry_cnt,omitempty"` // Must be at least 1
RetryDelay int `koanf:"retry_delay,omitempty"` // Must be at least 1
Name string `koanf:"name" validate:"required,oneof=api scraper monitor ipfs"` // Must be non-empty
Enabled bool `koanf:"enabled"` // Defaults to false if not specified
Port int `koanf:"port,omitempty" validate:"opt_min=1024,opt_max=65535"` // Must be between 1024 and 65535
Sleep int `koanf:"sleep,omitempty"` // Must be non-negative
BatchSize int `koanf:"batch_size,omitempty" validate:"opt_min=50,opt_max=10000"` // Must be between 50 and 10000
}

func NewService(serviceType string) Service {
switch serviceType {
case "scraper":
return Service{
Name: "scraper",
Enabled: false,
Sleep: 10,
BatchSize: 500,
RetryCnt: 3,
RetryDelay: 3,
Name: "scraper",
Enabled: false,
Sleep: 10,
BatchSize: 500,
}
case "monitor":
return Service{
Name: "monitor",
Enabled: false,
Sleep: 12,
BatchSize: 500,
RetryCnt: 3,
RetryDelay: 3,
Name: "monitor",
Enabled: false,
Sleep: 12,
BatchSize: 500,
}
case "api":
return Service{
Expand Down
162 changes: 39 additions & 123 deletions pkg/config/structs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,43 +153,21 @@ func TestServiceValidation(t *testing.T) {
},
wantErr: false,
},
{
name: "Valid Service with RetryCnt unset (0)",
service: Service{
Name: "api",
Port: 8080,
RetryCnt: 0, // Optional, no validation
},
wantErr: false,
},
{
name: "Valid Service with RetryDelay unset (0)",
service: Service{
Name: "api",
Port: 8080,
RetryDelay: 0, // Optional, no validation
},
wantErr: false,
},
{
name: "Valid Service with BatchSize at min",
service: Service{
Name: "scraper",
BatchSize: 50, // Minimum valid BatchSize
Sleep: 1,
RetryCnt: 1,
RetryDelay: 1,
Name: "scraper",
BatchSize: 50, // Minimum valid BatchSize
Sleep: 1,
},
wantErr: false,
},
{
name: "Valid Service with BatchSize at max",
service: Service{
Name: "scraper",
BatchSize: 10000, // Maximum valid BatchSize
Sleep: 1,
RetryCnt: 1,
RetryDelay: 1,
Name: "scraper",
BatchSize: 10000, // Maximum valid BatchSize
Sleep: 1,
},
wantErr: false,
},
Expand Down Expand Up @@ -252,13 +230,11 @@ func TestServiceValidation(t *testing.T) {
{
name: "Valid Service with all fields set to valid values",
service: Service{
Name: "api",
Enabled: true,
Port: 8080,
Sleep: 5,
BatchSize: 500,
RetryCnt: 3,
RetryDelay: 10,
Name: "api",
Enabled: true,
Port: 8080,
Sleep: 5,
BatchSize: 500,
},
wantErr: false,
},
Expand Down Expand Up @@ -314,56 +290,28 @@ func TestScraperServiceValidation(t *testing.T) {
{
name: "Valid Scraper service with required fields",
service: Service{
Name: "scraper",
Enabled: true,
Sleep: 60,
BatchSize: 500,
RetryCnt: 3,
RetryDelay: 10,
Name: "scraper",
Enabled: true,
Sleep: 60,
BatchSize: 500,
},
wantErr: false,
},
{
name: "Invalid Scraper service without Sleep",
service: Service{
Name: "scraper",
Enabled: true,
BatchSize: 500,
RetryCnt: 3,
RetryDelay: 10,
Name: "scraper",
Enabled: true,
BatchSize: 500,
},
wantErr: true,
},
{
name: "Invalid Scraper service without BatchSize",
service: Service{
Name: "scraper",
Enabled: true,
Sleep: 60,
RetryCnt: 3,
RetryDelay: 10,
},
wantErr: true,
},
{
name: "Invalid Scraper service without RetryCnt",
service: Service{
Name: "scraper",
Enabled: true,
Sleep: 60,
BatchSize: 500,
RetryDelay: 10,
},
wantErr: true,
},
{
name: "Invalid Scraper service without RetryDelay",
service: Service{
Name: "scraper",
Enabled: true,
Sleep: 60,
BatchSize: 500,
RetryCnt: 3,
Name: "scraper",
Enabled: true,
Sleep: 60,
},
wantErr: true,
},
Expand All @@ -386,56 +334,28 @@ func TestMonitorServiceValidation(t *testing.T) {
{
name: "Valid Monitor service with required fields",
service: Service{
Name: "monitor",
Enabled: true,
Sleep: 60,
BatchSize: 500,
RetryCnt: 3,
RetryDelay: 10,
Name: "monitor",
Enabled: true,
Sleep: 60,
BatchSize: 500,
},
wantErr: false,
},
{
name: "Invalid Monitor service without Sleep",
service: Service{
Name: "monitor",
Enabled: true,
BatchSize: 500,
RetryCnt: 3,
RetryDelay: 10,
Name: "monitor",
Enabled: true,
BatchSize: 500,
},
wantErr: true,
},
{
name: "Invalid Monitor service without BatchSize",
service: Service{
Name: "monitor",
Enabled: true,
Sleep: 60,
RetryCnt: 3,
RetryDelay: 10,
},
wantErr: true,
},
{
name: "Invalid Monitor service without RetryCnt",
service: Service{
Name: "monitor",
Enabled: true,
Sleep: 60,
BatchSize: 500,
RetryDelay: 10,
},
wantErr: true,
},
{
name: "Invalid Monitor service without RetryDelay",
service: Service{
Name: "monitor",
Enabled: true,
Sleep: 60,
BatchSize: 500,
RetryCnt: 3,
Name: "monitor",
Enabled: true,
Sleep: 60,
},
wantErr: true,
},
Expand Down Expand Up @@ -490,20 +410,16 @@ func TestServiceListValidation(t *testing.T) {
Port: 8080,
},
{
Name: "scraper",
Enabled: true,
Sleep: 60,
BatchSize: 500,
RetryCnt: 3,
RetryDelay: 10,
Name: "scraper",
Enabled: true,
Sleep: 60,
BatchSize: 500,
},
{
Name: "monitor",
Enabled: true,
Sleep: 60,
BatchSize: 500,
RetryCnt: 3,
RetryDelay: 10,
Name: "monitor",
Enabled: true,
Sleep: 60,
BatchSize: 500,
},
{
Name: "ipfs",
Expand Down
6 changes: 0 additions & 6 deletions pkg/config/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,6 @@ func init() {
if service.BatchSize < 50 || service.BatchSize > 10000 {
sl.ReportError(service.BatchSize, "BatchSize", "batch_size", "invalid_scraper_monitor_batch_size", "")
}
if service.RetryCnt < 1 {
sl.ReportError(service.RetryCnt, "RetryCnt", "retry_cnt", "invalid_scraper_monitor_retry_cnt", "")
}
if service.RetryDelay < 1 {
sl.ReportError(service.RetryDelay, "RetryDelay", "retry_delay", "invalid_scraper_monitor_retry_delay", "")
}
case "ipfs":
// For "ipfs" services, `Port` is required.
if service.Port == 0 {
Expand Down

0 comments on commit 5500d6d

Please sign in to comment.