-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
pkg/skaffold/config/util.go
Outdated
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO : Add tests
return map[string]struct{}{} | ||
} | ||
taken := map[string]struct{}{} | ||
if timeutil.LessThan(sc.LastTaken, 90*24*time.Hour) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
- define/declare variable code closer to where its used.
- 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 { |
There was a problem hiding this comment.
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{}}),
}
}
There was a problem hiding this comment.
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?
} | ||
|
||
func New(configFile string) *Runner { | ||
func New(configFile string, skaffoldConfig string, mode string) *Runner { |
There was a problem hiding this comment.
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.
pkg/skaffold/survey/survey.go
Outdated
if cfg == nil || cfg.Global == nil || cfg.Global.Survey == nil { | ||
return false | ||
return s.taken(cfg.Global.Survey) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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{}{}
}
There was a problem hiding this comment.
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
Co-authored-by: Brian de Alwis <bsd@acm.org>
There was a problem hiding this 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!
This is the meaty PR to
should merge after #6191, #6192, #6193, #6194
The above all PRs are small refactors.
Design document: #6186
Changes:
Change
surveyPrompt
from bool to string in cmd.Rename
survey.ShouldDisplaySurveyPrompt()
tosurvey.SurveyPromptID
now return a stringAdd
UpdateUserSurveyTaken
to updatecfg.Global.Survey.UserSurveys
with taken true once survey is takenFinally
recentlyPromptedOrTaken
now does the followinga) find candidate user or hats survey id to present iff the survey prompt was not recently sown
Follow up work:
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 aiErrTesting Notes
skaffold build
on helm deployer example - start date in futureskaffold build
on helm deployer example - start date in pastRunning the command