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

feat: event tracking for work distribution #525

Merged
merged 25 commits into from
Sep 9, 2024

Conversation

teslashibe
Copy link
Contributor

@teslashibe teslashibe commented Aug 22, 2024

Add Event Tracking System and Refactor API Handlers

Overview

This PR introduces a new event tracking system and refactors several API handlers to incorporate this system. It also includes some minor adjustments to improve logging and code organization.

Key Changes

1. New Event Tracking System

  • Introduced a new event package with the following components:
    • EventTracker: Manages event tracking and sending
    • EventClient: Handles sending events to an external API
    • Event: Struct representing individual events
    • Various event types and data sources defined as constants
  • Added configuration options for the event tracking system
  • Implemented methods for tracking different types of events (e.g., work requests, work distribution, work completion)

2. API Refactoring

  • Modified NewAPI function to create and include an EventTracker
  • Updated SearchTweetsProfile, SearchTweetsRecent, and SearchTwitterFollowers handlers to use the new event tracking system
  • Removed several unused handler functions related to sentiment analysis and LLM models

3. Logging Improvements

  • Added debug logging in main.go to set log level to Debug
  • Included more detailed logging in the event tracking system

4. Code Cleanup

  • Removed commented-out code and unused functions
  • Reorganized imports and adjusted code formatting for better readability

Detailed Changes

cmd/masa-node/main.go

  • Set log level to Debug and added a debug log message

pkg/api/api.go

  • Added EventTracker to the API struct
  • Modified NewAPI to create and include an EventTracker
  • Added debug logging for API instance creation

pkg/api/handlers_data.go

  • Updated SearchTweetsProfile, SearchTweetsRecent, and SearchTwitterFollowers to use event tracking
  • Removed unused handlers (e.g., sentiment analysis, LLM-related functions)
  • Simplified and standardized error handling in handlers

pkg/api/routes.go

  • Removed routes for unused handlers (e.g., sentiment analysis, LLM models)

pkg/event/* (new files)

  • Implemented the event tracking system (see "New Event Tracking System" above for details)

Testing

  • Unit tests for the new event tracking system
  • Integration tests for the modified API handlers
  • Manual testing of the affected endpoints

Documentation

  • Update API documentation to reflect changes in available endpoints
  • Add documentation for the new event tracking system and how to use it

Next Steps

  • Consider expanding event tracking to other parts of the application
  • Implement a dashboard or analytics tool to visualize the tracked events
  • Review and potentially refactor other API handlers for consistency

Potential Impacts

  • This change may affect the performance of API calls due to the added event tracking. Monitor response times after deployment.

  • The removal of certain endpoints (e.g., sentiment analysis) may break existing integrations. Ensure all stakeholders are informed of these changes.

  • Yes, I signed my commits.

teslashibe and others added 8 commits August 18, 2024 18:19
- Implement EventTracker for in-memory event management
- Create EventClient for sending events to external API
- Add configuration options with sensible defaults
- Provide convenience methods for common event types
- Integrate logrus for comprehensive error handling and logging
- Ensure thread-safety with mutex locks
- Add error check for nil EventClient
- Log SendEvent errors
- Return SendEvent errors to caller
- Clarify nil EventTracker error message
Copy link

PR description is too short and seems to not fulfill PR template, please fill in

Copy link

⚠ golint failed (.)

Found 212 lint suggestions; failing.

Show Detail
cmd/masa-node-cli/handlers.go:159:10: if block ends with a return statement, so drop this else and outdent its block
cmd/masa-node-cli/handlers.go:185:9: if block ends with a return statement, so drop this else and outdent its block
cmd/masa-node-cli/types.go:10:6: exported type AppConfig should have comment or be unexported
cmd/masa-node-cli/types.go:22:6: exported type Gossip should have comment or be unexported
cmd/masa-node-cli/types.go:27:6: exported type SpeakRequest should have comment or be unexported
cmd/masa-node-cli/types.go:35:6: exported type SubscriptionHandler should have comment or be unexported
cmd/masa-node-cli/types.go:41:6: exported type RadioButtons should have comment or be unexported
cmd/masa-node-cli/types.go:48:6: exported type InputBox should have comment or be unexported
cmd/tagger/main.go:23:1: package comment is detached; there should be no blank lines between it and the package statement
cmd/tagger/main.go:100:1: exported function TagProject should have comment or be unexported
internal/versioning/version.go:4:2: exported var ApplicationVersion should have comment or be unexported
internal/versioning/version.go:6:2: comment on exported var ProtocolVersion should be of the form "ProtocolVersion ..."
pkg/oracle_node.go:42:6: exported type OracleNode should have comment or be unexported
pkg/oracle_node.go:348:6: exported type BlockData should have comment or be unexported
pkg/oracle_node.go:356:6: exported type Blocks should have comment or be unexported
pkg/oracle_node.go:360:6: exported type BlockEvents should have comment or be unexported
pkg/oracle_node.go:362:6: exported type BlockEventTracker should have comment or be unexported
pkg/oracle_node.go:475:1: exported function SubscribeToBlocks should have comment or be unexported
pkg/oracle_node_listener.go:77:6: exported type NodeDataPage should have comment or be unexported
pkg/oracle_node_listener.go:208:2: var remotePeerId should be remotePeerID
pkg/api/api.go:12:6: exported type API should have comment or be unexported
pkg/api/config.go:6:6: type name will be used as api.APIConfig by other packages, and that stutters; consider calling this Config
pkg/api/config.go:11:5: exported var DefaultConfig should have comment or be unexported
pkg/api/handlers_data.go:32:6: exported type LLMChat should have comment or be unexported
pkg/api/handlers_data.go:41:1: exported function IsBase64 should have comment or be unexported
pkg/api/handlers_data.go:366:4: struct field Url should be URL
pkg/api/handlers_data.go:826:4: struct field Url should be URL
pkg/api/handlers_data.go:912:1: exported method API.GetChannelMessagesHandler should have comment or be unexported
pkg/api/handlers_data.go:1058:3: var cfUrl should be cfURL
pkg/api/handlers_node.go:435:17: method GetNodeApiKey should be GetNodeAPIKey
pkg/chain/block.go:13:6: exported type Block should have comment or be unexported
pkg/chain/block.go:21:1: exported method Block.Build should have comment or be unexported
pkg/chain/block.go:30:1: exported method Block.Serialize should have comment or be unexported
pkg/chain/block.go:40:1: exported method Block.Deserialize should have comment or be unexported
pkg/chain/block.go:51:1: exported method Block.Print should have comment or be unexported
pkg/chain/chain.go:13:6: exported type Chain should have comment or be unexported
pkg/chain/chain.go:173:1: exported method Chain.GetBlock should have comment or be unexported
pkg/chain/persistance.go:9:2: exported const KeyLastHash should have comment (or a comment on this block) or be unexported
pkg/chain/persistance.go:12:6: exported type Persistance should have comment or be unexported
pkg/chain/persistance.go:16:6: exported type Serializable should have comment or be unexported
pkg/chain/persistance.go:21:1: exported method Persistance.Init should have comment or be unexported
pkg/chain/persistance.go:74:1: exported method Persistance.Get should have comment or be unexported
pkg/chain/persistance.go:96:1: exported method Persistance.GetLastHash should have comment or be unexported
pkg/chain/persistance.go:100:1: exported method Persistance.SaveBlock should have comment or be unexported
pkg/chain/persistance.go:122:1: exported method Persistance.Iterate should have comment or be unexported
pkg/chain/pos.go:16:6: exported type ProofOfStake should have comment or be unexported
pkg/chain/pos.go:44:1: exported method ProofOfStake.Run should have comment or be unexported
pkg/chain/pos.go:68:1: exported function IsValidPoS should have comment or be unexported
pkg/config/app.go:68:2: struct field RpcUrl should be RPCURL
pkg/config/app.go:70:2: struct field AllowedPeerId should be AllowedPeerID
pkg/config/app.go:85:2: struct field ClaudeApiKey should be ClaudeAPIKey
pkg/config/app.go:86:2: struct field ClaudeApiURL should be ClaudeAPIURL
pkg/config/app.go:87:2: struct field ClaudeApiVersion should be ClaudeAPIVersion
pkg/config/app.go:94:2: struct field LLMChatUrl should be LLMChatURL
pkg/config/app.go:95:2: struct field LLMCfUrl should be LLMCfURL
pkg/config/constants.go:81:2: exported const PrivKeyFile should have comment (or a comment on this block) or be unexported
pkg/config/constants.go:84:2: const RpcUrl should be RPCURL
pkg/config/constants.go:116:2: const ClaudeApiKey should be ClaudeAPIKey
pkg/config/constants.go:117:2: const ClaudeApiURL should be ClaudeAPIURL
pkg/config/constants.go:118:2: const ClaudeApiVersion should be ClaudeAPIVersion
pkg/config/constants.go:125:2: const LlmChatUrl should be LlmChatURL
pkg/config/constants.go:126:2: const LlmCfUrl should be LlmCfURL
pkg/config/constants.go:149:1: exported function GetCloudflareModels should have comment or be unexported
pkg/config/welcome.go:7:1: exported function DisplayWelcomeMessage should have comment or be unexported
pkg/consensus/pow.go:20:1: exported function GeneratePoW should have comment or be unexported
pkg/consensus/pow.go:20:18: func parameter peerId should be peerID
pkg/consensus/pow.go:42:1: exported function ComputeProofOfWork should have comment or be unexported
pkg/consensus/pow.go:42:25: func parameter peerId should be peerID
pkg/consensus/signer.go:20:1: exported function GenerateJWTToken should have comment or be unexported
pkg/consensus/signer.go:20:23: func parameter peerId should be peerID
pkg/db/operations.go:17:6: exported type WorkEvent should have comment or be unexported
pkg/db/operations.go:19:2: struct field PeerId should be PeerID
pkg/db/resolver_cache.go:26:6: exported type Record should have comment or be unexported
pkg/db/resolver_cache.go:74:9: if block ends with a return statement, so drop this else and outdent its block
pkg/db/resolver_cache.go:115:9: if block ends with a return statement, so drop this else and outdent its block
pkg/event/event.go:12:2: exported const WorkCompletion should have comment (or a comment on this block) or be unexported
pkg/event/event.go:24:6: exported type Event should have comment or be unexported
pkg/event/event.go:30:6: exported type EventTracker should have comment or be unexported
pkg/event/event.go:30:6: type name will be used as event.EventTracker by other packages, and that stutters; consider calling this Tracker
pkg/event/event.go:38:1: exported function NewEventTracker should have comment or be unexported
pkg/event/event.go:55:1: exported method EventTracker.TrackEvent should have comment or be unexported
pkg/event/event.go:76:1: exported method EventTracker.GetEvents should have comment or be unexported
pkg/event/event.go:87:1: exported method EventTracker.ClearEvents should have comment or be unexported
pkg/event/event.go:99:1: exported method EventTracker.TrackAndSendEvent should have comment or be unexported
pkg/event/event.go:117:9: if block ends with a return statement, so drop this else and outdent its block
pkg/event/event_client.go:14:6: exported type EventClient should have comment or be unexported
pkg/event/event_client.go:14:6: type name will be used as event.EventClient by other packages, and that stutters; consider calling this Client
pkg/event/event_client.go:20:1: exported function NewEventClient should have comment or be unexported
pkg/event/event_client.go:28:1: exported method EventClient.SendEvent should have comment or be unexported
pkg/event/event_library.go:22:97: method parameter peerId should be peerID
pkg/event/event_library.go:44:90: method parameter peerId should be peerID
pkg/event/event_library.go:66:96: method parameter peerId should be peerID
pkg/event/event_library.go:88:99: method parameter peerId should be peerID
pkg/event/event_library.go:125:52: method parameter peerId should be peerID
pkg/event/event_library.go:143:44: method parameter peerId should be peerID
pkg/llmbridge/client.go:18:6: exported type ClaudeClient should have comment or be unexported
pkg/llmbridge/client.go:22:6: exported type GPTClient should have comment or be unexported
pkg/llmbridge/client.go:54:1: exported method GPTClient.SendRequest should have comment or be unexported
pkg/llmbridge/client.go:96:6: exported type Response should have comment or be unexported
pkg/llmbridge/client.go:107:6: exported type ResponseContent should have comment or be unexported
pkg/llmbridge/client.go:113:6: exported type ResponseError should have comment or be unexported
pkg/llmbridge/client.go:118:6: exported type Usage should have comment or be unexported
pkg/llmbridge/config.go:5:6: exported type ClaudeAPIConfig should have comment or be unexported
pkg/llmbridge/config.go:11:6: exported type GPTAPIConfig should have comment or be unexported
pkg/llmbridge/payload.go:7:6: exported type Payload should have comment or be unexported
pkg/llmbridge/payload.go:15:6: exported type Message should have comment or be unexported
pkg/llmbridge/payload.go:20:6: exported type Content should have comment or be unexported
pkg/llmbridge/sentiment.go:169:3: var cfUrl should be cfURL
pkg/llmbridge/sentiment.go:270:9: if block ends with a return statement, so drop this else and outdent its block
pkg/llmbridge/sentiment.go:354:9: if block ends with a return statement, so drop this else and outdent its block
pkg/masacrypto/keys.go:135:1: exported function Libp2pPubKeyToEthAddress should have comment or be unexported
pkg/network/events.go:7:6: exported type PeerEvent should have comment or be unexported
pkg/network/kdht.go:23:2: exported const PeerAdded should have comment (or a comment on this block) or be unexported
pkg/network/kdht.go:32:1: exported function WithDht should have comment or be unexported
pkg/network/kdht.go:33:2: func parameter protocolId should be protocolID
pkg/network/mdns.go:9:7: exported const PeerFound should have comment or be unexported
pkg/network/mdns.go:27:1: exported function WithMDNS should have comment or be unexported
pkg/pubsub/manager.go:22:6: exported type Manager should have comment or be unexported
pkg/pubsub/node_data.go:20:2: exported const ActivityJoined should have comment (or a comment on this block) or be unexported
pkg/pubsub/node_data.go:24:6: exported type JSONMultiaddr should have comment or be unexported
pkg/pubsub/node_data.go:47:6: exported type NodeData should have comment or be unexported
pkg/pubsub/node_data.go:50:2: struct field PeerId should be PeerID
pkg/pubsub/node_data.go:76:44: func parameter peerId should be peerID
pkg/pubsub/node_data.go:108:2: exported const CategoryDiscord should have comment (or a comment on this block) or be unexported
pkg/pubsub/node_data.go:262:6: func GetSelfNodeDataJson should be GetSelfNodeDataJSON
pkg/pubsub/node_event_tracker.go:19:6: exported type NodeEventTracker should have comment or be unexported
pkg/pubsub/node_event_tracker.go:26:6: exported type ConnectBufferEntry should have comment or be unexported
pkg/pubsub/node_event_tracker.go:35:55: func parameter hostId should be hostID
pkg/pubsub/node_event_tracker.go:81:9: if block ends with a return statement, so drop this else and outdent its block
pkg/pubsub/node_event_tracker.go:178:10: if block ends with a return statement, so drop this else and outdent its block
pkg/pubsub/node_event_tracker.go:440:71: method parameter hostId should be hostID
pkg/pubsub/node_event_tracker.go:455:48: method parameter hostId should be hostID
pkg/pubsub/public_key_topic.go:23:6: exported type PublicKeyPublisher should have comment or be unexported
pkg/pubsub/public_key_topic.go:184:1: comment on exported method PublicKeyPublisher.GetPublishedMessages should be of the form "GetPublishedMessages ..."
pkg/pubsub/safe_map.go:11:6: exported type SafeMap should have comment or be unexported
pkg/pubsub/worker_tracker.go:11:6: exported type Workers should have comment or be unexported
pkg/scrapers/discord/exchangetoken.go:1:1: package comment should be of the form "Package discord ..."
pkg/scrapers/discord/getchannelmessages.go:1:1: package comment should be of the form "Package discord ..."
pkg/scrapers/discord/getguildchannels.go:1:1: package comment should be of the form "Package discord ..."
pkg/scrapers/discord/getuserguilds.go:1:1: package comment should be of the form "Package discord ..."
pkg/scrapers/reddit/reddit.go:5:1: exported function TestReddit should have comment or be unexported
pkg/scrapers/telegram/telegram_client.go:30:1: exported function GetClient should have comment or be unexported
pkg/scrapers/twitter/auth.go:41:1: exported function IsLoggedIn should have comment or be unexported
pkg/scrapers/twitter/auth.go:45:1: exported function Logout should have comment or be unexported
pkg/scrapers/twitter/cookies.go:12:1: exported function SaveCookies should have comment or be unexported
pkg/scrapers/twitter/cookies.go:25:1: exported function LoadCookies should have comment or be unexported
pkg/scrapers/twitter/followers.go:7:2: a blank import should be only in a main or test package, or have a comment justifying it
pkg/scrapers/twitter/tweets.go:8:2: a blank import should be only in a main or test package, or have a comment justifying it
pkg/scrapers/twitter/tweets.go:17:6: exported type TweetResult should have comment or be unexported
pkg/staking/abi.go:13:2: exported const MasaTokenABIPath should have comment (or a comment on this block) or be unexported
pkg/staking/abi.go:18:6: exported type ContractAddresses should have comment or be unexported
pkg/staking/contracts.go:13:5: exported var MasaTokenAddress should have comment or be unexported
pkg/staking/contracts.go:14:5: exported var ProtocolStakingContractAddress should have comment or be unexported
pkg/staking/contracts.go:16:6: exported type Client should have comment or be unexported
pkg/staking/faucet.go:11:1: exported method Client.RunFaucet should have comment or be unexported
pkg/workers/config.go:9:6: exported type WorkerConfig should have comment or be unexported
pkg/workers/config.go:19:5: exported var DefaultConfig should have comment or be unexported
pkg/workers/config.go:39:1: exported function LoadConfig should have comment or be unexported
pkg/workers/response_channel_map.go:9:6: exported type ResponseChannelMap should have comment or be unexported
pkg/workers/response_channel_map.go:64:1: exported method ResponseChannelMap.CreateChannel should have comment or be unexported
pkg/workers/worker_manager.go:28:1: exported function GetWorkHandlerManager should have comment or be unexported
pkg/workers/worker_manager.go:100:1: exported method WorkHandlerManager.DistributeWork should have comment or be unexported
pkg/workers/worker_manager.go:153:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/workers/worker_manager.go:262:1: exported method WorkHandlerManager.HandleWorkerStream should have comment or be unexported
pkg/workers/worker_manager.go:293:2: var peerId should be peerID
pkg/workers/handlers/discord.go:12:6: exported type DiscordProfileHandler should have comment or be unexported
pkg/workers/handlers/discord.go:13:6: exported type DiscordChannelHandler should have comment or be unexported
pkg/workers/handlers/discord.go:14:6: exported type DiscordSentimentHandler should have comment or be unexported
pkg/workers/handlers/discord.go:15:6: exported type DiscordGuildHandler should have comment or be unexported
pkg/workers/handlers/discord.go:16:6: exported type DiscoreUserGuildsHandler should have comment or be unexported
pkg/workers/handlers/discord.go:82:1: exported method DiscoreUserGuildsHandler.HandleWork should have comment or be unexported
pkg/workers/handlers/helper.go:7:1: exported function JsonBytesToMap should have comment or be unexported
pkg/workers/handlers/helper.go:7:6: func JsonBytesToMap should be JSONBytesToMap
pkg/workers/handlers/http_client.go:16:2: exported const GET should have comment (or a comment on this block) or be unexported
pkg/workers/handlers/http_client.go:38:1: exported function Get should have comment or be unexported
pkg/workers/handlers/http_client.go:42:1: exported function Post should have comment or be unexported
pkg/workers/handlers/http_client.go:46:1: exported function Put should have comment or be unexported
pkg/workers/handlers/http_client.go:50:1: exported function Patch should have comment or be unexported
pkg/workers/handlers/http_client.go:88:10: if block ends with a return statement, so drop this else and outdent its block
pkg/workers/handlers/llm.go:13:1: comment on exported type LLMChatBody should be of the form "LLMChatBody ..." (with optional leading article)
pkg/workers/handlers/llm.go:23:6: exported type LLMChatHandler should have comment or be unexported
pkg/workers/handlers/telegram.go:13:6: exported type TelegramSentimentHandler should have comment or be unexported
pkg/workers/handlers/telegram.go:14:6: exported type TelegramChannelHandler should have comment or be unexported
pkg/workers/handlers/twitter.go:12:6: exported type TwitterQueryHandler should have comment or be unexported
pkg/workers/handlers/twitter.go:13:6: exported type TwitterFollowersHandler should have comment or be unexported
pkg/workers/handlers/twitter.go:14:6: exported type TwitterProfileHandler should have comment or be unexported
pkg/workers/handlers/twitter.go:15:6: exported type TwitterSentimentHandler should have comment or be unexported
pkg/workers/handlers/twitter.go:16:6: exported type TwitterTrendsHandler should have comment or be unexported
pkg/workers/handlers/twitter.go:18:1: exported method TwitterQueryHandler.HandleWork should have comment or be unexported
pkg/workers/handlers/twitter.go:33:1: exported method TwitterFollowersHandler.HandleWork should have comment or be unexported
pkg/workers/handlers/twitter.go:48:1: exported method TwitterProfileHandler.HandleWork should have comment or be unexported
pkg/workers/handlers/twitter.go:62:1: exported method TwitterSentimentHandler.HandleWork should have comment or be unexported
pkg/workers/handlers/twitter.go:78:1: exported method TwitterTrendsHandler.HandleWork should have comment or be unexported
pkg/workers/handlers/web.go:14:6: exported type WebSentimentHandler should have comment or be unexported
pkg/workers/handlers/web.go:16:1: exported method WebHandler.HandleWork should have comment or be unexported
pkg/workers/handlers/web.go:31:1: exported method WebSentimentHandler.HandleWork should have comment or be unexported
pkg/workers/types/request_response.go:1:1: don't use an underscore in package name
pkg/workers/types/request_response.go:10:6: exported type Worker should have comment or be unexported
pkg/workers/types/request_response.go:18:6: exported type WorkRequest should have comment or be unexported
pkg/workers/types/request_response.go:20:2: struct field RequestId should be RequestID
pkg/workers/types/request_response.go:24:6: exported type WorkResponse should have comment or be unexported
pkg/workers/types/request_response.go:28:2: struct field WorkerPeerId should be WorkerPeerID
pkg/workers/types/work_types.go:1:1: don't use an underscore in package name
pkg/workers/types/work_types.go:9:6: exported type WorkerType should have comment or be unexported
pkg/workers/types/work_types.go:12:2: exported const Discord should have comment (or a comment on this block) or be unexported
tests/node_listener.go:28:6: exported type NodeListener should have comment or be unexported
tests/node_listener.go:31:2: struct field ServerId should be ServerID
tests/node_listener.go:36:1: exported function NewNodeListener should have comment or be unexported
tests/node_listener.go:54:1: exported method NodeListener.Start should have comment or be unexported
tools/abigen_helper.go:14:6: exported type Contract should have comment or be unexported
tools/abigen_helper.go:19:1: exported function AbiGen should have comment or be unexported
tools/abigen_helper.go:56:1: exported function AbiGenBindings should have comment or be unexported

Copy link

⚠ goimports failed (.)

pkg/api/handlers_data.go
 	"github.com/masa-finance/masa-oracle/pkg/scrapers/discord"
 	"github.com/masa-finance/masa-oracle/pkg/scrapers/telegram"
 	"github.com/masa-finance/masa-oracle/pkg/workers"
-	"github.com/masa-finance/masa-oracle/pkg/workers/types"
+	data_types "github.com/masa-finance/masa-oracle/pkg/workers/types"
 )
 
 type LLMChat struct {
pkg/db/access_control.go
 
 import (
 	"encoding/hex"
+
 	libp2pCrypto "github.com/libp2p/go-libp2p/core/crypto"
 	"github.com/libp2p/go-libp2p/core/host"
 	"github.com/sirupsen/logrus"
pkg/workers/handlers/discord.go
 	"github.com/sirupsen/logrus"
 
 	"github.com/masa-finance/masa-oracle/pkg/scrapers/discord"
-	"github.com/masa-finance/masa-oracle/pkg/workers/types"
+	data_types "github.com/masa-finance/masa-oracle/pkg/workers/types"
 )
 
 type DiscordProfileHandler struct{}
pkg/workers/handlers/llm.go
 	"github.com/sirupsen/logrus"
 
 	"github.com/masa-finance/masa-oracle/pkg/config"
-	"github.com/masa-finance/masa-oracle/pkg/workers/types"
+	data_types "github.com/masa-finance/masa-oracle/pkg/workers/types"
 )
 
 // TODO: LLMChatBody isn't used anywhere in the codebase. Remove after testing
pkg/workers/handlers/telegram.go
 	"github.com/sirupsen/logrus"
 
 	"github.com/masa-finance/masa-oracle/pkg/scrapers/telegram"
-	"github.com/masa-finance/masa-oracle/pkg/workers/types"
+	data_types "github.com/masa-finance/masa-oracle/pkg/workers/types"
 )
 
 type TelegramSentimentHandler struct{}
pkg/workers/handlers/twitter.go
 	"github.com/sirupsen/logrus"
 
 	"github.com/masa-finance/masa-oracle/pkg/scrapers/twitter"
-	"github.com/masa-finance/masa-oracle/pkg/workers/types"
+	data_types "github.com/masa-finance/masa-oracle/pkg/workers/types"
 )
 
 type TwitterQueryHandler struct{}
pkg/workers/handlers/web.go
 	"github.com/sirupsen/logrus"
 
 	"github.com/masa-finance/masa-oracle/pkg/scrapers/web"
-	"github.com/masa-finance/masa-oracle/pkg/workers/types"
+	data_types "github.com/masa-finance/masa-oracle/pkg/workers/types"
 )
 
 // WebHandler - All the web handlers implement the WorkHandler interface.
pkg/workers/response_channel_map.go
 import (
 	"sync"
 
-	"github.com/masa-finance/masa-oracle/pkg/workers/types"
+	data_types "github.com/masa-finance/masa-oracle/pkg/workers/types"
 )
 
 type ResponseChannelMap struct {
pkg/workers/worker_selection.go
 
 	masa "github.com/masa-finance/masa-oracle/pkg"
 	"github.com/masa-finance/masa-oracle/pkg/pubsub"
-	"github.com/masa-finance/masa-oracle/pkg/workers/types"
+	data_types "github.com/masa-finance/masa-oracle/pkg/workers/types"
 )
 
 // GetEligibleWorkers Uses the new NodeTracker method to get the eligible workers for a given message type

Copy link

⚠ shadow failed (.)

pkg/network/address.go:9:2: no required module provides package github.com/chyeh/pubip; to add it:
	go get github.com/chyeh/pubip

Copy link

⚠ gosec failed (.)

2024/08/22 05:40:48 internal error: package "flag" without types was imported from "command-line-arguments"
Show Detail
2024/08/22 05:40:48 internal error: package "flag" without types was imported from "command-line-arguments"

Code Reference

Copy link

⚠ errcheck failed (.)

error: failed to check packages: errors while loading package github.com/masa-finance/masa-oracle/pkg/network: [/github/workspace/pkg/network/address.go:9:2: could not import github.com/chyeh/pubip (invalid package name: "")]

@teslashibe teslashibe changed the title Feat event tracking for work distribution feat event tracking for work distribution Aug 22, 2024
Copy link

⚠ staticcheck failed (.)

-: error obtaining VCS status: exit status 128
	Use -buildvcs=false to disable VCS stamping. (compile)
pkg/scrapers/telegram/telegram_client.go:24:2: var once is unused (U1000)
pkg/staking/abi.go:6:2: "io/ioutil" has been deprecated since Go 1.19: As of Go 1.16, the same functionality is now provided by package [io] or package [os], and those implementations should be preferred in new code. See the specific function documentation for details.  (SA1019)
tests/node_listener.go:136:2: this value of err is never used (SA4006)
pkg/network/address.go:9:2: no required module provides package github.com/chyeh/pubip; to add it:
	go get github.com/chyeh/pubip (compile)

Checks Document

Copy link

PR description is too short and seems to not fulfill PR template, please fill in

@teslashibe teslashibe changed the title feat event tracking for work distribution feat: event tracking for work distribution Aug 22, 2024
Copy link

PR description is too short and seems to not fulfill PR template, please fill in

Copy link

PR description is too short and seems to not fulfill PR template, please fill in

Copy link

⚠ golint failed (.)

Found 212 lint suggestions; failing.

Show Detail
cmd/masa-node-cli/handlers.go:159:10: if block ends with a return statement, so drop this else and outdent its block
cmd/masa-node-cli/handlers.go:185:9: if block ends with a return statement, so drop this else and outdent its block
cmd/masa-node-cli/types.go:10:6: exported type AppConfig should have comment or be unexported
cmd/masa-node-cli/types.go:22:6: exported type Gossip should have comment or be unexported
cmd/masa-node-cli/types.go:27:6: exported type SpeakRequest should have comment or be unexported
cmd/masa-node-cli/types.go:35:6: exported type SubscriptionHandler should have comment or be unexported
cmd/masa-node-cli/types.go:41:6: exported type RadioButtons should have comment or be unexported
cmd/masa-node-cli/types.go:48:6: exported type InputBox should have comment or be unexported
cmd/tagger/main.go:23:1: package comment is detached; there should be no blank lines between it and the package statement
cmd/tagger/main.go:100:1: exported function TagProject should have comment or be unexported
internal/versioning/version.go:4:2: exported var ApplicationVersion should have comment or be unexported
internal/versioning/version.go:6:2: comment on exported var ProtocolVersion should be of the form "ProtocolVersion ..."
pkg/oracle_node.go:42:6: exported type OracleNode should have comment or be unexported
pkg/oracle_node.go:348:6: exported type BlockData should have comment or be unexported
pkg/oracle_node.go:356:6: exported type Blocks should have comment or be unexported
pkg/oracle_node.go:360:6: exported type BlockEvents should have comment or be unexported
pkg/oracle_node.go:362:6: exported type BlockEventTracker should have comment or be unexported
pkg/oracle_node.go:475:1: exported function SubscribeToBlocks should have comment or be unexported
pkg/oracle_node_listener.go:77:6: exported type NodeDataPage should have comment or be unexported
pkg/oracle_node_listener.go:208:2: var remotePeerId should be remotePeerID
pkg/api/api.go:12:6: exported type API should have comment or be unexported
pkg/api/config.go:6:6: type name will be used as api.APIConfig by other packages, and that stutters; consider calling this Config
pkg/api/config.go:11:5: exported var DefaultConfig should have comment or be unexported
pkg/api/handlers_data.go:32:6: exported type LLMChat should have comment or be unexported
pkg/api/handlers_data.go:41:1: exported function IsBase64 should have comment or be unexported
pkg/api/handlers_data.go:366:4: struct field Url should be URL
pkg/api/handlers_data.go:826:4: struct field Url should be URL
pkg/api/handlers_data.go:912:1: exported method API.GetChannelMessagesHandler should have comment or be unexported
pkg/api/handlers_data.go:1058:3: var cfUrl should be cfURL
pkg/api/handlers_node.go:435:17: method GetNodeApiKey should be GetNodeAPIKey
pkg/chain/block.go:13:6: exported type Block should have comment or be unexported
pkg/chain/block.go:21:1: exported method Block.Build should have comment or be unexported
pkg/chain/block.go:30:1: exported method Block.Serialize should have comment or be unexported
pkg/chain/block.go:40:1: exported method Block.Deserialize should have comment or be unexported
pkg/chain/block.go:51:1: exported method Block.Print should have comment or be unexported
pkg/chain/chain.go:13:6: exported type Chain should have comment or be unexported
pkg/chain/chain.go:173:1: exported method Chain.GetBlock should have comment or be unexported
pkg/chain/persistance.go:9:2: exported const KeyLastHash should have comment (or a comment on this block) or be unexported
pkg/chain/persistance.go:12:6: exported type Persistance should have comment or be unexported
pkg/chain/persistance.go:16:6: exported type Serializable should have comment or be unexported
pkg/chain/persistance.go:21:1: exported method Persistance.Init should have comment or be unexported
pkg/chain/persistance.go:74:1: exported method Persistance.Get should have comment or be unexported
pkg/chain/persistance.go:96:1: exported method Persistance.GetLastHash should have comment or be unexported
pkg/chain/persistance.go:100:1: exported method Persistance.SaveBlock should have comment or be unexported
pkg/chain/persistance.go:122:1: exported method Persistance.Iterate should have comment or be unexported
pkg/chain/pos.go:16:6: exported type ProofOfStake should have comment or be unexported
pkg/chain/pos.go:44:1: exported method ProofOfStake.Run should have comment or be unexported
pkg/chain/pos.go:68:1: exported function IsValidPoS should have comment or be unexported
pkg/config/app.go:68:2: struct field RpcUrl should be RPCURL
pkg/config/app.go:70:2: struct field AllowedPeerId should be AllowedPeerID
pkg/config/app.go:85:2: struct field ClaudeApiKey should be ClaudeAPIKey
pkg/config/app.go:86:2: struct field ClaudeApiURL should be ClaudeAPIURL
pkg/config/app.go:87:2: struct field ClaudeApiVersion should be ClaudeAPIVersion
pkg/config/app.go:94:2: struct field LLMChatUrl should be LLMChatURL
pkg/config/app.go:95:2: struct field LLMCfUrl should be LLMCfURL
pkg/config/constants.go:81:2: exported const PrivKeyFile should have comment (or a comment on this block) or be unexported
pkg/config/constants.go:84:2: const RpcUrl should be RPCURL
pkg/config/constants.go:116:2: const ClaudeApiKey should be ClaudeAPIKey
pkg/config/constants.go:117:2: const ClaudeApiURL should be ClaudeAPIURL
pkg/config/constants.go:118:2: const ClaudeApiVersion should be ClaudeAPIVersion
pkg/config/constants.go:125:2: const LlmChatUrl should be LlmChatURL
pkg/config/constants.go:126:2: const LlmCfUrl should be LlmCfURL
pkg/config/constants.go:149:1: exported function GetCloudflareModels should have comment or be unexported
pkg/config/welcome.go:7:1: exported function DisplayWelcomeMessage should have comment or be unexported
pkg/consensus/pow.go:20:1: exported function GeneratePoW should have comment or be unexported
pkg/consensus/pow.go:20:18: func parameter peerId should be peerID
pkg/consensus/pow.go:42:1: exported function ComputeProofOfWork should have comment or be unexported
pkg/consensus/pow.go:42:25: func parameter peerId should be peerID
pkg/consensus/signer.go:20:1: exported function GenerateJWTToken should have comment or be unexported
pkg/consensus/signer.go:20:23: func parameter peerId should be peerID
pkg/db/operations.go:17:6: exported type WorkEvent should have comment or be unexported
pkg/db/operations.go:19:2: struct field PeerId should be PeerID
pkg/db/resolver_cache.go:26:6: exported type Record should have comment or be unexported
pkg/db/resolver_cache.go:74:9: if block ends with a return statement, so drop this else and outdent its block
pkg/db/resolver_cache.go:115:9: if block ends with a return statement, so drop this else and outdent its block
pkg/event/event.go:12:2: exported const WorkCompletion should have comment (or a comment on this block) or be unexported
pkg/event/event.go:24:6: exported type Event should have comment or be unexported
pkg/event/event.go:30:6: exported type EventTracker should have comment or be unexported
pkg/event/event.go:30:6: type name will be used as event.EventTracker by other packages, and that stutters; consider calling this Tracker
pkg/event/event.go:38:1: exported function NewEventTracker should have comment or be unexported
pkg/event/event.go:55:1: exported method EventTracker.TrackEvent should have comment or be unexported
pkg/event/event.go:76:1: exported method EventTracker.GetEvents should have comment or be unexported
pkg/event/event.go:87:1: exported method EventTracker.ClearEvents should have comment or be unexported
pkg/event/event.go:99:1: exported method EventTracker.TrackAndSendEvent should have comment or be unexported
pkg/event/event.go:117:9: if block ends with a return statement, so drop this else and outdent its block
pkg/event/event_client.go:14:6: exported type EventClient should have comment or be unexported
pkg/event/event_client.go:14:6: type name will be used as event.EventClient by other packages, and that stutters; consider calling this Client
pkg/event/event_client.go:20:1: exported function NewEventClient should have comment or be unexported
pkg/event/event_client.go:28:1: exported method EventClient.SendEvent should have comment or be unexported
pkg/event/event_library.go:22:97: method parameter peerId should be peerID
pkg/event/event_library.go:44:90: method parameter peerId should be peerID
pkg/event/event_library.go:66:96: method parameter peerId should be peerID
pkg/event/event_library.go:88:99: method parameter peerId should be peerID
pkg/event/event_library.go:125:52: method parameter peerId should be peerID
pkg/event/event_library.go:143:44: method parameter peerId should be peerID
pkg/llmbridge/client.go:18:6: exported type ClaudeClient should have comment or be unexported
pkg/llmbridge/client.go:22:6: exported type GPTClient should have comment or be unexported
pkg/llmbridge/client.go:54:1: exported method GPTClient.SendRequest should have comment or be unexported
pkg/llmbridge/client.go:96:6: exported type Response should have comment or be unexported
pkg/llmbridge/client.go:107:6: exported type ResponseContent should have comment or be unexported
pkg/llmbridge/client.go:113:6: exported type ResponseError should have comment or be unexported
pkg/llmbridge/client.go:118:6: exported type Usage should have comment or be unexported
pkg/llmbridge/config.go:5:6: exported type ClaudeAPIConfig should have comment or be unexported
pkg/llmbridge/config.go:11:6: exported type GPTAPIConfig should have comment or be unexported
pkg/llmbridge/payload.go:7:6: exported type Payload should have comment or be unexported
pkg/llmbridge/payload.go:15:6: exported type Message should have comment or be unexported
pkg/llmbridge/payload.go:20:6: exported type Content should have comment or be unexported
pkg/llmbridge/sentiment.go:169:3: var cfUrl should be cfURL
pkg/llmbridge/sentiment.go:270:9: if block ends with a return statement, so drop this else and outdent its block
pkg/llmbridge/sentiment.go:354:9: if block ends with a return statement, so drop this else and outdent its block
pkg/masacrypto/keys.go:135:1: exported function Libp2pPubKeyToEthAddress should have comment or be unexported
pkg/network/events.go:7:6: exported type PeerEvent should have comment or be unexported
pkg/network/kdht.go:23:2: exported const PeerAdded should have comment (or a comment on this block) or be unexported
pkg/network/kdht.go:32:1: exported function WithDht should have comment or be unexported
pkg/network/kdht.go:33:2: func parameter protocolId should be protocolID
pkg/network/mdns.go:9:7: exported const PeerFound should have comment or be unexported
pkg/network/mdns.go:27:1: exported function WithMDNS should have comment or be unexported
pkg/pubsub/manager.go:22:6: exported type Manager should have comment or be unexported
pkg/pubsub/node_data.go:20:2: exported const ActivityJoined should have comment (or a comment on this block) or be unexported
pkg/pubsub/node_data.go:24:6: exported type JSONMultiaddr should have comment or be unexported
pkg/pubsub/node_data.go:47:6: exported type NodeData should have comment or be unexported
pkg/pubsub/node_data.go:50:2: struct field PeerId should be PeerID
pkg/pubsub/node_data.go:76:44: func parameter peerId should be peerID
pkg/pubsub/node_data.go:108:2: exported const CategoryDiscord should have comment (or a comment on this block) or be unexported
pkg/pubsub/node_data.go:262:6: func GetSelfNodeDataJson should be GetSelfNodeDataJSON
pkg/pubsub/node_event_tracker.go:19:6: exported type NodeEventTracker should have comment or be unexported
pkg/pubsub/node_event_tracker.go:26:6: exported type ConnectBufferEntry should have comment or be unexported
pkg/pubsub/node_event_tracker.go:35:55: func parameter hostId should be hostID
pkg/pubsub/node_event_tracker.go:81:9: if block ends with a return statement, so drop this else and outdent its block
pkg/pubsub/node_event_tracker.go:178:10: if block ends with a return statement, so drop this else and outdent its block
pkg/pubsub/node_event_tracker.go:440:71: method parameter hostId should be hostID
pkg/pubsub/node_event_tracker.go:455:48: method parameter hostId should be hostID
pkg/pubsub/public_key_topic.go:23:6: exported type PublicKeyPublisher should have comment or be unexported
pkg/pubsub/public_key_topic.go:184:1: comment on exported method PublicKeyPublisher.GetPublishedMessages should be of the form "GetPublishedMessages ..."
pkg/pubsub/safe_map.go:11:6: exported type SafeMap should have comment or be unexported
pkg/pubsub/worker_tracker.go:11:6: exported type Workers should have comment or be unexported
pkg/scrapers/discord/exchangetoken.go:1:1: package comment should be of the form "Package discord ..."
pkg/scrapers/discord/getchannelmessages.go:1:1: package comment should be of the form "Package discord ..."
pkg/scrapers/discord/getguildchannels.go:1:1: package comment should be of the form "Package discord ..."
pkg/scrapers/discord/getuserguilds.go:1:1: package comment should be of the form "Package discord ..."
pkg/scrapers/reddit/reddit.go:5:1: exported function TestReddit should have comment or be unexported
pkg/scrapers/telegram/telegram_client.go:30:1: exported function GetClient should have comment or be unexported
pkg/scrapers/twitter/auth.go:41:1: exported function IsLoggedIn should have comment or be unexported
pkg/scrapers/twitter/auth.go:45:1: exported function Logout should have comment or be unexported
pkg/scrapers/twitter/cookies.go:12:1: exported function SaveCookies should have comment or be unexported
pkg/scrapers/twitter/cookies.go:25:1: exported function LoadCookies should have comment or be unexported
pkg/scrapers/twitter/followers.go:7:2: a blank import should be only in a main or test package, or have a comment justifying it
pkg/scrapers/twitter/tweets.go:8:2: a blank import should be only in a main or test package, or have a comment justifying it
pkg/scrapers/twitter/tweets.go:17:6: exported type TweetResult should have comment or be unexported
pkg/staking/abi.go:13:2: exported const MasaTokenABIPath should have comment (or a comment on this block) or be unexported
pkg/staking/abi.go:18:6: exported type ContractAddresses should have comment or be unexported
pkg/staking/contracts.go:13:5: exported var MasaTokenAddress should have comment or be unexported
pkg/staking/contracts.go:14:5: exported var ProtocolStakingContractAddress should have comment or be unexported
pkg/staking/contracts.go:16:6: exported type Client should have comment or be unexported
pkg/staking/faucet.go:11:1: exported method Client.RunFaucet should have comment or be unexported
pkg/workers/config.go:9:6: exported type WorkerConfig should have comment or be unexported
pkg/workers/config.go:19:5: exported var DefaultConfig should have comment or be unexported
pkg/workers/config.go:39:1: exported function LoadConfig should have comment or be unexported
pkg/workers/response_channel_map.go:9:6: exported type ResponseChannelMap should have comment or be unexported
pkg/workers/response_channel_map.go:64:1: exported method ResponseChannelMap.CreateChannel should have comment or be unexported
pkg/workers/worker_manager.go:28:1: exported function GetWorkHandlerManager should have comment or be unexported
pkg/workers/worker_manager.go:100:1: exported method WorkHandlerManager.DistributeWork should have comment or be unexported
pkg/workers/worker_manager.go:153:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/workers/worker_manager.go:262:1: exported method WorkHandlerManager.HandleWorkerStream should have comment or be unexported
pkg/workers/worker_manager.go:293:2: var peerId should be peerID
pkg/workers/handlers/discord.go:12:6: exported type DiscordProfileHandler should have comment or be unexported
pkg/workers/handlers/discord.go:13:6: exported type DiscordChannelHandler should have comment or be unexported
pkg/workers/handlers/discord.go:14:6: exported type DiscordSentimentHandler should have comment or be unexported
pkg/workers/handlers/discord.go:15:6: exported type DiscordGuildHandler should have comment or be unexported
pkg/workers/handlers/discord.go:16:6: exported type DiscoreUserGuildsHandler should have comment or be unexported
pkg/workers/handlers/discord.go:82:1: exported method DiscoreUserGuildsHandler.HandleWork should have comment or be unexported
pkg/workers/handlers/helper.go:7:1: exported function JsonBytesToMap should have comment or be unexported
pkg/workers/handlers/helper.go:7:6: func JsonBytesToMap should be JSONBytesToMap
pkg/workers/handlers/http_client.go:16:2: exported const GET should have comment (or a comment on this block) or be unexported
pkg/workers/handlers/http_client.go:38:1: exported function Get should have comment or be unexported
pkg/workers/handlers/http_client.go:42:1: exported function Post should have comment or be unexported
pkg/workers/handlers/http_client.go:46:1: exported function Put should have comment or be unexported
pkg/workers/handlers/http_client.go:50:1: exported function Patch should have comment or be unexported
pkg/workers/handlers/http_client.go:88:10: if block ends with a return statement, so drop this else and outdent its block
pkg/workers/handlers/llm.go:13:1: comment on exported type LLMChatBody should be of the form "LLMChatBody ..." (with optional leading article)
pkg/workers/handlers/llm.go:23:6: exported type LLMChatHandler should have comment or be unexported
pkg/workers/handlers/telegram.go:13:6: exported type TelegramSentimentHandler should have comment or be unexported
pkg/workers/handlers/telegram.go:14:6: exported type TelegramChannelHandler should have comment or be unexported
pkg/workers/handlers/twitter.go:12:6: exported type TwitterQueryHandler should have comment or be unexported
pkg/workers/handlers/twitter.go:13:6: exported type TwitterFollowersHandler should have comment or be unexported
pkg/workers/handlers/twitter.go:14:6: exported type TwitterProfileHandler should have comment or be unexported
pkg/workers/handlers/twitter.go:15:6: exported type TwitterSentimentHandler should have comment or be unexported
pkg/workers/handlers/twitter.go:16:6: exported type TwitterTrendsHandler should have comment or be unexported
pkg/workers/handlers/twitter.go:18:1: exported method TwitterQueryHandler.HandleWork should have comment or be unexported
pkg/workers/handlers/twitter.go:33:1: exported method TwitterFollowersHandler.HandleWork should have comment or be unexported
pkg/workers/handlers/twitter.go:48:1: exported method TwitterProfileHandler.HandleWork should have comment or be unexported
pkg/workers/handlers/twitter.go:62:1: exported method TwitterSentimentHandler.HandleWork should have comment or be unexported
pkg/workers/handlers/twitter.go:78:1: exported method TwitterTrendsHandler.HandleWork should have comment or be unexported
pkg/workers/handlers/web.go:14:6: exported type WebSentimentHandler should have comment or be unexported
pkg/workers/handlers/web.go:16:1: exported method WebHandler.HandleWork should have comment or be unexported
pkg/workers/handlers/web.go:31:1: exported method WebSentimentHandler.HandleWork should have comment or be unexported
pkg/workers/types/request_response.go:1:1: don't use an underscore in package name
pkg/workers/types/request_response.go:10:6: exported type Worker should have comment or be unexported
pkg/workers/types/request_response.go:18:6: exported type WorkRequest should have comment or be unexported
pkg/workers/types/request_response.go:20:2: struct field RequestId should be RequestID
pkg/workers/types/request_response.go:24:6: exported type WorkResponse should have comment or be unexported
pkg/workers/types/request_response.go:28:2: struct field WorkerPeerId should be WorkerPeerID
pkg/workers/types/work_types.go:1:1: don't use an underscore in package name
pkg/workers/types/work_types.go:9:6: exported type WorkerType should have comment or be unexported
pkg/workers/types/work_types.go:12:2: exported const Discord should have comment (or a comment on this block) or be unexported
tests/node_listener.go:28:6: exported type NodeListener should have comment or be unexported
tests/node_listener.go:31:2: struct field ServerId should be ServerID
tests/node_listener.go:36:1: exported function NewNodeListener should have comment or be unexported
tests/node_listener.go:54:1: exported method NodeListener.Start should have comment or be unexported
tools/abigen_helper.go:14:6: exported type Contract should have comment or be unexported
tools/abigen_helper.go:19:1: exported function AbiGen should have comment or be unexported
tools/abigen_helper.go:56:1: exported function AbiGenBindings should have comment or be unexported

Copy link

⚠ goimports failed (.)

pkg/api/handlers_data.go
 	"github.com/masa-finance/masa-oracle/pkg/scrapers/discord"
 	"github.com/masa-finance/masa-oracle/pkg/scrapers/telegram"
 	"github.com/masa-finance/masa-oracle/pkg/workers"
-	"github.com/masa-finance/masa-oracle/pkg/workers/types"
+	data_types "github.com/masa-finance/masa-oracle/pkg/workers/types"
 )
 
 type LLMChat struct {
pkg/db/access_control.go
 
 import (
 	"encoding/hex"
+
 	libp2pCrypto "github.com/libp2p/go-libp2p/core/crypto"
 	"github.com/libp2p/go-libp2p/core/host"
 	"github.com/sirupsen/logrus"
pkg/workers/handlers/discord.go
 	"github.com/sirupsen/logrus"
 
 	"github.com/masa-finance/masa-oracle/pkg/scrapers/discord"
-	"github.com/masa-finance/masa-oracle/pkg/workers/types"
+	data_types "github.com/masa-finance/masa-oracle/pkg/workers/types"
 )
 
 type DiscordProfileHandler struct{}
pkg/workers/handlers/llm.go
 	"github.com/sirupsen/logrus"
 
 	"github.com/masa-finance/masa-oracle/pkg/config"
-	"github.com/masa-finance/masa-oracle/pkg/workers/types"
+	data_types "github.com/masa-finance/masa-oracle/pkg/workers/types"
 )
 
 // TODO: LLMChatBody isn't used anywhere in the codebase. Remove after testing
pkg/workers/handlers/telegram.go
 	"github.com/sirupsen/logrus"
 
 	"github.com/masa-finance/masa-oracle/pkg/scrapers/telegram"
-	"github.com/masa-finance/masa-oracle/pkg/workers/types"
+	data_types "github.com/masa-finance/masa-oracle/pkg/workers/types"
 )
 
 type TelegramSentimentHandler struct{}
pkg/workers/handlers/twitter.go
 	"github.com/sirupsen/logrus"
 
 	"github.com/masa-finance/masa-oracle/pkg/scrapers/twitter"
-	"github.com/masa-finance/masa-oracle/pkg/workers/types"
+	data_types "github.com/masa-finance/masa-oracle/pkg/workers/types"
 )
 
 type TwitterQueryHandler struct{}
pkg/workers/handlers/web.go
 	"github.com/sirupsen/logrus"
 
 	"github.com/masa-finance/masa-oracle/pkg/scrapers/web"
-	"github.com/masa-finance/masa-oracle/pkg/workers/types"
+	data_types "github.com/masa-finance/masa-oracle/pkg/workers/types"
 )
 
 // WebHandler - All the web handlers implement the WorkHandler interface.
pkg/workers/response_channel_map.go
 import (
 	"sync"
 
-	"github.com/masa-finance/masa-oracle/pkg/workers/types"
+	data_types "github.com/masa-finance/masa-oracle/pkg/workers/types"
 )
 
 type ResponseChannelMap struct {
pkg/workers/worker_selection.go
 
 	masa "github.com/masa-finance/masa-oracle/pkg"
 	"github.com/masa-finance/masa-oracle/pkg/pubsub"
-	"github.com/masa-finance/masa-oracle/pkg/workers/types"
+	data_types "github.com/masa-finance/masa-oracle/pkg/workers/types"
 )
 
 // GetEligibleWorkers Uses the new NodeTracker method to get the eligible workers for a given message type

Copy link

⚠ gosec failed (.)

2024/08/23 12:33:00 internal error: package "bytes" without types was imported from "command-line-arguments"
Show Detail
2024/08/23 12:33:00 internal error: package "bytes" without types was imported from "command-line-arguments"

Code Reference

Copy link

⚠ errcheck failed (.)

error: failed to check packages: errors while loading package github.com/masa-finance/masa-oracle/cmd/masa-node: [-: error obtaining VCS status: exit status 128
	Use -buildvcs=false to disable VCS stamping.]

Copy link

⚠ staticcheck failed (.)

-: error obtaining VCS status: exit status 128
	Use -buildvcs=false to disable VCS stamping. (compile)
pkg/api/handlers_data.go:92:6: func publishWorkRequest is unused (U1000)
pkg/oracle_node.go:80:6: func getOutboundIP is unused (U1000)
pkg/scrapers/telegram/telegram_client.go:24:2: var once is unused (U1000)
pkg/staking/abi.go:6:2: "io/ioutil" has been deprecated since Go 1.19: As of Go 1.16, the same functionality is now provided by package [io] or package [os], and those implementations should be preferred in new code. See the specific function documentation for details.  (SA1019)
tests/node_listener.go:136:2: this value of err is never used (SA4006)

Checks Document

Copy link

⚠ shadow failed (.)

# github.com/masa-finance/masa-oracle/pkg/chain
pkg/chain/persistance.go:35:9: declaration of "err" shadows declaration at line 24
pkg/chain/persistance.go:41:17: declaration of "err" shadows declaration at line 35
# github.com/masa-finance/masa-oracle/pkg/pubsub
pkg/pubsub/public_key_topic.go:62:16: declaration of "err" shadows declaration at line 50
# github.com/masa-finance/masa-oracle/pkg/network
pkg/network/discover.go:70:5: declaration of "err" shadows declaration at line 63
pkg/network/kdht.go:119:6: declaration of "err" shadows declaration at line 108
# github.com/masa-finance/masa-oracle/pkg/event
pkg/event/event_client.go:46:3: declaration of "err" shadows declaration at line 34
# github.com/masa-finance/masa-oracle/cmd/tagger
# [github.com/masa-finance/masa-oracle/cmd/tagger]
cmd/tagger/main.go:102:8: declaration of "err" shadows declaration at line 100
# github.com/masa-finance/masa-oracle/pkg/masacrypto
# [github.com/masa-finance/masa-oracle/pkg/masacrypto]
pkg/masacrypto/cert.go:61:5: declaration of "err" shadows declaration at line 23
pkg/masacrypto/cert_test.go:20:8: declaration of "err" shadows declaration at line 14
pkg/masacrypto/cert_test.go:25:8: declaration of "err" shadows declaration at line 14
# github.com/masa-finance/masa-oracle/tools
# [github.com/masa-finance/masa-oracle/tools]
tools/abigen_helper.go:34:5: declaration of "err" shadows declaration at line 27
tools/abigen_helper.go:76:5: declaration of "err" shadows declaration at line 70
# github.com/masa-finance/masa-oracle/pkg/scrapers/discord
pkg/scrapers/discord/getguildchannels.go:44:14: declaration of "err" shadows declaration at line 28
# github.com/masa-finance/masa-oracle/pkg/scrapers/telegram
pkg/scrapers/telegram/getchannelmessages.go:25:13: declaration of "err" shadows declaration at line 16
pkg/scrapers/telegram/telegram_client.go:84:13: declaration of "err" shadows declaration at line 73
pkg/scrapers/telegram/telegram_client.go:131:9: declaration of "err" shadows declaration at line 120
# github.com/masa-finance/masa-oracle/pkg/workers/handlers
pkg/workers/handlers/http_client.go:93:3: declaration of "err" shadows declaration at line 56
# github.com/masa-finance/masa-oracle/pkg/workers
pkg/workers/worker_manager.go:166:4: declaration of "err" shadows declaration at line 157
# github.com/masa-finance/masa-oracle/pkg/api
pkg/api/handlers_data.go:630:6: declaration of "err" shadows declaration at line 608
pkg/api/handlers_data.go:643:8: declaration of "err" shadows declaration at line 608
pkg/api/handlers_data.go:1079:4: declaration of "err" shadows declaration at line 1052
# github.com/masa-finance/masa-oracle/cmd/masa-node
# [github.com/masa-finance/masa-oracle/cmd/masa-node]
cmd/masa-node/main.go:119:3: declaration of "cfg" shadows declaration at line 29
cmd/masa-node/main.go:121:7: declaration of "err" shadows declaration at line 60

Copy link

PR description is too short and seems to not fulfill PR template, please fill in

Copy link

PR description is too short and seems to not fulfill PR template, please fill in

… for work requests

- Add TrackWorkRequest in event_library.go to use host node's peer ID
- Modify SearchTweetsRecent in handlers_data.go to pass Host peer ID
- Add null checks for EventTracker and Node in API handlers
- Ensure proper initialization of EventTracker in NewAPI function
- Update API struct to include EventTracker field
- Add debug logging for EventTracker creation and API initialization

This commit enhances the accuracy of event tracking by using the host node's
peer ID instead of the client IP when logging work requests. It also improves
robustness with additional null checks and error handling.
Copy link

PR description is too short and seems to not fulfill PR template, please fill in

- Introduce DataSource field to Event struct for specifying data origins
- Add Payload field to Event struct for storing request details
- Update TrackWorkRequest function to include DataSource and Payload params
- Modify SearchTweetsRecent handler to use new TrackWorkRequest signature
- Define constants for common data sources (Twitter, Discord, Web, Telegram)
- Ensure server-side timestamp generation for consistency and reliability

This change enhances event tracking granularity and provides more
context for work requests across different data sources.
Copy link

PR description is too short and seems to not fulfill PR template, please fill in

- Remove Timestamp field from Event struct in event.go
- Eliminate timestamp-related operations in event_library.go
- Remove timestamp setting and logging in TrackAndSendEvent function
- Update validateEvent function to exclude timestamp validation

This change centralizes timestamp management to the server side,
ensuring consistency and eliminating potential issues with client-side
time discrepancies. Timestamp handling is now delegated to the server's
logging system or database layer for more accurate and reliable
event timing.
Copy link

PR description is too short and seems to not fulfill PR template, please fill in

Copy link

github-actions bot commented Sep 3, 2024

PR description is too short and seems to not fulfill PR template, please fill in

- Update TrackWorkRequest call in SearchTweetsRecent to include full request payload
- Add logging of work request input in EventTracker

This change improves the tracking and logging of work requests, providing more
comprehensive information for debugging and analysis purposes.
Copy link

github-actions bot commented Sep 4, 2024

PR description is too short and seems to not fulfill PR template, please fill in

- Delete SearchTweetsTrends function from handlers_data.go
- Remove /data/twitter/tweets/trends route from SetupRoutes in routes.go

This change simplifies the API by removing the Twitter trends functionality,
which may have been deprecated or no longer needed.
- Delete sentiment analysis handlers for tweets, Discord, Telegram, and web content
- Remove GetLLMModelsHandler and its associated route
- Remove corresponding route definitions from SetupRoutes function

This change simplifies the API by removing sentiment analysis functionality
and LLM model listing, which may no longer be needed or are being moved to a
different service.
- Implement work request tracking for SearchTweetsProfile
- Add event tracking for SearchTweetsRecent
- Integrate event tracking in SearchTwitterFollowers
- Ensure proper error handling and logging for event tracking
- Reorganize handler functions for better readability
- Remove commented-out ExchangeDiscordTokenHandler function
Copy link

github-actions bot commented Sep 4, 2024

PR description is too short and seems to not fulfill PR template, please fill in

@teslashibe teslashibe requested a review from 5u6r054 September 4, 2024 20:12
@teslashibe teslashibe self-assigned this Sep 4, 2024
@teslashibe teslashibe marked this pull request as ready for review September 4, 2024 20:12
restevens402 and others added 3 commits September 4, 2024 15:35
Added defer statements to ensure streams are properly closed after use in OracleNode methods. This change helps prevent resource leaks and improves code maintainability by consolidating stream closure logic.
Integrate `EventTracker` to monitor worker failures and track task completion outcomes. Adjust log message level related to stream closure errors for consistency.
@teslashibe teslashibe merged commit 97ba448 into main Sep 9, 2024
12 of 16 checks passed
@teslashibe teslashibe deleted the feat-event-tracking-for-work-distribution branch September 9, 2024 22:38
mudler pushed a commit that referenced this pull request Sep 17, 2024
* feat: add event tracking and analytics package

- Implement EventTracker for in-memory event management
- Create EventClient for sending events to external API
- Add configuration options with sensible defaults
- Provide convenience methods for common event types
- Integrate logrus for comprehensive error handling and logging
- Ensure thread-safety with mutex locks

* chore: upadte event_library and add todos

* feat: event tracking package with library

* chore: update readme for event tracking package ready for implementation

* fix: timestamps in UTC

* feat: Improve error handling in TrackAndSendEvent function

- Add error check for nil EventClient
- Log SendEvent errors
- Return SendEvent errors to caller
- Clarify nil EventTracker error message

* adding the event tracker handling to the work distribution.

* chore: add API local base URL and tidy

* update go.mod

* fix go.mod unused import

* Squashed commit of the following:

commit e8e1822
Author: Ettore Di Giacinto <[email protected]>
Date:   Fri Aug 23 17:54:21 2024 +0200

    ci: Rename static.yml to static.yml

    Signed-off-by: Ettore Di Giacinto <[email protected]>

commit efb84f9
Author: Ettore Di Giacinto <[email protected]>
Date:   Fri Aug 23 17:53:15 2024 +0200

    feat(tests): add baseline for an integration test (#527)

    * feat(tests): add baseline for an integration test

    Signed-off-by: mudler <[email protected]>

    * chore: drop obsoleted code

    Signed-off-by: mudler <[email protected]>

    * fix: HasBootnodes otherwise panics if no bootnodes are specified

    Signed-off-by: mudler <[email protected]>

    * chore(integration tests): make it possible to run the tests without generating identity keys

    - Introduce GetP2PMultiAddrs() to retrieve the node id multiaddress which
    is having p2p encapsulation, in order to be used as bootnode
    - Wire up some changes into the constructor of the oracle to allow to
      specify bootnodes and enable random identity generation

    Signed-off-by: mudler <[email protected]>

    * chore: drop unneeded code

    Signed-off-by: mudler <[email protected]>

    ---------

    Signed-off-by: mudler <[email protected]>

commit 6dae3fe
Author: Brendan Playford <[email protected]>
Date:   Mon Aug 19 14:01:08 2024 -0700

    hotfix: .env formatting and description plus runpod and Docker image

commit 5e5853e
Author: Ettore Di Giacinto <[email protected]>
Date:   Mon Aug 19 11:03:16 2024 +0200

    fix(ci): point correctly to main in `goreleaser.yml` (#516)

    * fix(ci): point correctly to main

    Otherwise goreleaser will fail building.

    Fixes: #514

    Signed-off-by: mudler <[email protected]>

    * detect goreleaser

    Signed-off-by: mudler <[email protected]>

    ---------

    Signed-off-by: mudler <[email protected]>

* Add AddrInfo to localWorker in worker_selection.go

This commit adds the AddrInfo struct to the localWorker object in worker_selection.go. This change ensures that localWorker now contains information about its ID and addresses, which may be necessary for future network operations or worker identification.

* Refactor event tracking to include peer ID and other details

Updated event tracking functions to accept additional parameters such as peer ID. Simplified the event structure and ensured that all necessary information is captured and validated before sending events.

* feat : Improve event tracking with TrackWorkRequest with Host peer ID for work requests

- Add TrackWorkRequest in event_library.go to use host node's peer ID
- Modify SearchTweetsRecent in handlers_data.go to pass Host peer ID
- Add null checks for EventTracker and Node in API handlers
- Ensure proper initialization of EventTracker in NewAPI function
- Update API struct to include EventTracker field
- Add debug logging for EventTracker creation and API initialization

This commit enhances the accuracy of event tracking by using the host node's
peer ID instead of the client IP when logging work requests. It also improves
robustness with additional null checks and error handling.

* feat (event): Add DataSource and Payload to event tracking

- Introduce DataSource field to Event struct for specifying data origins
- Add Payload field to Event struct for storing request details
- Update TrackWorkRequest function to include DataSource and Payload params
- Modify SearchTweetsRecent handler to use new TrackWorkRequest signature
- Define constants for common data sources (Twitter, Discord, Web, Telegram)
- Ensure server-side timestamp generation for consistency and reliability

This change enhances event tracking granularity and provides more
context for work requests across different data sources.

* refactor: Move event timestamp handling to server side

- Remove Timestamp field from Event struct in event.go
- Eliminate timestamp-related operations in event_library.go
- Remove timestamp setting and logging in TrackAndSendEvent function
- Update validateEvent function to exclude timestamp validation

This change centralizes timestamp management to the server side,
ensuring consistency and eliminating potential issues with client-side
time discrepancies. Timestamp handling is now delegated to the server's
logging system or database layer for more accurate and reliable
event timing.

* feat(api): enhance work request tracking for SearchTweetsRecent

- Update TrackWorkRequest call in SearchTweetsRecent to include full request payload
- Add logging of work request input in EventTracker

This change improves the tracking and logging of work requests, providing more
comprehensive information for debugging and analysis purposes.

* feat(api): remove Twitter trends endpoint and handler

- Delete SearchTweetsTrends function from handlers_data.go
- Remove /data/twitter/tweets/trends route from SetupRoutes in routes.go

This change simplifies the API by removing the Twitter trends functionality,
which may have been deprecated or no longer needed.

* refactor(api): remove sentiment analysis and LLM model endpoints

- Delete sentiment analysis handlers for tweets, Discord, Telegram, and web content
- Remove GetLLMModelsHandler and its associated route
- Remove corresponding route definitions from SetupRoutes function

This change simplifies the API by removing sentiment analysis functionality
and LLM model listing, which may no longer be needed or are being moved to a
different service.

* feat(api): add event tracking for Twitter-related endpoints

- Implement work request tracking for SearchTweetsProfile
- Add event tracking for SearchTweetsRecent
- Integrate event tracking in SearchTwitterFollowers
- Ensure proper error handling and logging for event tracking
- Reorganize handler functions for better readability
- Remove commented-out ExchangeDiscordTokenHandler function

* Streamlining stream closures in OracleNode methods

Added defer statements to ensure streams are properly closed after use in OracleNode methods. This change helps prevent resource leaks and improves code maintainability by consolidating stream closure logic.

* Update event_library.go

* Restore event tracking for worker failures and task completion

Integrate `EventTracker` to monitor worker failures and track task completion outcomes. Adjust log message level related to stream closure errors for consistency.

---------

Co-authored-by: Bob Stevens <[email protected]>
@mudler mudler added the enhancement New feature or request label Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants