-
Notifications
You must be signed in to change notification settings - Fork 812
Support syslog rate limit configuration for containers and host #2454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
saiarcot895
merged 6 commits into
sonic-net:master
from
Junchao-Mellanox:syslog-rate-limit-containercfgd
Dec 7, 2022
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
238bd67
Support syslog rate limit configuration for containers and host
Junchao-Mellanox 8b1b250
Fix LGTM
Junchao-Mellanox 60d0c4c
Fix unit test issue
Junchao-Mellanox 8018f6b
Add syslog_util as a package
Junchao-Mellanox d2aead9
Fix review comment
Junchao-Mellanox e23305a
Update feature.py
Junchao-Mellanox File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import click | ||
|
|
||
|
|
||
| FEATURE_TABLE = "FEATURE" | ||
| SYSLOG_CONFIG_TABLE = 'SYSLOG_CONFIG' | ||
| SYSLOG_CONFIG_GLOBAL_KEY = 'GLOBAL' | ||
| SYSLOG_CONFIG_FEATURE_TABLE = 'SYSLOG_CONFIG_FEATURE' | ||
|
|
||
| SYSLOG_RATE_LIMIT_INTERVAL = 'rate_limit_interval' | ||
| SYSLOG_RATE_LIMIT_BURST = 'rate_limit_burst' | ||
| SUPPORT_RATE_LIMIT = 'support_syslog_rate_limit' | ||
|
|
||
|
|
||
| def rate_limit_validator(interval, burst): | ||
| """Validate input interval/burst | ||
|
|
||
| Args: | ||
| interval (int): Rate limit interval | ||
| burst (int): Rate limit burst | ||
| """ | ||
| if interval is None and burst is None: | ||
| raise click.UsageError('Either interval or burst must be configured') | ||
|
|
||
|
|
||
| def service_validator(feature_data, service_name): | ||
| """Validate input service name | ||
|
|
||
| Args: | ||
| db (obj): db object | ||
Junchao-Mellanox marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| service_name (str): service name | ||
| """ | ||
| if service_name not in feature_data: | ||
Junchao-Mellanox marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| valid_service_names = ','.join(feature_data.keys()) | ||
| raise click.ClickException(f'Invalid service name {service_name}, please choose from: {valid_service_names}') | ||
|
|
||
| service_data = feature_data[service_name] | ||
|
|
||
| support_rate_limit = service_data.get(SUPPORT_RATE_LIMIT, '').lower() == 'true' | ||
| if not support_rate_limit: | ||
| raise click.ClickException(f'Service {service_name} does not support syslog rate limit configuration') | ||
|
|
||
|
|
||
| def save_rate_limit_to_db(db, service_name, interval, burst, log): | ||
| """Save rate limit configuration to DB | ||
|
|
||
| Args: | ||
| db (object): db object | ||
| service_name (str): service name. None means config for host. | ||
| interval (int): rate limit interval | ||
| burst (int): rate limit burst | ||
| log (obj): log object | ||
| """ | ||
| if service_name is None: | ||
| service_name = 'host' | ||
| table = SYSLOG_CONFIG_TABLE | ||
| key = SYSLOG_CONFIG_GLOBAL_KEY | ||
| else: | ||
| table = SYSLOG_CONFIG_FEATURE_TABLE | ||
| key = service_name | ||
|
|
||
| if interval == 0 or burst == 0: | ||
| msg = f'Disable syslog rate limit for {service_name}' | ||
| click.echo(msg) | ||
| log.log_notice(msg) | ||
| interval = 0 | ||
| burst = 0 | ||
|
|
||
| data = {} | ||
| if interval is not None: | ||
| data[SYSLOG_RATE_LIMIT_INTERVAL] = interval | ||
| if burst is not None: | ||
| data[SYSLOG_RATE_LIMIT_BURST] = burst | ||
| db.cfgdb.mod_entry(table, key, data) | ||
Junchao-Mellanox marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| log.log_notice(f"Configured syslog {service_name} rate-limits: interval={data.get(SYSLOG_RATE_LIMIT_INTERVAL, 'N/A')},\ | ||
| burst={data.get(SYSLOG_RATE_LIMIT_BURST, 'N/A')}") | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.