Skip to content

Commit

Permalink
[processor/servicegraph] making cache and expired loop configurable (o…
Browse files Browse the repository at this point in the history
…pen-telemetry#19640)

fix default

Signed-off-by: Jared Tan <[email protected]>
  • Loading branch information
JaredTan95 committed Mar 27, 2023
1 parent ef5bfc7 commit a3a5ace
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 4 deletions.
17 changes: 17 additions & 0 deletions .chloggen/servicegraph-support-cache-loop-time-configurable.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: breaking

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: servicegraphprocessor

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Making cache and expire loop time configurable

# One or more tracking issues related to the change
issues: [19639]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: |
add new config items(cache_loop, store_expiration_loop)
21 changes: 21 additions & 0 deletions processor/servicegraphprocessor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,25 @@ datasources:
version: 1
```

## Configuration

The following settings are required:

- `metrics_exporter`: the name of the exporter that this processor will write metrics to. This exporter **must** be present in a pipeline.
- `latency_histogram_buckets`: the list of durations defining the latency histogram buckets.
- Default: `[2ms, 4ms, 6ms, 8ms, 10ms, 50ms, 100ms, 200ms, 400ms, 800ms, 1s, 1400ms, 2s, 5s, 10s, 15s]`
- `dimensions`: the list of dimensions to add together with the default dimensions defined above.

The following settings can be optionally configured:

- `store` defines the config for the in-memory store used to find requests between services by pairing spans.
- `ttl` - TTL is the time to live for items in the store.
- Default: `2ms`
- `max_items` - MaxItems is the maximum number of items to keep in the store.
- Default: `1000`
- `cache_loop` - the time to cleans the cache periodically
- `store_expiration_loop` the time to expire old entries from the store periodically.

## Example configuration

```yaml
Expand All @@ -117,6 +136,8 @@ processors:
store: # Configuration for the in-memory store
ttl: 2s # Value to wait for an edge to be completed
max_items: 200 # Amount of edges that will be stored in the storeMap
cache_loop: 2m # the time to cleans the cache periodically
store_expiration_loop: 10s # the time to expire old entries from the store periodically.

exporters:
prometheus/servicegraph:
Expand Down
4 changes: 4 additions & 0 deletions processor/servicegraphprocessor/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ type Config struct {

// Store contains the config for the in-memory store used to find requests between services by pairing spans.
Store StoreConfig `mapstructure:"store"`
// CacheLoop is the time to cleans the cache periodically.
CacheLoop time.Duration `mapstructure:"cache_loop"`
// CacheLoop is the time to expire old entries from the store periodically.
StoreExpirationLoop time.Duration `mapstructure:"store_expiration_loop"`
}

type StoreConfig struct {
Expand Down
4 changes: 4 additions & 0 deletions processor/servicegraphprocessor/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ func TestLoadConfig(t *testing.T) {
TTL: time.Second,
MaxItems: 10,
},
CacheLoop: 2 * time.Minute,
StoreExpirationLoop: 10 * time.Second,
},
cfg.Processors[component.NewID(typeStr)],
)
Expand All @@ -72,6 +74,8 @@ func TestLoadConfig(t *testing.T) {
TTL: time.Second,
MaxItems: 10,
},
CacheLoop: time.Minute,
StoreExpirationLoop: 2 * time.Second,
},
cfg.Connectors[component.NewID(typeStr)],
)
Expand Down
2 changes: 2 additions & 0 deletions processor/servicegraphprocessor/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ func createDefaultConfig() component.Config {
TTL: 2 * time.Second,
MaxItems: 1000,
},
CacheLoop: time.Minute,
StoreExpirationLoop: 2 * time.Second,
}
}

Expand Down
13 changes: 9 additions & 4 deletions processor/servicegraphprocessor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ func newProcessor(logger *zap.Logger, config component.Config) *serviceGraphProc
bounds = mapDurationsToMillis(pConfig.LatencyHistogramBuckets)
}

if pConfig.CacheLoop <= 0 {
pConfig.CacheLoop = time.Minute
}

if pConfig.StoreExpirationLoop <= 0 {
pConfig.StoreExpirationLoop = 2 * time.Second
}
return &serviceGraphProcessor{
config: pConfig,
logger: logger,
Expand Down Expand Up @@ -127,11 +134,9 @@ func (p *serviceGraphProcessor) Start(_ context.Context, host component.Host) er
}
}

// TODO: Consider making this configurable.
go p.cacheLoop(time.Minute)
go p.cacheLoop(p.config.CacheLoop)

// TODO: Consider making this configurable.
go p.storeExpirationLoop(2 * time.Second)
go p.storeExpirationLoop(p.config.StoreExpirationLoop)

if p.tracesConsumer == nil {
p.logger.Info("Started servicegraphconnector")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ processors:
store:
ttl: 1s
max_items: 10
cache_loop: 2m
store_expiration_loop: 10s

service:
pipelines:
Expand Down

0 comments on commit a3a5ace

Please sign in to comment.