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

Hera otel integration #402

Merged
merged 3 commits into from
Dec 7, 2024
Merged

Conversation

rasamala83
Copy link
Collaborator

No description provided.

Copy link
Collaborator

@ishi-0987 ishi-0987 left a comment

Choose a reason for hiding this comment

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

Looks good to me

Detailed conversation has happened on the code. Feedbacks have been discussed and addressed.
The code functionality is One box tested.

@rasamala83
Copy link
Collaborator Author

@CodiumAI-Agent /review

@CodiumAI-Agent
Copy link

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Possible Bug
The error handling in the StartMetricsCollection function may not properly handle the case where hostname fetching fails, potentially leading to uninitialized variables being used.

Error Handling
In the StartMetricsCollection function, the error from os.Hostname() is not checked immediately, which might lead to using an uninitialized hostname if an error occurs.

Concurrency Issue
The usage of sync.Once for registerStateMetrics may not be safe if StartMetricsCollection is called from multiple goroutines, as the initialization of metricsStateLogger and totalConnectionStateDataLogger involves non-thread-safe operations.

Resource Leak
In the StopMetricCollection function, the channels (doneCh and stopPublish) are not always properly closed when exiting the goroutines, which could potentially lead to goroutine leaks.

Inefficient Data Handling
The AddDataPointToOTELStateDataChan and AddDataPointToTotalConnectionsDataChannel functions use a select statement with a timeout for sending data, which might drop data points if the channel is full. Consider handling backpressure more gracefully or increasing channel size.

@rasamala83
Copy link
Collaborator Author

@CodiumAI-Agent /describe

@CodiumAI-Agent
Copy link

Title

Hera otel integration


PR Type

Enhancement, Tests


Description

  • Integrated OpenTelemetry (OTEL) for metrics collection and logging in the application.
  • Added OTEL SDK initialization with support for GRPC and HTTP exporters.
  • Implemented state logger for capturing worker states and connection metrics.
  • Enhanced configuration to support OTEL settings like TLS, retry, and custom endpoints.
  • Added extensive unit and integration tests for OTEL functionality, including sharding and error scenarios.
  • Introduced mock OTEL collector for testing and validation.
  • Verified OTEL metrics publishing, dimensions, and error handling.

Changes walkthrough 📝

Relevant files
Enhancement
5 files
state_logger.go
Implement OTEL state logger for metrics collection.           

