Skip to content

Instantly share code, notes, and snippets.

@chaudum
Created May 5, 2022 13:30
Show Gist options
  • Save chaudum/90bf381981aa6bea7a20fa9462b53c42 to your computer and use it in GitHub Desktop.
Save chaudum/90bf381981aa6bea7a20fa9462b53c42 to your computer and use it in GitHub Desktop.
package main
import (
"context"
"fmt"
"os"
"time"
"github.com/grafana/loki/pkg/logproto"
"github.com/weaveworks/common/user"
grpc "google.golang.org/grpc"
)
type ingesterClient struct {
logproto.QuerierClient
}
func main() {
cc, err := grpc.Dial("localhost:9095", grpc.WithInsecure())
if err != nil {
fmt.Printf("failed to dial grpc: %s\n", err)
os.Exit(1)
}
cli := ingesterClient{
QuerierClient: logproto.NewQuerierClient(cc),
}
for {
func() {
fmt.Printf("current time: %s\n", time.Now().UTC())
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
ctx = user.InjectOrgID(ctx, "fake")
ctx, err = user.InjectIntoGRPCRequest(ctx)
if err != nil {
fmt.Printf("failed to inject org_id: %s\n", err)
os.Exit(1)
}
req := logproto.GetChunkIDsRequest{
Matchers: `{os="linux"}`,
Start: time.Now().Add(-1 * time.Hour),
End: time.Now(),
}
res, err := cli.GetChunkIDs(ctx, &req)
if err != nil {
fmt.Printf("request failed: %s\n", err)
os.Exit(1)
}
fmt.Printf("gRPC response: %s\n", res.GoString())
time.Sleep(time.Second)
}()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment