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

Unable to compile: error: github.com/grafana/[email protected]/pkg/promtail/client/client.go:133:69: cannot use false (untyped bool constant) as config.HTTPClientOption value in argument to config.NewClientFromConfig #8541

Open
tathagatachowdhury opened this issue Feb 16, 2023 · 2 comments

Comments

@tathagatachowdhury
Copy link

I had raised the issue before and it was closed as I had not provided enough details, I apologize for that.
#8540

Please find below the details.

While trying to create new promtail client using
https://pkg.go.dev/github.com/grafana/[email protected]/pkg/promtail/client#New

Using golang v1.18
OS: rhel 8

I am trying to create promtail client to push logs. I am receiving the error when I try to create the client.

Below is the code segment from where I am trying to create the promtail client.


package main

import (
	"log"
	"net/url"
	"os"
	"time"

	"github.com/cortexproject/cortex/pkg/util/flagext"
	lokiLogger "github.com/go-kit/log"
	"github.com/grafana/loki/pkg/promtail/client"
	"github.com/prometheus/common/config"
	"github.com/prometheus/common/model"
)

func main() {
	c := config.HTTPClientConfig{}
	var label model.LabelSet
	label["service"] = "service1"
	label["environment"] = "dev"
	labelSet := lokiflag.LabelSet{
		label,
	}
	url, err := url.Parse("<loki service url>")
	if err != nil {
		log.Fatalf("error in url parsing endpoint: %v, with error: %v", "<loki service url>", err)
	}
	Url := flagext.URLValue{
		url,
	}
	lokiConfig := client.Config{
		URL:            Url,
		BatchWait:      5 * time.Second,
		BatchSize:      10000,
		ExternalLabels: labelSet,
		TenantID:       "development",
		Client:         c,
	}
	lokiLog := lokiLogger.NewLogfmtLogger(os.Stdout)
	loki, err := client.New(lokiConfig, lokiLog)
	if err != nil {
		log.Fatalf("error in getting loki client: %v", err)
	}
}

Please note that this is not the complete code but a part of it, where I am trying to create the promtail client.

When I compile it, the below error:
/github.com/grafana/[email protected]/pkg/promtail/client/client.go:133:69: cannot use false (untyped bool constant) as config.HTTPClientOption value in argument to config.NewClientFromConfig

Please let me know if further details are required.

@chaudum
Copy link
Contributor

chaudum commented Feb 16, 2023

I am not sure about the actual error, but I want to point out that you are using a very out-of-date version of the Loki package (from Aug 2020)

Screenshot 2023-02-16 at 10-32-12 client package - github com_grafana_loki_pkg_promtail_client - Go Packages

This is due to the fact that we don't use Go's semantic versioning for modules - it basically stopped working with Loki 2.0, see initial issue.

You should install the latest version of Loki using a commit hash or branch name:

go get -u github.com/grafana/[email protected]

You will find a lot of things changed compared to the version you are using. Please let me know if the issue persists after updating.

For reference how to use the client, you can look at https://github.com/grafana/loki/blob/main/clients/pkg/promtail/client/client.go#L188

@tathagatachowdhury
Copy link
Author

Thank you for the reply.

I based my code on the packages published in pkg.go.dev.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants