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

Add lakefs instrumentation #6217

Merged
merged 21 commits into from
Aug 7, 2023
Merged

Conversation

N-o-Z
Copy link
Member

@N-o-Z N-o-Z commented Jul 17, 2023

Linked Issue

Closes #6216

@N-o-Z N-o-Z added BI exclude-changelog PR description should not be included in next release changelog labels Jul 17, 2023
@N-o-Z N-o-Z requested review from nopcoder and rmoff July 17, 2023 12:35
@N-o-Z N-o-Z self-assigned this Jul 17, 2023
@github-actions
Copy link

github-actions bot commented Jul 17, 2023

🎊 PR Preview 0268f29 has been successfully built and deployed to https://treeverse-lakeFS-preview-pr-6217.surge.sh

🕐 Build time: 0.018s

🤖 By surge-preview

Comment on lines 221 to 224
_, k8s := os.LookupEnv("KUBERNETES_SERVICE_HOST")
lakefsAccessKeyID := os.Getenv("LAKEFS_ACCESS_KEY_ID")
quickstart, _ := strconv.ParseBool(os.Getenv("QUICKSTART"))
_, statErr := StatFunc("/.dockerenv")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. separate keys for docker / k8s / sample|quickstart
  2. stats - global string point to dockerenv filename instead of override stat func

treeverse/lakefs:latest

- name: Build and push lakefs quickstart
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we will get to the point where we will need to version quickstart images I prefer to keep it simple and think of alternative way to identify quickstart usage - arg? or just env var and not new image.

Copy link
Contributor

@rmoff rmoff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not in favour of a new Docker image for quickstart, sorry. This is for two reasons:

  1. Quickstart should ideally be a "runway" for users to get up and running (and take off, to continue the analogy)—using a dedicated image is like a dead-end road. There are exceptions to this rule but they need to be a good one, not just to make it easier to instrument
  2. If we use a dedicated image we need to explain to the user why, and that explanation is too thin to hold weight IMHO

@N-o-Z
Copy link
Member Author

N-o-Z commented Jul 17, 2023

I'm not in favour of a new Docker image for quickstart, sorry. This is for two reasons:

  1. Quickstart should ideally be a "runway" for users to get up and running (and take off, to continue the analogy)—using a dedicated image is like a dead-end road. There are exceptions to this rule but they need to be a good one, not just to make it easier to instrument
  2. If we use a dedicated image we need to explain to the user why, and that explanation is too thin to hold weight IMHO

Appreciate the feedback, please suggest an alternative for identifying execution as part of the quickstart guide

@N-o-Z N-o-Z requested a review from nopcoder July 17, 2023 13:46
@@ -206,13 +212,43 @@ func (m *KVMetadataManager) IsInitialized(ctx context.Context) (bool, error) {
return !setupTimestamp.IsZero(), nil
}

// DockerFileExists For testing purposes
var DockerFileExists = "/.dockerenv"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DockeEnvExists

@N-o-Z N-o-Z requested a review from nopcoder July 17, 2023 14:00
func (m *KVMetadataManager) GetMetadata(ctx context.Context) (map[string]string, error) {
metadata := make(map[string]string)
metadata["lakefs_version"] = m.version
metadata["lakefs_kv_type"] = m.kvType
metadata["golang_version"] = runtime.Version()
metadata["architecture"] = runtime.GOARCH
metadata["os"] = runtime.GOOS
getInstrumentation(metadata)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest to split into functions

Suggested change
getInstrumentation(metadata)
metadata["is_k8s"] = inK8sMetadata()
metadata["is_docker"] = inDockerMetadata()
metadata["instrumentation"] = instrumentationMetadata()
func isK8sMetadata() string {
	_, k8s := os.LookupEnv("KUBERNETES_SERVICE_HOST")
	return strconv.FormatBool(k8s)
}

func isDockerMetadata() string {
	var err error
	if DockerFileExists != "" {
		_, err = os.Stat(DockerFileExists)
	}
	return strconv.FormatBool(err == nil)
}

func instrumentationMetadata() string {
	lakefsAccessKeyID := os.Getenv("LAKEFS_ACCESS_KEY_ID")
	if strings.HasSuffix(lakefsAccessKeyID, "LKFSSAMPLES") {
		return InstrumentationSamplesRepo
	}
	quickstart, _ := strconv.ParseBool(os.Getenv("QUICKSTART"))
	if quickstart {
		return InstrumentationQuickstart
	}
	return InstrumentationRun
}

@N-o-Z N-o-Z requested a review from nopcoder July 17, 2023 14:13
Copy link
Contributor

@nopcoder nopcoder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! looks good - if there is an alternative for the docker image I'm +1

@N-o-Z N-o-Z requested review from rmoff and nopcoder July 18, 2023 11:51
@N-o-Z
Copy link
Member Author

N-o-Z commented Jul 18, 2023

@nopcoder Please re-review quickstart refactor

Comment on lines 233 to 241
switch {
case strings.HasSuffix(lakefsAccessKeyID, "LKFSSAMPLES"):
return InstrumentationSamplesRepo
}
quickstart, _ := strconv.ParseBool(os.Getenv("QUICKSTART"))
if quickstart {
case strings.HasSuffix(lakefsAccessKeyID, "QUICKSTART"):
return InstrumentationQuickstart
default:
return InstrumentationRun
}
return InstrumentationRun
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

os.Exit(1)
}
accessKey := "AKIAIOSFOLQUICKSTART"
secretKey := "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will need to lint ignore - gosec

Comment on lines 54 to 55
accessKey := "AKIAIOSFOLQUICKSTART"
secretKey := "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
accessKey := "AKIAIOSFOLQUICKSTART"
secretKey := "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
const (
accessKey = "AKIAIOSFOLQUICKSTART"
secretKey = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
)

Comment on lines 59 to 60
fmt.Printf("Access Key ID : %s \n", accessKey)
fmt.Printf("Secret Access Key: %s \n", secretKey)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fmt.Printf("Access Key ID : %s \n", accessKey)
fmt.Printf("Secret Access Key: %s \n", secretKey)
fmt.Printf("Access Key ID : %s\n", accessKey)
fmt.Printf("Secret Access Key: %s\n", secretKey)

if useLocal() {
return config.NewLocalConfig()
}
quickStart := useConfig(config.QuickStartConfiguration)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to verify that not both are on?

Copy link
Member Author

@N-o-Z N-o-Z Jul 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure we wan't to enforce mutual exclusion - do you see an issue with it?

}

func useLocal() bool {
res, err := rootCmd.PersistentFlags().GetBool(config.UseLocalConfiguration)
func validateQuickstartEnv(cfg *config.Config) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name is a bit misleading as we verify the database and blockstore - but we override the configuration and not set them as default.
If we like to verify that the default as not override we should do the same as local - setup the right defaults for quick-start and verify after the configuration is loaded that the user didn't override the default for all the values we require.

@N-o-Z N-o-Z requested a review from nopcoder July 18, 2023 13:34
fmt.Printf("Secret Access Key: %s\n", config.DefaultQuickstartSecretKey)
}

func useConfig(cfg string) bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func useConfig(cfg string) bool {
func useConfig(flagName string) bool {

if useLocal() {
return config.NewLocalConfig()
}
quickStart := useConfig(config.QuickstartConfiguration)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest, if it is more clear and less references of calling NewConfig

name := ""
configurations := []string{config.QuickstartConfiguration, config.UseLocalConfiguration}
if idx := slices.IndexFunc(configurations, func(f string) bool { return useConfig(f); }); idx != -1 {
  name = configurations[idx]
}

cfg, err := config.NewConfig(name)
if err != nil {
  return nil, err
}

if name == config.QuickstartConfiguration {
  validateQuickstartEnv(cfg)
}
return cfg, nil

func setDefaults(local bool) {
if local {
func setDefaults(cfgType string) {
switch {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
switch {
switch cfgType {

@N-o-Z N-o-Z requested a review from nopcoder July 18, 2023 14:50
Copy link
Contributor

@nopcoder nopcoder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Contributor

@rmoff rmoff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Firstly: I think this is a positive change and a good direction 👍🏻

However 😬 I have some nits, as well as a blocker.

🛑 Potential blocker: This change will remove quickstart email capture

From a DevEx point of view I am 💯 💯 💯 💯 💯 in favour of this, but last time I did it it caused ructions elsewhere ;)

We need to make it clear to all stakeholders (@iddoavn, @einato , @ozkatz et al) the impact and get agreement from them.

The solution here is to implement #6033 / #6204 first.

Nits

Pre-create the quickstart repo

Since we know they're running the quickstart, we should pre-create the quickstart sample repo

Sample repo instructions

These need updating for the new --quickstart flag

Startup Banner

The startup banner should reflect the startup mode; if the user is using --quickstart then echo the pre-baked creds to stdout and not direct them to complete the setup process at http://127.0.0.1:8000/setup

You already have this change but only in the docs, whereas it should be conditional and in the lakeFS output itself

i.e. instead the current startup banner:


     ██╗      █████╗ ██╗  ██╗███████╗███████╗███████╗
     ██║     ██╔══██╗██║ ██╔╝██╔════╝██╔════╝██╔════╝
     ██║     ███████║█████╔╝ █████╗  █████╗  ███████╗
     ██║     ██╔══██║██╔═██╗ ██╔══╝  ██╔══╝  ╚════██║
     ███████╗██║  ██║██║  ██╗███████╗██║     ███████║
     ╚══════╝╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝╚═╝     ╚══════╝

│
│ If you're running lakeFS locally for the first time,
│     complete the setup process at http://127.0.0.1:8000/setup
│

│
│ For more information on how to use lakeFS,
│     check out the docs at https://docs.lakefs.io/quickstart/
│

│
│ For support or any other question,                            >(._.)<
│     join our Slack channel https://docs.lakefs.io/slack         (  )_
│

Should be this for quickstart:


     ██╗      █████╗ ██╗  ██╗███████╗███████╗███████╗
     ██║     ██╔══██╗██║ ██╔╝██╔════╝██╔════╝██╔════╝
     ██║     ███████║█████╔╝ █████╗  █████╗  ███████╗
     ██║     ██╔══██║██╔═██╗ ██╔══╝  ██╔══╝  ╚════██║
     ███████╗██║  ██║██║  ██╗███████╗██║     ███████║
     ╚══════╝╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝╚═╝     ╚══════╝

│
│ You are running lakeFS in quickstart mode. 
|   Login at http://127.0.0.1:8000/
│     
|    Access Key ID    : AKIAIOSFOLQUICKSTART
│    Secret Access Key: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
│

│
│ For more information on how to use lakeFS,
│     check out the docs at https://docs.lakefs.io/quickstart/
│

│
│ For support or any other question,                            >(._.)<
│     join our Slack channel https://docs.lakefs.io/slack         (  )_
│

I realise that the creds are echoed earlier on as part of the bootup but from a DX point of view it's not obvious particularly when there is a user-facing dialog later on in the stdout

CleanShot_2023-07-19_at_10 25 15

@N-o-Z
Copy link
Member Author

N-o-Z commented Jul 19, 2023

Firstly: I think this is a positive change and a good direction 👍🏻

However grimacing I have some nits, as well as a blocker.

Potential blocker: This change will remove quickstart email capture

From a DevEx point of view I am 100 100 100 100 100 in favour of this, but last time I did it it caused ructions elsewhere ;)

We need to make it clear to all stakeholders (@iddoavn, @einato , @ozkatz et al) the impact and get agreement from them.

The solution here is to implement #6033 / #6204 first.

Nits

Pre-create the quickstart repo

Since we know they're running the quickstart, we should pre-create the quickstart sample repo

Sample repo instructions

These need updating for the new --quickstart flag

Startup Banner

The startup banner should reflect the startup mode; if the user is using --quickstart then echo the pre-baked creds to stdout and not direct them to complete the setup process at http://127.0.0.1:8000/setup

You already have this change but only in the docs, whereas it should be conditional and in the lakeFS output itself

i.e. instead the current startup banner:


     ██╗      █████╗ ██╗  ██╗███████╗███████╗███████╗
     ██║     ██╔══██╗██║ ██╔╝██╔════╝██╔════╝██╔════╝
     ██║     ███████║█████╔╝ █████╗  █████╗  ███████╗
     ██║     ██╔══██║██╔═██╗ ██╔══╝  ██╔══╝  ╚════██║
     ███████╗██║  ██║██║  ██╗███████╗██║     ███████║
     ╚══════╝╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝╚═╝     ╚══════╝

│
│ If you're running lakeFS locally for the first time,
│     complete the setup process at http://127.0.0.1:8000/setup
│

│
│ For more information on how to use lakeFS,
│     check out the docs at https://docs.lakefs.io/quickstart/
│

│
│ For support or any other question,                            >(._.)<
│     join our Slack channel https://docs.lakefs.io/slack         (  )_
│

Should be this for quickstart:


     ██╗      █████╗ ██╗  ██╗███████╗███████╗███████╗
     ██║     ██╔══██╗██║ ██╔╝██╔════╝██╔════╝██╔════╝
     ██║     ███████║█████╔╝ █████╗  █████╗  ███████╗
     ██║     ██╔══██║██╔═██╗ ██╔══╝  ██╔══╝  ╚════██║
     ███████╗██║  ██║██║  ██╗███████╗██║     ███████║
     ╚══════╝╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝╚═╝     ╚══════╝

│
│ You are running lakeFS in quickstart mode. 
|   Login at http://127.0.0.1:8000/
│     
|    Access Key ID    : AKIAIOSFOLQUICKSTART
│    Secret Access Key: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
│

│
│ For more information on how to use lakeFS,
│     check out the docs at https://docs.lakefs.io/quickstart/
│

│
│ For support or any other question,                            >(._.)<
│     join our Slack channel https://docs.lakefs.io/slack         (  )_
│

I realise that the creds are echoed earlier on as part of the bootup but from a DX point of view it's not obvious particularly when there is a user-facing dialog later on in the stdout

CleanShot_2023-07-19_at_10 25 15

Thanks,

Regarding the blocker:
As you stated - this will be resolved in #6204, so we can wait until that issue is resolved before merging this one - in that case there's no impact so there's nothing to discuss.

Nits:
Pre-create the quickstart repo
That's a good idea - but outside of this PR scope. We can open an issue for that if we want this feature

Startup Banner
Since we expected users running quickstart as part of the quickstart tutorial, we can assume they will continue to the next steps where we added the credentials.
Customizing the banner is a good idea, but I think the solution we have is good enough for now

@rmoff
Copy link
Contributor

rmoff commented Jul 19, 2023

I'd like both the nits addressed as part of this PR please. If we're implementing a --quickstart flag (which is a great idea) then it should behave as a proper quickstart, not a partial one nor rely on users to RTFM ;)

@N-o-Z
Copy link
Member Author

N-o-Z commented Jul 19, 2023

@rmoff Added the banner changes - but I have to insist on the sample repo creation. This PR should focus on the issue at hand which is providing a way to understand where lakefs is run from.
The quickstart flag was created out of necessity and not out of requirement. If we think we should add the creation of a sample repo as part of the "quickstart mode" we should discuss and do it as part of a designated context (issue)

@N-o-Z N-o-Z requested a review from rmoff July 19, 2023 11:58
Copy link
Contributor

@rmoff rmoff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for this @N-o-Z.

Assuming we wait for #6204 then we need to make sure that includes changes to the quickstart doc also as the flow will change there.

}
templ := template.New("banner")
var buf bytes.Buffer
t := template.Must(templ.Parse(runBannerTmpl))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can define var outside and use template must api to render it once

}
if isQuickstart {
data.LocalSetup = ""
data.Quickstart = quickStartBanner
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be done inside the template base on the args we provide.
provide the params we require to render the template - it can include the admin key/secret, the mode and the lakefs version.

_, _ = fmt.Fprintf(os.Stderr, "Failed formatting banner: %v\n", err)
os.Exit(1)
}
_, _ = fmt.Fprintf(os.Stderr, "lakeFS %s - Up and running (^C to shutdown)...\n", version.Version)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice - I think it can be also move inside the template

@N-o-Z N-o-Z requested a review from guy-har August 7, 2023 12:57
Copy link
Contributor

@guy-har guy-har left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looked at the CR Fixes
LGTM

@N-o-Z N-o-Z dismissed nopcoder’s stale review August 7, 2023 13:32

On vacation - Guy covered requested changes

@N-o-Z N-o-Z merged commit e31c75c into master Aug 7, 2023
33 checks passed
@N-o-Z N-o-Z deleted the task/add-lakefs-instrumentation-6216 branch August 7, 2023 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BI exclude-changelog PR description should not be included in next release changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add lakeFS instrumentation
4 participants