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 logic to show user survey in DisplaySurveyPrompt flow. #6196

Merged
merged 19 commits into from
Jul 13, 2021

Conversation

tejal29
Copy link
Member

@tejal29 tejal29 commented Jul 13, 2021

This is the meaty PR to

should merge after #6191, #6192, #6193, #6194
The above all PRs are small refactors.

Design document: #6186

Changes:

  1. Change surveyPrompt from bool to string in cmd.

  2. Rename survey.ShouldDisplaySurveyPrompt() to survey.SurveyPromptID now return a string

     surveyPrompt <- s.SurveyPromptID()
    
  3. Add UpdateUserSurveyTaken to update cfg.Global.Survey.UserSurveys with taken true once survey is taken

    &UserSurvey{ID: id, Taken: util.BoolPtr(true)}
    
  4. Finally recentlyPromptedOrTaken now does the following
    a) find candidate user or hats survey id to present iff the survey prompt was not recently sown

Follow up work:

  • Support skaffold config set --survey --global --id helm taken true so in case skaffold fails to update the config, users can manually run the command mentioned in aiErr
updateUserTaken = "skaffold config set --survey --global --id %s taken true"
func UpdateUserSurveyTaken(configFile string, id string) error {
	ai := fmt.Sprintf(updateUserTaken, id)
	aiErr := fmt.Errorf("could not automatically update the survey prompted timestamp - please run `%s`", ai)
}

Testing Notes

  1. Hats prompted, hats not taken on getting started example which has a helm deployer
global:
  update-check: true
  collect-metrics: true
  update:
    last-prompted: "2021-07-12T23:22:21-07:00"
kubeContexts: []
../../out/skaffold build
....
Help improve Skaffold with our 2-minute anonymous survey: run 'skaffold survey'
  1. Hats not taken, running skaffold build on helm deployer example - start date in future
global:
  update-check: true
  collect-metrics: true
  update:
    last-prompted: "2021-07-13T00:32:16-07:00"
kubeContexts: []

skaffold build
Help improve Skaffold with our 2-minute anonymous survey: run 'skaffold survey'
$

  1. Hats not taken, running skaffold build on helm deployer example - start date in past
+++ b/pkg/skaffold/survey/config.go
@@ -48,13 +48,16 @@ var (
                hats,
                {
                        id:       helmID,
-                       startsAt: time.Date(2021, time.July, 19, 0, 0, 0, 0, time.UTC),
+                       startsAt: time.Date(2021, time.July, 11, 0, 0, 0, 0, time.UTC),

$ cat ~/.skaffold/config
global:
  update-check: true
  collect-metrics: true
  update:
    last-prompted: "2021-07-13T00:32:16-07:00"
kubeContexts: []

➜  helm-deployment git:(addSurveyHooks) ✗ ../../out/skaffold build
Skaffold is working on revamping helm deployer support. Help us understand your helm deployer use case with our 2-minute anonymous survey: run 'skaffold survey --id helm'

Running the command

➜  helm-deployment git:(addSurveyHooks) ✗ ../../out/skaffold survey --id helm
Thank you for offering your feedback on Skaffold! Understanding your experiences and opinions helps us make Skaffold better for you and other users.

Skaffold will now attempt to open the survey in your default web browser. You may also manually open it using this URL:

https://forms.gle/cLQg8sGD71JnPSZf6

Tip: To permanently disable the survey prompt, run:
   skaffold config set --survey --global disable-prompt true
➜  helm-deployment git:(addSurveyHooks) ✗ 

@codecov
Copy link

codecov bot commented Jul 13, 2021

Codecov Report

Merging #6196 (a5fdbf7) into master (8d0a32f) will increase coverage by 0.13%.
The diff coverage is 67.61%.

❗ Current head a5fdbf7 differs from pull request most recent head 623fc2b. Consider uploading reports for the commit 623fc2b to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master    #6196      +/-   ##
==========================================
+ Coverage   71.09%   71.22%   +0.13%     
==========================================
  Files         485      481       -4     
  Lines       21609    21672      +63     
==========================================
+ Hits        15362    15435      +73     
+ Misses       5264     5253      -11     
- Partials      983      984       +1     
Impacted Files Coverage Δ
cmd/skaffold/app/cmd/survey.go 70.00% <0.00%> (ø)
cmd/skaffold/app/cmd/cmd.go 73.51% <28.57%> (-0.40%) ⬇️
pkg/skaffold/survey/config.go 68.62% <52.94%> (+2.91%) ⬆️
pkg/skaffold/config/util.go 67.63% <75.00%> (+0.81%) ⬆️
pkg/skaffold/survey/survey.go 69.62% <75.00%> (+6.76%) ⬆️
pkg/skaffold/log/provider.go 0.00% <0.00%> (-61.91%) ⬇️
pkg/skaffold/log/log.go 83.33% <0.00%> (-16.67%) ⬇️
...affold/kubernetes/portforward/forwarder_manager.go 48.57% <0.00%> (-3.16%) ⬇️
pkg/skaffold/runner/v1/new.go 63.24% <0.00%> (-2.08%) ⬇️
pkg/skaffold/util/env_template.go 94.36% <0.00%> (-2.07%) ⬇️
... and 19 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8d0a32f...623fc2b. Read the comment docs.

@tejal29 tejal29 added this to the v1.28.0 milestone Jul 13, 2021
Comment on lines 376 to 378
func UpdateUserSurveyTaken(configFile string, id string) error {
ai := fmt.Sprintf(updateUserTaken, id)
aiErr := fmt.Errorf("could not automatically update the survey prompted timestamp - please run `%s`", ai)
Copy link
Member Author

Choose a reason for hiding this comment

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

TODO : Add tests

@tejal29 tejal29 changed the base branch from master to base_pr July 13, 2021 09:19
return map[string]struct{}{}
}
taken := map[string]struct{}{}
if timeutil.LessThan(sc.LastTaken, 90*24*time.Hour) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: extract these times as constants up top with description about what they control

Copy link
Member Author

Choose a reason for hiding this comment

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

I actually had these as constants. I remember @tstromberg went in made them in to inline values here to follow the readability principle.

  1. define/declare variable code closer to where its used.
  2. dont create a constant if its not used multiple time.

I also do prefer constants, but he convinced me its easy to infer this value due to time.Hour

expiresAt: time.Date(2021, time.August,
14, 00, 00, 00, 0, time.UTC),
promptText: "Skaffold is working on revamping helm deployer support. Help us understand your helm deployer use case with our 2-minute anonymous survey",
isRelevantFn: func(cfgs []util.VersionedConfig, _ sConfig.RunMode) bool {
Copy link
Collaborator

Choose a reason for hiding this comment

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

wdyt about replacing isRelevantFn with an explicit type survey.target where:

type target interface {
    valid([]util.VersionedConfig, sConfig.RunMode) bool
}

type targets []target

func (t targets) valid(c []util.VersionedConfig, m sConfig.RunMode) bool{
    for _, survey := range t {
        if !survey.valid(c, m) {
            return false
        }
    }
    return true
}

so we can arbitrarily compose them for more targeted surveys

surveys = []config{
    {
        id: helmUsers,
        targets: usesHelm{},
    },
    {
        id: multiConfigHelmUsers,
        targets: targets([]target{usesHelm{}, isMultiConfig{}}),
    }
}

Copy link
Member Author

Choose a reason for hiding this comment

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

sounds like a good idea. Shd we do this when we do have to re-use?

pkg/skaffold/survey/config.go Outdated Show resolved Hide resolved
pkg/skaffold/survey/config.go Outdated Show resolved Hide resolved
pkg/skaffold/survey/config.go Outdated Show resolved Hide resolved
pkg/skaffold/survey/config.go Show resolved Hide resolved
pkg/skaffold/survey/survey.go Outdated Show resolved Hide resolved
}

func New(configFile string) *Runner {
func New(configFile string, skaffoldConfig string, mode string) *Runner {
Copy link
Member

Choose a reason for hiding this comment

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

It would be nice if we could avoid reloading the configs for the survey and in the runner. Perhaps we could have provider / loader that is passed here and into the runner so that we only load it once. This can wait for later.

if cfg == nil || cfg.Global == nil || cfg.Global.Survey == nil {
return false
return s.taken(cfg.Global.Survey)
Copy link
Member

Choose a reason for hiding this comment

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

This will result in a nil panic given the if condition above.

Copy link
Member Author

Choose a reason for hiding this comment

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

s.taken first line has a check to make sure cfg.Global.Survey is nil and a test is added.

Copy link
Member Author

Choose a reason for hiding this comment

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

update: not s.taken but function calls below. There is a nil input test

func (s *Runner) taken(gc *sConfig.SurveyConfig) bool {
	// fetch candidate surveys not taken by the user.
	s.surveyID = s.selectSurvey(gc)
	return s.surveyID == ""
}

func (s *Runner) selectSurvey(gc *sConfig.SurveyConfig) string {
	taken := surveysTaken(gc)
...
}

func surveysTaken(sc *sConfig.SurveyConfig) map[string]struct{} {
	if sc == nil {
		return map[string]struct{}{}
}

Copy link
Member Author

@tejal29 tejal29 Jul 13, 2021

Choose a reason for hiding this comment

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

hmm. Integration tests failed due to npe.
I am still scratching my brain why this happened.

Changed in 00b6cf4

pkg/skaffold/survey/survey.go Show resolved Hide resolved
pkg/skaffold/survey/survey.go Outdated Show resolved Hide resolved
pkg/skaffold/survey/survey.go Outdated Show resolved Hide resolved
tejal29 and others added 2 commits July 13, 2021 09:35
Co-authored-by: Brian de Alwis <bsd@acm.org>
@tejal29 tejal29 changed the base branch from base_pr to master July 13, 2021 18:21
Copy link
Member

@briandealwis briandealwis left a comment

Choose a reason for hiding this comment

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

Some minor nits, but it seems to work for me!

pkg/skaffold/survey/config.go Show resolved Hide resolved
pkg/skaffold/survey/config.go Outdated Show resolved Hide resolved
pkg/skaffold/survey/survey.go Outdated Show resolved Hide resolved
pkg/skaffold/survey/config.go Outdated Show resolved Hide resolved
@tejal29 tejal29 enabled auto-merge (squash) July 13, 2021 21:14
@tejal29 tejal29 merged commit b3e0201 into GoogleContainerTools:master Jul 13, 2021
@tejal29 tejal29 deleted the addSurveyHooks branch July 21, 2021 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants