Skip to content

Commit

Permalink
feat(#15): assign names to agents
Browse files Browse the repository at this point in the history
  • Loading branch information
mcharytoniuk committed Aug 12, 2024
1 parent 42698b3 commit 4282c51
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 6 deletions.
1 change: 1 addition & 0 deletions agent/AgentConfiguration.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package agent
import "time"

type AgentConfiguration struct {
Name string
ReportingIntervalMiliseconds uint
}

Expand Down
16 changes: 16 additions & 0 deletions agent/LlamaCppObserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/distantmagic/paddler/goroutine"
"github.com/distantmagic/paddler/llamacpp"
"github.com/distantmagic/paddler/management"
"github.com/google/uuid"
"github.com/hashicorp/go-hclog"
)

Expand All @@ -26,6 +27,19 @@ func (self *LlamaCppObserver) ObserveAndReport(
"host", self.LlamaCppClient.LlamaCppConfiguration.HttpAddress.GetHostWithPort(),
)

agentRuntimeId, err := uuid.NewV7()

if err != nil {
serverEventsChannel <- goroutine.ResultMessage{
Comment: "failed to generate agent uuid",
Error: err,
}

return
}

agentRuntimeIdString := agentRuntimeId.String()

llamaCppHealthStatusChannel := make(chan llamacpp.LlamaCppHealthStatus)

defer close(llamaCppHealthStatusChannel)
Expand All @@ -45,6 +59,8 @@ func (self *LlamaCppObserver) ObserveAndReport(
serverEventsChannel,
self.ExternalLlamaCppConfiguration,
&llamaCppHealthStatus,
agentRuntimeIdString,
self.AgentConfiguration.Name,
)

cancel()
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/aws/aws-sdk-go-v2 v1.27.1
github.com/aws/aws-sdk-go-v2/config v1.27.17
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.4
github.com/google/uuid v1.6.0
github.com/hashicorp/go-hclog v1.6.2
github.com/puzpuzpuz/xsync/v3 v3.4.0
github.com/smira/go-statsd v1.3.3
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hashicorp/go-hclog v1.6.2 h1:NOtoftovWkDheyUM/8JW3QMiXyxJK3uHRK7wV04nD2I=
github.com/hashicorp/go-hclog v1.6.2/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
Expand Down
4 changes: 0 additions & 4 deletions llamacpp/LlamaCppClient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ func TestHealthIsObtained(t *testing.T) {
func TestCompletionsAreGenerated(t *testing.T) {
responseChannel := make(chan LlamaCppCompletionToken)

defer close(responseChannel)

go llamaCppClient.GenerateCompletion(
context.Background(),
responseChannel,
Expand Down Expand Up @@ -69,8 +67,6 @@ func TestCompletionsAreGenerated(t *testing.T) {
func TestJsonSchemaConstrainedCompletionsAreGenerated(t *testing.T) {
responseChannel := make(chan LlamaCppCompletionToken)

defer close(responseChannel)

go llamaCppClient.GenerateCompletion(
context.Background(),
responseChannel,
Expand Down
1 change: 1 addition & 0 deletions loadbalancer/LlamaCppTargetConfiguration.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ import "github.com/distantmagic/paddler/llamacpp"

type LlamaCppTargetConfiguration struct {
Id string
Name string
LlamaCppConfiguration *llamacpp.LlamaCppConfiguration `json:"llama_cpp_configuration"`
}
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ func main() {
Value: DefaultManagementScheme,
Destination: &agent.ManagementServerConfiguration.HttpAddress.Scheme,
},
&cli.StringFlag{
Name: "name",
Value: "",
Destination: &agent.AgentConfiguration.Name,
},
&cli.StringFlag{
Name: "status-server-host",
Value: "127.0.0.1",
Expand Down
5 changes: 4 additions & 1 deletion management/Client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ func (self *Client) ReportLlamaCppHealthStatus(
serverEventsChannel chan<- goroutine.ResultMessage,
llamaCppConfiguration *llamacpp.LlamaCppConfiguration,
llamaCppHealthStatus *llamacpp.LlamaCppHealthStatus,
llamaCppTargetId string,
llamaCppTargetName string,
) {
jsonData, err := json.Marshal(&RegisterTargetRequest{
LlamaCppHealthStatus: llamaCppHealthStatus,
LlamaCppTargetConfiguration: &loadbalancer.LlamaCppTargetConfiguration{
Id: llamaCppConfiguration.String(),
Id: llamaCppTargetId,
Name: llamaCppTargetName,
LlamaCppConfiguration: llamaCppConfiguration,
},
})
Expand Down
1 change: 1 addition & 0 deletions management/RegisterTargetRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ import (
type RegisterTargetRequest struct {
LlamaCppHealthStatus *llamacpp.LlamaCppHealthStatus `json:"llama_cpp_health_status"`
LlamaCppTargetConfiguration *loadbalancer.LlamaCppTargetConfiguration `json:"llama_cpp_target_configuration"`
PaddlerAgentName string `json:"paddler_agent_name"`
}
6 changes: 5 additions & 1 deletion management/resources/views/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ <h2>Registered Agents ({{.LoadBalancerStatus.RegisteredTargets}} Total)</h2>
{{end}}
"
>
<p class="metric">
<span class="metric__name">Name:</span>
<span class="metric__value">{{.LlamaCppTargetConfiguration.Name}}</span>
</p>
<p class="metric">
<span class="metric__name">Host:</span>
<span class="metric__value">{{.LlamaCppTargetConfiguration}}</span>
<span class="metric__value">{{.LlamaCppTargetConfiguration.LlamaCppConfiguration}}</span>
</p>
<p class="metric">
<span class="metric__name">Status:</span>
Expand Down

0 comments on commit 4282c51

Please sign in to comment.