Skip to content

Commit 037bcac

Browse files
authored
Exclude agents without valid version when looking at runtime logs (#635)
* exclude agents without valid version * only exclude empty version for logs
1 parent a675348 commit 037bcac

1 file changed

Lines changed: 15 additions & 12 deletions

File tree

cmd/lk/agent.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ func createAgentConfig(ctx context.Context, cmd *cli.Command) error {
522522
func deployAgent(ctx context.Context, cmd *cli.Command) error {
523523
var req *lkproto.DeployAgentRequest
524524

525-
agentId, err := getAgentID(ctx, cmd, workingDir, tomlFilename)
525+
agentId, err := getAgentID(ctx, cmd, workingDir, tomlFilename, false)
526526
if err != nil {
527527
return err
528528
}
@@ -588,7 +588,7 @@ func deployAgent(ctx context.Context, cmd *cli.Command) error {
588588
}
589589

590590
func getAgentStatus(ctx context.Context, cmd *cli.Command) error {
591-
agentID, err := getAgentID(ctx, cmd, workingDir, tomlFilename)
591+
agentID, err := getAgentID(ctx, cmd, workingDir, tomlFilename, false)
592592
if err != nil {
593593
return err
594594
}
@@ -649,7 +649,7 @@ func getAgentStatus(ctx context.Context, cmd *cli.Command) error {
649649
}
650650

651651
func restartAgent(ctx context.Context, cmd *cli.Command) error {
652-
agentID, err := getAgentID(ctx, cmd, workingDir, tomlFilename)
652+
agentID, err := getAgentID(ctx, cmd, workingDir, tomlFilename, false)
653653
if err != nil {
654654
return err
655655
}
@@ -721,7 +721,7 @@ func updateAgent(ctx context.Context, cmd *cli.Command) error {
721721
}
722722

723723
func rollbackAgent(ctx context.Context, cmd *cli.Command) error {
724-
agentID, err := getAgentID(ctx, cmd, workingDir, tomlFilename)
724+
agentID, err := getAgentID(ctx, cmd, workingDir, tomlFilename, false)
725725
if err != nil {
726726
return err
727727
}
@@ -753,7 +753,7 @@ func rollbackAgent(ctx context.Context, cmd *cli.Command) error {
753753
}
754754

755755
func getLogs(ctx context.Context, cmd *cli.Command) error {
756-
agentID, err := getAgentID(ctx, cmd, workingDir, tomlFilename)
756+
agentID, err := getAgentID(ctx, cmd, workingDir, tomlFilename, true)
757757
if err != nil {
758758
return err
759759
}
@@ -762,7 +762,7 @@ func getLogs(ctx context.Context, cmd *cli.Command) error {
762762
}
763763

764764
func deleteAgent(ctx context.Context, cmd *cli.Command) error {
765-
agentID, err := getAgentID(ctx, cmd, workingDir, tomlFilename)
765+
agentID, err := getAgentID(ctx, cmd, workingDir, tomlFilename, false)
766766
if err != nil {
767767
return err
768768
}
@@ -815,7 +815,7 @@ func deleteAgent(ctx context.Context, cmd *cli.Command) error {
815815
}
816816

817817
func listAgentVersions(ctx context.Context, cmd *cli.Command) error {
818-
agentID, err := getAgentID(ctx, cmd, workingDir, tomlFilename)
818+
agentID, err := getAgentID(ctx, cmd, workingDir, tomlFilename, false)
819819
if err != nil {
820820
return err
821821
}
@@ -914,7 +914,7 @@ func listAgents(ctx context.Context, cmd *cli.Command) error {
914914
}
915915

916916
func listAgentSecrets(ctx context.Context, cmd *cli.Command) error {
917-
agentID, err := getAgentID(ctx, cmd, workingDir, tomlFilename)
917+
agentID, err := getAgentID(ctx, cmd, workingDir, tomlFilename, false)
918918
if err != nil {
919919
return err
920920
}
@@ -949,7 +949,7 @@ func listAgentSecrets(ctx context.Context, cmd *cli.Command) error {
949949
}
950950

951951
func updateAgentSecrets(ctx context.Context, cmd *cli.Command) error {
952-
agentID, err := getAgentID(ctx, cmd, workingDir, tomlFilename)
952+
agentID, err := getAgentID(ctx, cmd, workingDir, tomlFilename, false)
953953
if err != nil {
954954
return err
955955
}
@@ -983,7 +983,7 @@ func updateAgentSecrets(ctx context.Context, cmd *cli.Command) error {
983983
return fmt.Errorf("failed to update agent secrets: %s", resp.Message)
984984
}
985985

986-
func getAgentID(ctx context.Context, cmd *cli.Command, agentDir string, tomlFileName string) (string, error) {
986+
func getAgentID(ctx context.Context, cmd *cli.Command, agentDir string, tomlFileName string, excludeEmptyVersion bool) (string, error) {
987987
agentID := cmd.String("id")
988988
if agentID == "" {
989989
configExists, err := requireConfig(agentDir, tomlFileName)
@@ -997,7 +997,7 @@ func getAgentID(ctx context.Context, cmd *cli.Command, agentDir string, tomlFile
997997
}
998998
agentID = lkConfig.Agent.ID
999999
} else {
1000-
agentID, err = selectAgent(ctx, cmd)
1000+
agentID, err = selectAgent(ctx, cmd, excludeEmptyVersion)
10011001
if err != nil {
10021002
return "", err
10031003
}
@@ -1014,7 +1014,7 @@ func getAgentID(ctx context.Context, cmd *cli.Command, agentDir string, tomlFile
10141014
return agentID, nil
10151015
}
10161016

1017-
func selectAgent(ctx context.Context, _ *cli.Command) (string, error) {
1017+
func selectAgent(ctx context.Context, _ *cli.Command, excludeEmptyVersion bool) (string, error) {
10181018
var agents *lkproto.ListAgentsResponse
10191019
var err error
10201020

@@ -1036,6 +1036,9 @@ func selectAgent(ctx context.Context, _ *cli.Command) (string, error) {
10361036

10371037
var agentNames []huh.Option[string]
10381038
for _, agent := range agents.Agents {
1039+
if excludeEmptyVersion && agent.Version == "---" {
1040+
continue
1041+
}
10391042
name := agent.AgentId + " " + util.Dimmed("deployed "+agent.DeployedAt.AsTime().Format(time.RFC3339))
10401043
agentNames = append(agentNames, huh.Option[string]{Key: name, Value: agent.AgentId})
10411044
}

0 commit comments

Comments
 (0)