utility/logger/otel/state_logger.go

  • Added OpenTelemetry (OTEL) state logger implementation for metrics
    collection.
  • Introduced functions to start and stop metrics collection.
  • Implemented metrics registration and callback mechanisms.
  • Added support for various worker states and connection metrics.
  • +445/-0 
    logger.go
    Add OTEL SDK initialization and exporter configuration.   

    utility/logger/otel/logger.go

  • Added initialization logic for OTEL SDK with support for GRPC and HTTP
    exporters.
  • Configured metric views and resource attributes for OTEL integration.
  • Introduced error handling and shutdown mechanisms for OTEL SDK.
  • +382/-0 
    statelog.go
    Integrate OTEL metrics collection into state logs.             

    lib/statelog.go

  • Integrated OTEL metrics collection into state log generation.
  • Added worker dimension titles and metrics data aggregation.
  • Enabled OTEL initialization and error handling during startup.
  • +85/-32 
    config.go
    Add OTEL configuration initialization and logging.             

    lib/config.go

  • Added OTEL configuration initialization during application startup.
  • Introduced support for custom OTEL settings like TLS and retry.
  • Enabled logging of OTEL-related configurations.
  • +49/-2   
    defs.go
    Define constants and structures for OTEL metrics.               

    utility/logger/otel/defs.go

  • Defined constants and data structures for OTEL metrics.
  • Added support for worker states and connection metrics.
  • Introduced tags and dimensions for OTEL metrics.
  • +171/-0 
    Tests
    8 files
    state_logger_test.go
    Add unit tests for OTEL state logger.                                       

    utility/logger/otel/test/state_logger_test.go

  • Added unit tests for OTEL state logger functionality.
  • Tested metrics collection and data channel operations.
  • Verified OTEL integration with mock collectors.
  • +392/-0 
    mock_collector.go
    Add mock OTEL collector for testing.                                         

    utility/logger/otel/test/mock_collector.go

  • Implemented a mock OTEL collector for testing purposes.
  • Added support for HTTP and GRPC protocols.
  • Enabled metrics storage and retrieval for validation.
  • +341/-0 
    main_test.go
    Add integration tests for OTEL with sharding.                       

    tests/unittest/otel_sharding/main_test.go

  • Added integration tests for OTEL metrics with sharding enabled.
  • Verified shard-specific metrics and dimensions in OTEL logs.
  • Tested OTEL configuration and data publishing.
  • +198/-0 
    main_test.go
    Add basic integration tests for OTEL metrics.                       

    tests/unittest/otel_basic/main_test.go

  • Added basic integration tests for OTEL metrics collection.
  • Verified application-level dimensions and metrics in OTEL logs.
  • Tested OTEL configuration and data publishing.
  • +136/-0 
    main_test.go
    Add tests for OTEL metrics with incorrect endpoint.           

    tests/unittest/otel_incorrect_endpoint/main_test.go

  • Added tests for OTEL metrics with incorrect endpoint configuration.
  • Verified error handling and logging for publishing failures.
  • Ensured CAL logs capture OTEL runtime errors.
  • +119/-0 
    main_test.go
    Add tests for OTEL metrics with CAL skipping.                       

    tests/unittest/otel_with_skip_cal/main_test.go

  • Added tests for OTEL metrics with CAL state log skipping enabled.
  • Verified absence of CAL state logs when skip flag is set.
  • Ensured OTEL metrics are published correctly.
  • +114/-0 
    main_test.go
    Add tests for OTEL shutdown and cleanup.                                 

    tests/unittest/shutdown_cleanup/main_test.go

  • Added tests for OTEL shutdown and cleanup during application
    termination.
  • Verified graceful termination of workers and metrics collection.
  • Ensured proper logging of shutdown events.
  • +110/-0 
    defs.go
    Add OTEL configuration and setup for tests.                           

    tests/unittest/testutil/defs.go

  • Added OTEL configuration and docker setup for testing.
  • Defined YAML configuration for OTEL collector.
  • Enabled log file generation for OTEL metrics.
  • +44/-0   
    Additional files (token-limit)
    10 files
    main.go
    ...                                                                                                           

    lib/main.go

    ...

    +25/-5   
    error_handler.go
    ...                                                                                                           

    utility/logger/otel/error_handler.go

    ...

    +79/-0   
    otelconfig.go
    ...                                                                                                           

    utility/logger/otel/config/otelconfig.go

    ...

    +66/-0   
    workerpool_test.go
    ...                                                                                                           

    lib/workerpool_test.go

    ...

    +3/-1     
    main.go
    ...                                                                                                           

    tests/unittest/testutil/main.go

    ...

    +7/-0     
    allcover.sh
    ...                                                                                                           

    tests/unittest/allcover.sh

    ...

    +1/-1     
    testall.sh
    ...                                                                                                           

    tests/unittest/testall.sh

    ...

    +1/-1     
    go.sum
    ...                                                                                                           

    go.sum

    ...

    +47/-5   
    go.mod
    ...                                                                                                           

    go.mod

    ...

    +21/-2   
    go.yml
    ...                                                                                                           

    .github/workflows/go.yml

    ...

    +2/-2     

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    @shtiencode
    Copy link
    Collaborator

    @CodiumAI-Agent /improve

    @CodiumAI-Agent
    Copy link

    PR Code Suggestions ✨

    No code suggestions found for the PR.

    @ishi-0987
    Copy link
    Collaborator

    @CodiumAI-Agent /optimize

    @rasamala83 rasamala83 merged commit 0be08e2 into paypal:main Dec 7, 2024
    6 of 7 checks passed
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    None yet
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    5 participants