tyk icon indicating copy to clipboard operation
tyk copied to clipboard

[TT-11217] Improve docs and linter

Open letzya opened this issue 1 year ago • 18 comments

User description

Description

Improve config docs Reorder configs Improve schema linter test in linter passed

~/src/github.com/tykTechnologies/tyk/cli/linter (letz-imporve-config-docs*) » go test                                                                       1 ↵ yaaraletz@Yaaras-MacBook-Pro
PASS
ok      github.com/TykTechnologies/tyk/cli/linter       0.343s

Related Issue

Motivation and Context

How This Has Been Tested

Screenshots (if appropriate)

Types of changes

  • [ ] Bug fix (non-breaking change which fixes an issue)
  • [ ] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to change)
  • [ ] Refactoring or add test (improvements in base code or adds test coverage to functionality)

Checklist

  • [ ] I ensured that the documentation is up to date
  • [ ] I explained why this PR updates go.mod in detail with reasoning why it's required
  • [ ] I would like a code coverage CI quality gate exception and have explained why

Type

enhancement, documentation


Description

  • Updated linter tests to accommodate new valid values for policy_source.
  • Enhanced and reorganized the PoliciesConfig structure in config.go for better clarity and documentation.
  • Updated the JSON schema to include "file" as a valid option for policy_source, aligning with the changes in config.go.

Changes walkthrough

Relevant files
Tests
linter_test.go
Update Linter Tests for Policy Source Validation                 

cli/linter/linter_test.go

  • Updated the expected error message in tests to reflect the new valid
    values for policy_source.
  • +1/-1     
    Enhancement
    config.go
    Enhance and Reorganize Policies Configuration                       

    config/config.go

  • Expanded and clarified documentation for PoliciesConfig fields.
  • Added PolicyPath and PolicyConnectionString fields with detailed
    comments.
  • Updated the AllowExplicitPolicyID field description for clarity.
  • +22/-17 
    schema.json
    Update Schema JSON for Policy Source Options                         

    cli/linter/schema.json

  • Updated the policy_source enum to include "file" as a valid option.
  • +1/-1     

    PR-Agent usage: Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    letzya avatar Feb 01 '24 18:02 letzya

    API Changes

    --- prev.txt	2024-04-17 12:26:48.065857836 +0000
    +++ current.txt	2024-04-17 12:26:44.989866344 +0000
    @@ -5535,30 +5535,35 @@
         functionalities
     
     type PoliciesConfig struct {
    -	// Set this value to `file` to look in the file system for a definition file. Set to `service` to use the Dashboard service.
    +	// Sets the location for the definitions of the policies. Optional vaules are `file`, `service` or `rpc`.
    +	// `file` - to look in the file system of the gateway for a definition file. Used in OSS deployment only.
    +	// `service` - to use Tyk Dashboard to get policy definitions. Used in Pro deployment only.
    +	// `rpc` - to use MDCB service to get policy definitions. Used in Pro deployment only.
     	PolicySource string `json:"policy_source"`
     
    -	// This option is required if `policies.policy_source` is set to `service`.
    -	// Set this to the URL of your Tyk Dashboard installation. The URL needs to be formatted as: http://dashboard_host:port.
    -	PolicyConnectionString string `json:"policy_connection_string"`
    +	// Tyk OSS deployment only
    +	// Used with OSS when `policies.policy_source` is either set to `file` (or an empty string).
    +	// Tyk will load policies from all the JSON files located in the directory defined by `policies.policy_path`.
    +	// With this configuration, policy management through the Gateway API is enabled in the Tyk Gateway.
    +	PolicyPath string `json:"policy_path"`
     
    -	// This option only applies in OSS deployment when the `policies.policy_source` is either set
    -	// to `file` or an empty string. If `policies.policy_path` is not set, then Tyk will load policies
    -	// from the JSON file specified by `policies.policy_record_name`.
    +	// Tyk OSS deployment only
    +	// Used with OSS when `policies.policy_source` is either set to `file` (or an empty string).
    +	// If `policies.policy_path` is not set, then Tyk will load policies from the JSON file specified by `policy_record_name`.
    +	// If `policy_record_name` is not set or is an empty string, the gateway will assume there are no policies to load and continues.
     	PolicyRecordName string `json:"policy_record_name"`
     
    -	// In a Pro installation, Tyk will load Policy IDs and use the internal object-ID as the ID of the policy.
    +	// Tyk Pro deployment only.
    +	// Required when `policies.policy_source` is set to `service`.
    +	// Set this to the URL of your Tyk Dashboard installation. The URL needs to be formatted as: http://dashboard_host:port.
    +	PolicyConnectionString string `json:"policy_connection_string"`
    +
    +	// Tyk Pro deployment only.
    +	// Tyk will load Policy IDs and use the internal object-ID as the ID of the policy.
     	// This is not portable in cases where the data needs to be moved from installation to installation.
    -	//
    -	// If you set this value to `true`, then the id parameter in a stored policy (or imported policy using the Dashboard API), will be used instead of the internal ID.
    -	//
    -	// This option should only be used when moving an installation to a new database.
    +	// If you set this value to `true`, then the id field in a stored policy (or imported policy using the Dashboard API), will be used instead of the internal ID.
    +	// This option is useful only when moving an installation to a new database and you want to retain the same IDs.
     	AllowExplicitPolicyID bool `json:"allow_explicit_policy_id"`
    -	// This option only applies in OSS deployment when the `policies.policy_source` is either set
    -	// to `file` or an empty string. If `policies.policy_path` is set, then Tyk will load policies
    -	// from all the JSON files under the directory specified by the `policies.policy_path` option.
    -	// In this configuration, Tyk Gateway will allow policy management through the Gateway API.
    -	PolicyPath string `json:"policy_path"`
     }
     
     type PortRange struct {
    

    github-actions[bot] avatar Feb 01 '24 18:02 github-actions[bot]

    PR Description updated to latest commit (https://github.com/TykTechnologies/tyk/commit/08e997c706b5a4448df3f40f6178b2a2b2db4c51)

    github-actions[bot] avatar Feb 01 '24 18:02 github-actions[bot]

    :boom: CI tests failed :see_no_evil:

    git-state

    diff --git a/config/config.go b/config/config.go
    index 6d9092b..9f878b3 100644
    --- a/config/config.go
    +++ b/config/config.go
    @@ -76,13 +76,13 @@ type PoliciesConfig struct {
     	PolicySource string `json:"policy_source"`
     
     	// Tyk OSS deployment only
    -	// Used with OSS when `policies.policy_source` is either set to `file` (or an empty string). 
    +	// Used with OSS when `policies.policy_source` is either set to `file` (or an empty string).
     	// Tyk will load policies from all the JSON files located in the directory defined by `policies.policy_path`.
     	// With this configuration, policy management through the Gateway API is enabled in the Tyk Gateway.
     	PolicyPath string `json:"policy_path"`
     
     	// Tyk OSS deployment only
    -	// Used with OSS when `policies.policy_source` is either set to `file` (or an empty string). 
    +	// Used with OSS when `policies.policy_source` is either set to `file` (or an empty string).
     	// If `policies.policy_path` is not set, then Tyk will load policies from the JSON file specified by `policy_record_name`.
     	// If `policy_record_name` is not set or is an empty string, the gateway will assume there are no policies to load and continues.
     	PolicyRecordName string `json:"policy_record_name"`
    

    Please look at the run or in the Checks tab.

    github-actions[bot] avatar Feb 01 '24 18:02 github-actions[bot]

    Sweeping

    Fixing PR: track the progress here.

    I'm currently fixing this PR to address the following:

    [Sweep GHA Fix] The GitHub Actions run failed on 08e997c (master) with the following error logs:
    
    
    
    

    Created Pull Request: https://github.com/TykTechnologies/tyk/pull/6020

    PR Analysis

    • 🎯 Main theme: Improving documentation and linter for configuration
    • 📝 PR summary: This PR improves the documentation in the config.go file and updates the linter test and schema to reflect these changes. The changes mainly involve reordering and elaborating on the PoliciesConfig struct fields.
    • 📌 Type of PR: Documentation
    • 🧪 Relevant tests added: No
    • ⏱️ Estimated effort to review [1-5]: 2, because the changes are mostly related to documentation and minor updates in the linter test and schema.
    • 🔒 Security concerns: No security concerns found

    PR Feedback

    💡 General suggestions: The PR is well-structured and the changes are clearly explained in the documentation. However, it would be beneficial to add tests that validate the new linter rules and ensure that the updated documentation does not mislead the users.

    🤖 Code feedback:
    relevant filecli/linter/linter_test.go
    suggestion      

    Consider adding more test cases to validate the new linter rules, especially for the 'file' option in 'policy_source'. [important]

    relevant linepolicies.policy_source: policies.policy_source must be one of the following: "", "file", "service", "rpc",

    relevant fileconfig/config.go
    suggestion      

    It would be helpful to add more context or examples in the documentation for the 'policy_source' field to make it clear how each option ('file', 'service', 'rpc') affects the behavior of the application. [medium]

    relevant line// Sets the location for the definitions of the policies. Optional vaules are file, service or rpc.


    ✨ Usage guide:

    Overview: The review tool scans the PR code changes, and generates a PR review. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on any PR. When commenting, to edit configurations related to the review tool (pr_reviewer section), use the following template:

    /review --pr_reviewer.some_config1=... --pr_reviewer.some_config2=...
    

    With a configuration file, use the following template:

    [pr_reviewer]
    some_config1=...
    some_config2=...
    
    Utilizing extra instructions

    The review tool can be configured with extra instructions, which can be used to guide the model to a feedback tailored to the needs of your project.

    Be specific, clear, and concise in the instructions. With extra instructions, you are the prompter. Specify the relevant sub-tool, and the relevant aspects of the PR that you want to emphasize.

    Examples for extra instructions:

    [pr_reviewer] # /review #
    extra_instructions="""
    In the 'general suggestions' section, emphasize the following:
    - Does the code logic cover relevant edge cases?
    - Is the code logic clear and easy to understand?
    - Is the code logic efficient?
    ...
    """
    

    Use triple quotes to write multi-line instructions. Use bullet points to make the instructions more readable.

    How to enable\disable automation
    • When you first install PR-Agent app, the default mode for the review tool is:
    pr_commands = ["/review", ...]
    

    meaning the review tool will run automatically on every PR, with the default configuration. Edit this field to enable/disable the tool, or to change the used configurations

    Auto-labels

    The review tool can auto-generate two specific types of labels for a PR:

    • a possible security issue label, that detects possible security issues (enable_review_labels_security flag)
    • a Review effort [1-5]: x label, where x is the estimated effort to review the PR (enable_review_labels_effort flag)
    Extra sub-tools

    The review tool provides a collection of possible feedbacks about a PR. It is recommended to review the possible options, and choose the ones relevant for your use case. Some of the feature that are disabled by default are quite useful, and should be considered for enabling. For example: require_score_review, require_soc2_ticket, and more.

    More PR-Agent commands

    To invoke the PR-Agent, add a comment using one of the following commands:

    • /review: Request a review of your Pull Request.
    • /describe: Update the PR title and description based on the contents of the PR.
    • /improve [--extended]: Suggest code improvements. Extended mode provides a higher quality feedback.
    • /ask <QUESTION>: Ask a question about the PR.
    • /update_changelog: Update the changelog based on the PR's contents.
    • /add_docs 💎: Generate docstring for new components introduced in the PR.
    • /generate_labels 💎: Generate labels for the PR based on the PR's contents.
    • /analyze 💎: Automatically analyzes the PR, and presents changes walkthrough for each component.

    See the tools guide for more details. To list the possible configuration parameters, add a /config comment.

    See the review usage page for a comprehensive guide on using this tool.

    github-actions[bot] avatar Feb 01 '24 18:02 github-actions[bot]

    PR Code Suggestions

    Suggestions                                                                                                                                                         
    enhancement
    Add a test case for an empty policy_source.                     

    Consider adding a test case for when policy_source is an empty string, as it's a valid
    value according to the schema and the error message.

    cli/linter/linter_test.go [78-80]

     {
    -  "BadPolicySource", `{"policies": {"policy_source": "internet"}}`,
    -  `policies.policy_source: policies.policy_source must be one of the following: "", "file", "service", "rpc"`
    +  "EmptyPolicySource", `{"policies": {"policy_source": ""}}`,
    +  ``
     }
     
    
    maintainability
    Use constants for policy_source values.                         

    For better maintainability, consider using constants for the policy_source values
    ("file", "service", "rpc"). This will make it easier to manage these values and <br> reduce <br> the <br> risk <br> of <br> typos <br> in <br> multiple <br> places.

    config/config.go [72-76]

    -// Sets the location for the definitions of the policies. Optional vaules are `file`, `service` or `rpc`.
    +const (
    +  PolicySourceFile = "file"
    +  PolicySourceService = "service"
    +  PolicySourceRPC = "rpc"
    +)
     
    
    possible issue
    Clarify handling of empty policy_source.                        

    The comments for PolicyPath and PolicyRecordName both mention they are used when
    policies.policy_source is set to file or an empty string. However, the code does not
    explicitly handle the empty string case. Ensure that the implementation correctly defaults
    to file when policy_source is an empty string, or update the documentation to reflect
    the actual behavior.

    config/config.go [78-87]

    -// Used with OSS when `policies.policy_source` is either set to `file` (or an empty string).
    +// Used with OSS when `policies.policy_source` is set to `file`. If `policy_source` is an empty string, it defaults to `file`.
     
    
    best practice
    Recommend HTTPS for PolicyConnectionString.                     

    The PolicyConnectionString documentation specifies the format of the URL but does not
    mention if HTTPS is supported or recommended. Considering security best practices, it's
    advisable to explicitly state whether HTTPS is supported and recommended for the
    connection string.

    config/config.go [91-93]

    -// Set this to the URL of your Tyk Dashboard installation. The URL needs to be formatted as: http://dashboard_host:port.
    +// Set this to the URL of your Tyk Dashboard installation. The URL should be formatted as: https://dashboard_host:port. HTTPS is recommended for secure communication.
     
    
    documentation
    Clarify the empty string case for policy_source in the schema.  

    Ensure that the schema validation for policy_source includes all valid options,
    including handling the empty string "" case explicitly in documentation or
    implementation, as it's considered a valid value but might be overlooked.

    cli/linter/schema.json [898-904]

     "enum": [
    -  "",
    +  "", // Represents the default behavior when no policy source is specified.
       "file",
       "service",
       "rpc"
     ]
     
    

    ✨ Usage guide:

    Overview: The improve tool scans the PR code changes, and automatically generates suggestions for improving the PR code. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on a PR. When commenting, to edit configurations related to the improve tool (pr_code_suggestions section), use the following template:

    /improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=...
    

    With a configuration file, use the following template:

    [pr_code_suggestions]
    some_config1=...
    some_config2=...
    
    Enabling\disabling automation

    When you first install the app, the default mode for the improve tool is:

    pr_commands = ["/improve --pr_code_suggestions.summarize=true", ...]
    

    meaning the improve tool will run automatically on every PR, with summarization enabled. Delete this line to disable the tool from running automatically.

    Utilizing extra instructions

    Extra instructions are very important for the improve tool, since they enable to guide the model to suggestions that are more relevant to the specific needs of the project.

    Be specific, clear, and concise in the instructions. With extra instructions, you are the prompter. Specify relevant aspects that you want the model to focus on.

    Examples for extra instructions:

    [pr_code_suggestions] # /improve #
    extra_instructions="""
    Emphasize the following aspects:
    - Does the code logic cover relevant edge cases?
    - Is the code logic clear and easy to understand?
    - Is the code logic efficient?
    ...
    """
    

    Use triple quotes to write multi-line instructions. Use bullet points to make the instructions more readable.

    A note on code suggestions quality
    • While the current AI for code is getting better and better (GPT-4), it's not flawless. Not all the suggestions will be perfect, and a user should not accept all of them automatically.
    • Suggestions are not meant to be simplistic. Instead, they aim to give deep feedback and raise questions, ideas and thoughts to the user, who can then use his judgment, experience, and understanding of the code base.
    • Recommended to use the 'extra_instructions' field to guide the model to suggestions that are more relevant to the specific needs of the project, or use the custom suggestions :gem: tool
    • With large PRs, best quality will be obtained by using 'improve --extended' mode.
    More PR-Agent commands

    To invoke the PR-Agent, add a comment using one of the following commands:

    • /review: Request a review of your Pull Request.
    • /describe: Update the PR title and description based on the contents of the PR.
    • /improve [--extended]: Suggest code improvements. Extended mode provides a higher quality feedback.
    • /ask <QUESTION>: Ask a question about the PR.
    • /update_changelog: Update the changelog based on the PR's contents.
    • /add_docs 💎: Generate docstring for new components introduced in the PR.
    • /generate_labels 💎: Generate labels for the PR based on the PR's contents.
    • /analyze 💎: Automatically analyzes the PR, and presents changes walkthrough for each component.

    See the tools guide for more details. To list the possible configuration parameters, add a /config comment.

    See the improve usage page for a more comprehensive guide on using this tool.

    github-actions[bot] avatar Feb 01 '24 18:02 github-actions[bot]

    API tests result - postgres15-sha256 env: success :white_check_mark: Branch used: refs/pull/6019/merge Commit: 06d2dfc674d44eaf415ca41bd14b1350394c2ef3 Triggered by: pull_request (@letzya) Execution page

    buger avatar Feb 01 '24 19:02 buger

    API tests result - mongo44-sha256 env: success :white_check_mark: Branch used: refs/pull/6019/merge Commit: 06d2dfc674d44eaf415ca41bd14b1350394c2ef3 Triggered by: pull_request (@letzya) Execution page

    buger avatar Feb 01 '24 19:02 buger

    :boom: CI tests failed :see_no_evil:

    git-state

    diff --git a/config/config.go b/config/config.go
    index fc9fd71..e16791b 100644
    --- a/config/config.go
    +++ b/config/config.go
    @@ -76,13 +76,13 @@ type PoliciesConfig struct {
     	PolicySource string `json:"policy_source"`
     
     	// Tyk OSS deployment only
    -	// Used with OSS when `policies.policy_source` is either set to `file` (or an empty string). 
    +	// Used with OSS when `policies.policy_source` is either set to `file` (or an empty string).
     	// Tyk will load policies from all the JSON files located in the directory defined by `policies.policy_path`.
     	// With this configuration, policy management through the Gateway API is enabled in the Tyk Gateway.
     	PolicyPath string `json:"policy_path"`
     
     	// Tyk OSS deployment only
    -	// Used with OSS when `policies.policy_source` is either set to `file` (or an empty string). 
    +	// Used with OSS when `policies.policy_source` is either set to `file` (or an empty string).
     	// If `policies.policy_path` is not set, then Tyk will load policies from the JSON file specified by `policy_record_name`.
     	// If `policy_record_name` is not set or is an empty string, the gateway will assume there are no policies to load and continues.
     	PolicyRecordName string `json:"policy_record_name"`
    

    Please look at the run or in the Checks tab.

    github-actions[bot] avatar Feb 05 '24 22:02 github-actions[bot]

    :boom: CI tests failed :see_no_evil:

    git-state

    diff --git a/config/config.go b/config/config.go
    index fc9fd71..e16791b 100644
    --- a/config/config.go
    +++ b/config/config.go
    @@ -76,13 +76,13 @@ type PoliciesConfig struct {
     	PolicySource string `json:"policy_source"`
     
     	// Tyk OSS deployment only
    -	// Used with OSS when `policies.policy_source` is either set to `file` (or an empty string). 
    +	// Used with OSS when `policies.policy_source` is either set to `file` (or an empty string).
     	// Tyk will load policies from all the JSON files located in the directory defined by `policies.policy_path`.
     	// With this configuration, policy management through the Gateway API is enabled in the Tyk Gateway.
     	PolicyPath string `json:"policy_path"`
     
     	// Tyk OSS deployment only
    -	// Used with OSS when `policies.policy_source` is either set to `file` (or an empty string). 
    +	// Used with OSS when `policies.policy_source` is either set to `file` (or an empty string).
     	// If `policies.policy_path` is not set, then Tyk will load policies from the JSON file specified by `policy_record_name`.
     	// If `policy_record_name` is not set or is an empty string, the gateway will assume there are no policies to load and continues.
     	PolicyRecordName string `json:"policy_record_name"`
    

    Please look at the run or in the Checks tab.

    github-actions[bot] avatar Feb 06 '24 07:02 github-actions[bot]

    :boom: CI tests failed :see_no_evil:

    git-state

    diff --git a/config/config.go b/config/config.go
    index fc9fd71..e16791b 100644
    --- a/config/config.go
    +++ b/config/config.go
    @@ -76,13 +76,13 @@ type PoliciesConfig struct {
     	PolicySource string `json:"policy_source"`
     
     	// Tyk OSS deployment only
    -	// Used with OSS when `policies.policy_source` is either set to `file` (or an empty string). 
    +	// Used with OSS when `policies.policy_source` is either set to `file` (or an empty string).
     	// Tyk will load policies from all the JSON files located in the directory defined by `policies.policy_path`.
     	// With this configuration, policy management through the Gateway API is enabled in the Tyk Gateway.
     	PolicyPath string `json:"policy_path"`
     
     	// Tyk OSS deployment only
    -	// Used with OSS when `policies.policy_source` is either set to `file` (or an empty string). 
    +	// Used with OSS when `policies.policy_source` is either set to `file` (or an empty string).
     	// If `policies.policy_path` is not set, then Tyk will load policies from the JSON file specified by `policy_record_name`.
     	// If `policy_record_name` is not set or is an empty string, the gateway will assume there are no policies to load and continues.
     	PolicyRecordName string `json:"policy_record_name"`
    

    Please look at the run or in the Checks tab.

    github-actions[bot] avatar Feb 08 '24 16:02 github-actions[bot]

    /describe

    letzya avatar Apr 17 '24 12:04 letzya

    @letzya Sorry, but I do not understand!

    tykbot[bot] avatar Apr 17 '24 12:04 tykbot[bot]

    @letzya Sorry, but I do not understand!

    tykbot[bot] avatar Apr 17 '24 12:04 tykbot[bot]

    PR Description updated to latest commit (https://github.com/TykTechnologies/tyk/commit/a9d1b716cd4bf8c079289c84bc5f45e2cfbef02a)

    github-actions[bot] avatar Apr 17 '24 12:04 github-actions[bot]

    PR Description updated to latest commit (https://github.com/TykTechnologies/tyk/commit/a9d1b716cd4bf8c079289c84bc5f45e2cfbef02a)

    github-actions[bot] avatar Apr 17 '24 12:04 github-actions[bot]

    :boom: CI tests failed :see_no_evil:

    git-state

    diff --git a/config/config.go b/config/config.go
    index f7e0ac3..a763570 100644
    --- a/config/config.go
    +++ b/config/config.go
    @@ -79,13 +79,13 @@ type PoliciesConfig struct {
     	PolicySource string `json:"policy_source"`
     
     	// Tyk OSS deployment only
    -	// Used with OSS when `policies.policy_source` is either set to `file` (or an empty string). 
    +	// Used with OSS when `policies.policy_source` is either set to `file` (or an empty string).
     	// Tyk will load policies from all the JSON files located in the directory defined by `policies.policy_path`.
     	// With this configuration, policy management through the Gateway API is enabled in the Tyk Gateway.
     	PolicyPath string `json:"policy_path"`
     
     	// Tyk OSS deployment only
    -	// Used with OSS when `policies.policy_source` is either set to `file` (or an empty string). 
    +	// Used with OSS when `policies.policy_source` is either set to `file` (or an empty string).
     	// If `policies.policy_path` is not set, then Tyk will load policies from the JSON file specified by `policy_record_name`.
     	// If `policy_record_name` is not set or is an empty string, the gateway will assume there are no policies to load and continues.
     	PolicyRecordName string `json:"policy_record_name"`
    

    Please look at the run or in the Checks tab.

    github-actions[bot] avatar Apr 17 '24 12:04 github-actions[bot]

    @titpetric could you please review

    letzya avatar Apr 17 '24 13:04 letzya