Skip to content
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

enrich network neighbors with DNS data #144

Merged
merged 9 commits into from
Nov 9, 2023
Merged

Conversation

Daniel-GrunbergerCA
Copy link
Contributor

@Daniel-GrunbergerCA Daniel-GrunbergerCA commented Nov 7, 2023

PR Type:

Enhancement


PR Description:

This PR introduces the integration of a DNS tracer into the Network Manager. The main changes include:

  • Addition of a DNS tracer and supporting logic for enriching NetworkNeighbors with DNS data.
  • Refactoring of the network_manager_test.go file to include tests for the DNS enrichment.
  • Modification of the container_watcher.go file to include the DNS manager client.
  • Creation of new files for the DNS manager and its mock version.
  • Changes in the main.go file to create the DNS manager and pass it to the container watcher.
  • Minor adjustments and refactoring in several other files.

PR Main Files Walkthrough:

files:
  • pkg/networkmanager/network_manager.go: Integrated the DNS resolver client into the Network Manager and added logic to enrich network neighbors with DNS data.
  • pkg/containerwatcher/v1/container_watcher.go: Included the DNS manager client in the container watcher.
  • pkg/containerwatcher/v1/dns.go: Created a new file to handle DNS tracing, including starting and stopping the tracer.
  • pkg/containerwatcher/v1/container_watcher_private.go: Added logic to start DNS tracing and Kubernetes resolution.
  • pkg/containerwatcher/dnsmanager/dns_manager.go: Created a new file for the DNS manager, which handles saving network events.
  • pkg/containerwatcher/dnsmanager/dns_manager_mock.go: Created a mock version of the DNS manager for testing purposes.
  • pkg/networkmanager/network_manager_test.go: Refactored the tests to include DNS enrichment.
  • main.go: Created the DNS manager and passed it to the container watcher during initialization.
  • pkg/containerwatcher/v1/network.go: Moved the initialization of Kubernetes resolution to a separate function.
  • pkg/containerwatcher/v1/open_test.go: Adjusted the creation of the container watcher in the test to include the DNS manager.

User Description:

This PR adds a DNS tracer and supports the logic for enriching the NetworkNeighbors with its data

Signed-off-by: Daniel-GrunbergerCA <[email protected]>
Signed-off-by: Daniel-GrunbergerCA <[email protected]>
Signed-off-by: Daniel-GrunbergerCA <[email protected]>
Signed-off-by: Daniel-GrunbergerCA <[email protected]>
Signed-off-by: Daniel-GrunbergerCA <[email protected]>
Signed-off-by: Daniel-GrunbergerCA <[email protected]>
Signed-off-by: Daniel-GrunbergerCA <[email protected]>
Signed-off-by: Daniel-GrunbergerCA <[email protected]>
@codiumai-pr-agent-free codiumai-pr-agent-free bot added the enhancement New feature or request label Nov 7, 2023
Copy link

PR Analysis

  • 🎯 Main theme: Integration of DNS tracer into the Network Manager
  • 📝 PR summary: This PR introduces a DNS tracer into the Network Manager to enrich NetworkNeighbors with DNS data. The PR includes the addition of a DNS tracer, refactoring of tests to include DNS enrichment, and modifications to several files to integrate the DNS manager client. It also includes minor adjustments and refactoring in several other files.
  • 📌 Type of PR: Enhancement
  • 🧪 Relevant tests added: Yes
  • ⏱️ Estimated effort to review [1-5]: 4, due to the complexity of the changes and the need to understand the impact of the DNS tracer integration on the existing codebase.
  • 🔒 Security concerns: No security concerns found

PR Feedback

  • 💡 General suggestions: The PR is well-structured and the changes are logically grouped. The addition of the DNS tracer is a significant enhancement that could improve the functionality of the Network Manager. However, it is important to ensure that the integration of the DNS tracer does not introduce any performance issues or vulnerabilities. It would be beneficial to include performance testing results or benchmarks to demonstrate the impact of these changes on the system's performance.

  • 🤖 Code feedback:

    • relevant file: pkg/networkmanager/network_manager_test.go
      suggestion: Consider adding more test cases to cover possible edge cases and failure scenarios related to DNS resolution. This will help ensure the robustness of the new feature. [important]
      relevant line: '+type dnsResolverMock struct {'

    • relevant file: pkg/networkmanager/network_manager.go
      suggestion: It would be beneficial to handle the case where the DNS resolver client is not available or fails to initialize. This can help prevent potential issues during runtime. [important]
      relevant line: '+dnsResolverClient dnsmanager.DNSResolver'

    • relevant file: pkg/containerwatcher/v1/container_watcher.go
      suggestion: It might be a good idea to add error handling or fallback mechanisms in case the DNS manager client fails to initialize. This can help ensure the stability of the system. [medium]
      relevant line: '+dnsManager dnsmanager.DNSManagerClient'

    • relevant file: main.go
      suggestion: Consider adding logging statements to track the initialization and status of the DNS manager. This can help with debugging and monitoring the system. [medium]
      relevant line: '+dnsManager := dnsmanager.CreateDNSManager(ctx, cfg, k8sClient, storageClient, clusterData.ClusterName)'

How to use

To invoke the PR-Agent, add a comment using one of the following commands:
/review [-i]: Request a review of your Pull Request. For an incremental review, which only considers changes since the last review, include the '-i' option.
/describe: Modify the PR title and description based on the contents of the PR.
/improve [--extended]: Suggest improvements to the code in the PR. Extended mode employs several calls, and provides a more thorough feedback.
/ask <QUESTION>: Pose a question about the PR.
/update_changelog: Update the changelog based on the PR's contents.

To edit any configuration parameter from configuration.toml, add --config_path=new_value
For example: /review --pr_reviewer.extra_instructions="focus on the file: ..."
To list the possible configuration parameters, use the /config command.

@Daniel-GrunbergerCA Daniel-GrunbergerCA added the release Create release label Nov 7, 2023
Copy link

github-actions bot commented Nov 7, 2023

Summary:

  • License scan: success
  • Credentials scan: success
  • Vulnerabilities scan: failure
  • Unit test: success
  • Go linting: failure

Signed-off-by: Daniel-GrunbergerCA <[email protected]>

// DNSManager is used to manage DNS events and save IP resolutions. It exposes an API to resolve IP address to domain name.
type DNSManager struct {
addressToDomainMap maps.SafeMap[string, string] // this map is used to resolve IP address to domain name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to support TTL? in case DNS records change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't it is needed here. Every time I get a new query, it will override the entry on the map. The query will be performed a short time before we handle the network events, so the addresses will be always up-to-date

matthyx
matthyx previously approved these changes Nov 7, 2023
Copy link
Contributor

@matthyx matthyx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks mostly good, feel free to address my comments in a different PR

Copy link

github-actions bot commented Nov 8, 2023

Summary:

  • License scan: success
  • Credentials scan: success
  • Vulnerabilities scan: failure
  • Unit test: success
  • Go linting: failure

@Daniel-GrunbergerCA Daniel-GrunbergerCA merged commit 9b12f91 into main Nov 9, 2023
6 checks passed
@Daniel-GrunbergerCA Daniel-GrunbergerCA deleted the dns-tracer branch November 9, 2023 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request release Create release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants