Skip to content

Commit

Permalink
Merge pull request #383 from avenga/refine-ulimits
Browse files Browse the repository at this point in the history
Simplify/reduce ulimit info to file descriptors
  • Loading branch information
Marcel Ludwig authored Nov 17, 2021
2 parents e0a7df1 + a7e31c2 commit d2b26b8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 23 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Unreleased changes are available as `avenga/couper:edge` container.
* **Added**
* Register `default` function as `coalesce` alias ([#356](https://github.com/avenga/couper/pull/356))
* New HCL function [`relative_url()`](./docs/REFERENCE.md#functions) ([#361](https://github.com/avenga/couper/pull/361))
* Log system resource limits at startup ([#334](https://github.com/avenga/couper/pull/334))
* Log file descriptor limit at startup ([#383](https://github.com/avenga/couper/pull/383))

* **Changed**
* [`server` block](./docs/REFERENCE.md#server-block) label is now optional, [`api` block](./docs/REFERENCE.md#api-block) may be labelled ([#358](https://github.com/avenga/couper/pull/358))
Expand Down
30 changes: 8 additions & 22 deletions command/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,28 +88,14 @@ func (a AcceptForwardedValue) Set(s string) error {
}

func (r *Run) Execute(args Args, config *config.Couper, logEntry *logrus.Entry) error {
rlimits := map[string]int{
"RLIMIT CPU": syscall.RLIMIT_CPU,
"RLIMIT Data": syscall.RLIMIT_DATA,
"RLIMIT CORE": syscall.RLIMIT_CORE,
"RLIMIT AS": syscall.RLIMIT_AS,
"RLIMIT Stack": syscall.RLIMIT_STACK,
"RLIMIT FSIZE": syscall.RLIMIT_FSIZE,
"RLIMIT Nofile": syscall.RLIMIT_NOFILE,
}
for key, value := range rlimits {
lim := syscall.Rlimit{}
err := syscall.Getrlimit(value, &lim)
if err != nil {
logEntry.Infof("an error occured while retrieving '%s'", key)
continue
}
if lim.Cur < 4096 {
logEntry.Warnf("%s Current: %d, %s Max: %d", key, lim.Cur, key, lim.Max)
continue
}
logEntry.Infof("%s Current: %d, %s Max: %d", key, lim.Cur, key, lim.Max)
lim := syscall.Rlimit{}
err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &lim)
if err != nil {
logEntry.Warnf("ulimit: error retrieving file descriptor limit")
} else {
logEntry.Infof("ulimit: max open files: %d (hard limit: %d)", lim.Cur, lim.Max)
}

r.settingsMu.Lock()
*r.settings = *config.Settings
r.settingsMu.Unlock()
Expand All @@ -131,7 +117,7 @@ func (r *Run) Execute(args Args, config *config.Couper, logEntry *logrus.Entry)

// Some remapping due to flag set pre-definition
env.Decode(r.settings)
err := r.settings.SetAcceptForwarded()
err = r.settings.SetAcceptForwarded()
if err != nil {
return err
}
Expand Down

0 comments on commit d2b26b8

Please sign in to comment.