diff --git a/pkg/cmd/login/login.go b/pkg/cmd/login/login.go index 84600bb..1c44e16 100644 --- a/pkg/cmd/login/login.go +++ b/pkg/cmd/login/login.go @@ -36,6 +36,7 @@ type LoginOptions struct { Password string Token string Staging bool + Local bool } func NewLoginCmd(f *cmdutil.Factory) *cobra.Command { @@ -83,6 +84,7 @@ func NewLoginCmd(f *cmdutil.Factory) *cobra.Command { cmd.Flags().StringVarP(&opts.Password, "password", "p", "", "Password of the user.") cmd.Flags().StringVarP(&opts.Token, "token", "t", "", "Single Sign in token of the user.") cmd.Flags().BoolVarP(&opts.Staging, "staging", "s", false, "Use staging server?") + cmd.Flags().BoolVarP(&opts.Local, "local", "l", false, "Use local server?") return cmd } @@ -106,6 +108,18 @@ func loginRun(opts *LoginOptions) { } } + if opts.Local { + endpoint := "http://localhost:8888/" + grpc_endpoint := "localhost:8888" + grpc_ingestion := "http://localhost:8888/logfire.sh" + + err = cfg.UpdateConfig(nil, nil, nil, nil, + nil, nil, &endpoint, &grpc_endpoint, &grpc_ingestion, nil) + if err != nil { + return + } + } + var choiceList = []string{"Magic link", "Password"} if opts.Interactive && opts.Token == "" && opts.Email == "" && opts.Password == "" { @@ -284,6 +298,12 @@ func PasswordSignin(io *iostreams.IOStreams, cfg config.Config, cs *iostreams.Co return err } fmt.Fprintf(io.Out, "\n%s Logged in as %s\n", cs.SuccessIcon(), cs.Bold(response.UserBody.Email)) + + + if !response.UserBody.Onboarded { + fmt.Fprintf(io.Out, "\n%s Looks like your onboarding isn't done yet. Complete it now with `logfire bootstrap` for the full experience! \n \n", cs.WarningIcon()) + } + return nil } @@ -353,5 +373,9 @@ func TokenSignin(IO *iostreams.IOStreams, cfg config.Config, cs *iostreams.Color fmt.Fprintf(IO.Out, "%s Logged in as %s\n", cs.SuccessIcon(), cs.Bold(response.Email)) + if !response.UserBody.Onboarded { + fmt.Fprintf(IO.Out, "\n%s Looks like your onboarding isn't done yet. Complete it now with `logfire bootstrap` for the full experience! \n", cs.WarningIcon()) + } + return nil } diff --git a/pkg/cmd/roundtrip/roundtrip.go b/pkg/cmd/roundtrip/roundtrip.go index 1c9e677..e890ffe 100644 --- a/pkg/cmd/roundtrip/roundtrip.go +++ b/pkg/cmd/roundtrip/roundtrip.go @@ -113,6 +113,18 @@ func PromptRoundTripRun(opts *PromptRoundTripOptions) { id := uuid.New() + istLocation, err := time.LoadLocation("Asia/Kolkata") + if err != nil { + fmt.Println("Error loading IST location:", err) + return + } + + // Get the current time in the IST time zone + currentTime := time.Now().In(istLocation) + + // Format and print the time + formattedTime := currentTime.Format("2006-01-02 15:04:05") + cmd := exec.Command("curl", "--location", cfg.Get().GrpcIngestion, @@ -125,7 +137,7 @@ func PromptRoundTripRun(opts *PromptRoundTripOptions) { "--header", fmt.Sprintf("Github-Run: %v", opts.Run), "--data", - fmt.Sprintf("[{\"dt\":\"2023-06-15T6:00:39.351Z\",\"message\":\"%s\"}]", id), + fmt.Sprintf("[{\"dt\":\"%s\",\"message\":\"%s\"}]",formattedTime, id), ) go grpcutil.WaitForLog(cfg, id, opts.TeamId, opts.SourceId, stop) @@ -223,18 +235,31 @@ func PromptRoundTripRun(opts *PromptRoundTripOptions) { id := uuid.New() + istLocation, err := time.LoadLocation("Asia/Kolkata") + if err != nil { + fmt.Println("Error loading IST location:", err) + return + } + + // Get the current time in the IST time zone + currentTime := time.Now().In(istLocation) + + // Format and print the time + formattedTime := currentTime.Format("2006-01-02 15:04:05") + cmd := exec.Command("curl", "--location", cfg.Get().GrpcIngestion, "--header", "Content-Type: application/json", "--header", - fmt.Sprintf("Authorization: Bearer %s", sourceToken), - "--header", "Diagnostic: True", + "--header", + fmt.Sprintf("Authorization: Bearer %s", sourceToken), "--data", - fmt.Sprintf("[{\"dt\":\"2023-06-15T6:00:39.351Z\",\"message\":\"%s\"}]", id), + fmt.Sprintf("[{\"dt\":\"%s\",\"message\":\"%s\"}]", formattedTime, id), ) + if err != nil { log.Fatal(err) } diff --git a/pkg/cmd/sql/sql.go b/pkg/cmd/sql/sql.go index 8abb92c..06affd4 100644 --- a/pkg/cmd/sql/sql.go +++ b/pkg/cmd/sql/sql.go @@ -4,12 +4,13 @@ import ( "context" "encoding/json" "fmt" - "github.com/logfire-sh/cli/pkg/cmdutil/grpcutil" "log" "net/http" "os" "regexp" + "github.com/logfire-sh/cli/pkg/cmdutil/grpcutil" + "github.com/MakeNowJust/heredoc" "github.com/logfire-sh/cli/internal/config" "github.com/logfire-sh/cli/internal/prompter" @@ -75,7 +76,10 @@ func NewCmdSql(f *cmdutil.Factory) *cobra.Command { func GetRecommendations(opts *SQLQueryOptions, cfg config.Config) { opts.IO.StartProgressIndicatorWithLabel("Getting recommendations, please wait...") - recommendations, _ := APICalls.GetRecommendations(cfg.Get().Token, cfg.Get().EndPoint, opts.TeamId, cfg.Get().Role) + recommendations, err := APICalls.GetRecommendations(cfg.Get().Token, cfg.Get().EndPoint, opts.TeamId, cfg.Get().Role) + if err != nil { + fmt.Fprintf(opts.IO.ErrOut, "%s",err) + } var options []string @@ -230,7 +234,7 @@ func createGrpcSource(sources []sourceModels.Source) []*pb.Source { } // getSQL makes the actual grpc call to connect with flink-service. -func getSQL(client pb.FlinkServiceClient, sources []*pb.Source, opts *SQLQueryOptions) (*pb.SQLResponse, error) { +func getSQL(client pb.FilterServiceClient, sources []*pb.Source, opts *SQLQueryOptions) (*pb.SQLResponse, error) { // Prepare the request payload request := &pb.SQLRequest{ Sql: opts.SQLQuery, diff --git a/pkg/cmd/stream/livetail/livetail.go b/pkg/cmd/stream/livetail/livetail.go index ef11d1e..5b9f488 100644 --- a/pkg/cmd/stream/livetail/livetail.go +++ b/pkg/cmd/stream/livetail/livetail.go @@ -97,7 +97,7 @@ func livetailRun(opts *LivetailOptions) { FieldBasedFilters: []*pb.FieldBasedFilter{}, SearchQueries: []string{}, Sources: []*pb.Source{}, - BatchSize: 100, + BatchSize: 15, IsScrollDown: true, } @@ -235,6 +235,7 @@ func livetailRun(opts *LivetailOptions) { for { response, err := filterService.Client.GetFilteredData(context.Background(), request) if err != nil { + //log.Fatal(err) continue } diff --git a/pkg/cmd/stream/view/view.go b/pkg/cmd/stream/view/view.go index 38887de..f500016 100644 --- a/pkg/cmd/stream/view/view.go +++ b/pkg/cmd/stream/view/view.go @@ -10,7 +10,6 @@ import ( "time" "github.com/logfire-sh/cli/pkg/cmdutil/grpcutil" - "google.golang.org/protobuf/types/known/timestamppb" "github.com/MakeNowJust/heredoc" "github.com/logfire-sh/cli/internal/config" @@ -82,7 +81,7 @@ func ViewStreamRun(opts *ViewStreamOptions) { FieldBasedFilters: []*pb.FieldBasedFilter{}, SearchQueries: []string{}, Sources: []*pb.Source{}, - BatchSize: 100, + BatchSize: 15, IsScrollDown: true, } @@ -109,37 +108,12 @@ func ViewStreamRun(opts *ViewStreamOptions) { return } - if !view.DateFilter.StartDate.IsZero() { - request.DateTimeFilter.StartTimeStamp = timestamppb.New(view.DateFilter.StartDate) - - if !view.DateFilter.EndDate.IsZero() { - request.DateTimeFilter.EndTimeStamp = timestamppb.New(view.DateFilter.EndDate) - } - } - - if len(view.SearchFilter) != 0 { - for _, v := range view.SearchFilter { - if v.Key != "" { - if v.Condition != "" { - if v.Value != "" { - request.FieldBasedFilters = append(request.FieldBasedFilters, &pb.FieldBasedFilter{ - FieldName: v.Key, - FieldValue: v.Value, - Operator: pb.FieldBasedFilter_Operator(pb.FieldBasedFilter_Operator_value[v.Condition]), - }) - } - } - } - } - } - - if len(view.TextFilter) != 0 { - request.SearchQueries = append(request.SearchQueries, view.TextFilter...) - } - pbSources := grpcutil.CreateGrpcSource(view.SourcesFilter) var sourcesOffset = make(map[string]uint64) + request.Sources = pbSources + request.ViewID = view.Id + filterService := grpcutil.NewFilterService() defer filterService.CloseConnection() diff --git a/pkg/cmdutil/APICalls/source_api_calls.go b/pkg/cmdutil/APICalls/source_api_calls.go index 05c481a..e5de3f0 100644 --- a/pkg/cmdutil/APICalls/source_api_calls.go +++ b/pkg/cmdutil/APICalls/source_api_calls.go @@ -223,7 +223,7 @@ func CreateSource(token, endpoint string, teamId, sourceName, platform string) ( defer conn.Close() // Create a gRPC client - grpcClient := pb.NewFlinkServiceClient(conn) + grpcClient := pb.NewFilterServiceClient(conn) grpcClient.CreateSource(context.Background(), pbSource) diff --git a/pkg/cmdutil/grpcutil/grpc.go b/pkg/cmdutil/grpcutil/grpc.go index e8c4d6f..7275a09 100644 --- a/pkg/cmdutil/grpcutil/grpc.go +++ b/pkg/cmdutil/grpcutil/grpc.go @@ -2,18 +2,22 @@ package grpcutil import ( "context" + "github.com/logfire-sh/cli/internal/config" "github.com/logfire-sh/cli/pkg/cmd/sources/models" pb "github.com/logfire-sh/cli/services/flink-service" "google.golang.org/grpc" + + //"google.golang.org/grpc/credentials" + "log" + "google.golang.org/grpc/credentials" "google.golang.org/grpc/metadata" - "log" ) type FilterService struct { conn *grpc.ClientConn - Client pb.FlinkServiceClient + Client pb.FilterServiceClient } func authUnaryInterceptor(kv ...string) func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error { @@ -34,20 +38,19 @@ func (fs *FilterService) CloseConnection() { func NewFilterService(kv ...string) *FilterService { cfg, _ := config.NewConfig() grpc_url := cfg.Get().GrpcEndpoint - //grpc_url := "localhost:50051" allParams := make([]string, 0, len(kv)+2) allParams = append(allParams, "Authorization", "Bearer "+cfg.Get().Token) - for _, arg := range kv { - allParams = append(allParams, arg) - } + allParams = append(allParams, kv...) + conn, err := grpc.Dial(grpc_url, grpc.WithTransportCredentials(credentials.NewClientTLSFromCert(nil, "")), grpc.WithUnaryInterceptor(authUnaryInterceptor(allParams...)), grpc.WithUserAgent("Logfire-cli")) - //conn, err := grpc.Dial(grpc_url, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithUnaryInterceptor(authUnaryInterceptor(allParams...)), grpc.WithUserAgent("Logfire-cli")) + // conn, err := grpc.Dial(grpc_url, grpc.WithInsecure(), grpc.WithUnaryInterceptor(authUnaryInterceptor(allParams...)), grpc.WithUserAgent("Logfire-cli")) + if err != nil { log.Fatalf("Failed to dial server: %v", err) } // Create a gRPC client - client := pb.NewFlinkServiceClient(conn) + client := pb.NewFilterServiceClient(conn) return &FilterService{ conn: conn, @@ -85,40 +88,6 @@ func AddOffset(sources []*pb.Source, offset map[string]uint64) []*pb.Source { return sources } -func CreateSource(request *pb.Source) { - cfg, _ := config.NewConfig() - grpc_url := cfg.Get().GrpcEndpoint - conn, err := grpc.Dial(grpc_url, grpc.WithTransportCredentials(credentials.NewClientTLSFromCert(nil, ""))) - if err != nil { - log.Fatalf("Failed to dial server: %v", err) - } - defer conn.Close() - - // Create a gRPC client - client := pb.NewFlinkServiceClient(conn) - - _, err = client.CreateSource(context.Background(), request) - if err != nil { - return - } - if err != nil { - return - } -} - -// GetFilteredData makes the actual grpc call to connect with flink-service. -func GetFilteredData(client pb.FlinkServiceClient, request *pb.FilterRequest) (*pb.FilteredRecords, error) { - // Prepare the request payload - - // Invoke the gRPC method - response, err := client.GetFilteredData(context.Background(), request) - if err != nil { - return nil, err - } - - return response, nil -} - func GetOffsets(offsets map[string]uint64, records []*pb.FilteredRecord) map[string]uint64 { for _, record := range records { if offsets[record.SourceName] == 0 || record.Offset >= offsets[record.SourceName] { diff --git a/pkg/cmdutil/grpcutil/roundtrip_grpc.go b/pkg/cmdutil/grpcutil/roundtrip_grpc.go index ae432d5..62ea044 100644 --- a/pkg/cmdutil/grpcutil/roundtrip_grpc.go +++ b/pkg/cmdutil/grpcutil/roundtrip_grpc.go @@ -2,6 +2,7 @@ package grpcutil import ( "context" + "log" "time" "github.com/google/uuid" @@ -47,7 +48,9 @@ func WaitForLog(cfg config.Config, id uuid.UUID, teamId string, sourceId string, response, err := filterService.Client.GetFilteredData(context.Background(), request) if err != nil { - continue + log.Printf("Request: %v", request) + log.Printf("Error %v", err) + return } if len(response.Records) > 0 {