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 NullSystemTagSet to correctly read K6_SYSTEM_TAGS from env #3660

Closed
wants to merge 3 commits into from

Conversation

joanlopez
Copy link
Contributor

What?

It adds metrics.NullSystemTagSet as a nullable wrapper of metrics.SystemTagSet, following the same pattern we use from guregu/null, and with some custom types like types.NullHosts in order to correctly read K6_SYSTEM_TAGS from env.

Why?

Because now options.SystemTags is typed as *metrics.SystemTagSet, so as the default value for pointers is nil, it cannot ever be re-assigned, causing the call to envconfig.Process(...) to read the value set to K6_SYSTEM_TAGS, but without actually making any change to the options.

Checklist

  • I have performed a self-review of my code.
  • I have added tests for my changes.
  • I have run linter locally (make lint) and all checks pass.
  • I have run tests locally (make tests) and all tests pass.
  • I have commented on my code, particularly in hard-to-understand areas.

Related PR(s)/Issue(s)

Closes #3638

@joanlopez joanlopez added the bug label Mar 21, 2024
@joanlopez joanlopez self-assigned this Mar 21, 2024
@joanlopez joanlopez requested a review from a team as a code owner March 21, 2024 12:46
@joanlopez joanlopez requested review from mstoykov and codebien and removed request for a team March 21, 2024 12:46
@joanlopez joanlopez added this to the v0.51.0 milestone Mar 21, 2024
Comment on lines +171 to +204
// NewNullSystemTagSet returns valid (Valid: true) SystemTagSet
func NewNullSystemTagSet(tags ...SystemTag) NullSystemTagSet {
return NullSystemTagSet{
Set: NewSystemTagSet(tags...),
Valid: true,
}
}

// Add adds a tag to tag set.
func (n *NullSystemTagSet) Add(tag SystemTag) {
if n.Set == nil {
n.Set = new(SystemTagSet)
n.Valid = true
}
n.Set.Add(tag)
}

// Has checks a tag included in tag set.
func (n NullSystemTagSet) Has(tag SystemTag) bool {
if !n.Valid {
return false
}
return n.Set.Has(tag)
}

// Map returns the EnabledTags with current value from SystemTagSet
func (n NullSystemTagSet) Map() EnabledTags {
return n.Set.Map()
}

// SetString returns comma separated list of the string representation of all values in the set
func (n NullSystemTagSet) SetString() string {
return n.Set.SetString()
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I take it that without this additional methods the change is much bigger ?

Copy link
Contributor Author

@joanlopez joanlopez Mar 22, 2024

Choose a reason for hiding this comment

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

I might be missing something, but some of these methods are widely used (for instance, a quick search gives ~30 occurrences of SystemTags.Has(...), so the only alternative I see is replacing each of them by: SystemTags.Set.Has(...). The same for the rest, although Has is probably the one used the most.

Do you have any other suggestion? 🤔

Copy link
Contributor Author

@joanlopez joanlopez Apr 3, 2024

Choose a reason for hiding this comment

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

Any news? Any suggestion? @mstoykov 🙏🏻

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry, I started writing and then apparently never published this.

Given how big this change is and that it now mixes Null types with the actual implementation of how it is used - which we never do, I am kind of for not going forward with this.

I kind of prefer if we just use Null type and then fix it everywhere, but it might be a bit much. Arguably we will have to do this huge breaking change when we move to https://github.com/grafana/croconf or for any other fix for #883 . But not certain if we should do this before.

So at this point I kind of thing that your proposal to just patch envconfig might be better 🤔

Can you open a PR so we can at least look at it in parallel.

cc @codebien I guess this also is your concern

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here's the PR: mstoykov/envconfig#1
cc/ @codebien

Comment on lines +157 to +161
// NullSystemTagSet is a wrapper around SystemTagSet like guregu/null
type NullSystemTagSet struct {
Set *SystemTagSet
Valid bool
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

In principle:
Do we need the nullable type at this level? It resolves a config/option's issue so I would prefer if this new type remains a solution for those spaces and let the rest of the code only use SystemTagSet.
In this way, the rest of the code is independent of what we need on the config side. If in the future we change the way we configure k6, and use other types for the Null problem then all the code will be impacted. Instead, if it only relies on pure SystemTagSet then we don't have to change it.

In concrete, I may miss something marking my suggestion as not feasible. @joanlopez What do you think?

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 78.94737% with 8 lines in your changes are missing coverage. Please review.

Project coverage is 73.61%. Comparing base (2af1a3f) to head (cd793e3).

❗ Current head cd793e3 differs from pull request most recent head b3fb341. Consider uploading reports for the commit b3fb341 to get more accurate results

Files Patch % Lines
metrics/system_tag.go 76.47% 6 Missing and 2 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3660   +/-   ##
=======================================
  Coverage   73.60%   73.61%           
=======================================
  Files         277      277           
  Lines       20251    20285   +34     
=======================================
+ Hits        14906    14932   +26     
- Misses       4399     4404    +5     
- Partials      946      949    +3     
Flag Coverage Δ
macos 73.51% <78.94%> (?)
ubuntu 73.55% <78.94%> (+0.02%) ⬆️
windows 73.45% <78.94%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@joanlopez
Copy link
Contributor Author

Closing in favor of #3672

@joanlopez joanlopez closed this Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

K6_SYSTEM_TAGS environment variable not being read
4 participants