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 usage reporting pkg #396

Merged
merged 2 commits into from
Jul 7, 2023
Merged

Add usage reporting pkg #396

merged 2 commits into from
Jul 7, 2023

Conversation

alexmasi
Copy link
Contributor

@alexmasi alexmasi commented Jul 7, 2023

No description provided.

@alexmasi alexmasi requested a review from bormanp July 7, 2023 00:43
@coveralls
Copy link

coveralls commented Jul 7, 2023

Pull Request Test Coverage Report for Build 5489015002

  • 49 of 83 (59.04%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.09%) to 65.376%

Changes Missing Coverage Covered Lines Changed/Added Lines %
metrics/metrics.go 49 83 59.04%
Totals Coverage Status
Change from base Build 5481363602: -0.09%
Covered Lines: 3714
Relevant Lines: 5681

💛 - Coveralls

@alexmasi
Copy link
Contributor Author

alexmasi commented Jul 7, 2023

/gcbrun

usage/usage.go Outdated
// limitations under the License.

// Package usage handles anonymous usage reporting.
package usage
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not sure usage is the best name for a package. Normally usage is related to the how to use the command. Maybe metrics or something similar is a better name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

usage/usage.go Outdated
log "k8s.io/klog/v2"
)

const (
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not too fond of these being consts. They will need to be configurable at some point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

usage/usage.go Outdated

// Reporter is a client that reports KNE usage events using PubSub.
type Reporter struct {
pubsubClient *pubsub.Client
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a reason you didn't just embed pubsub.Client? If you do embed you can get rid of Reporter.Close.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

now that topic is also a struct field, Close correctly closes/stops both client and topic

usage/usage.go Outdated
if err != nil {
return err
}
t := r.pubsubClient.Topic(topicID)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there any value in adding a topic field to Reporter and then initialize it in NewReporter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good idea, done

usage/usage.go Outdated
}
t := r.pubsubClient.Topic(topicID)
res := t.Publish(ctx, &pubsub.Message{Data: msg})
id, err := res.Get(ctx)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since res is only used here you can combine these two lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

usage/usage.go Outdated
}

// ReportDeployClusterStart reports that a cluster deployment has started. The UUID of the
// reported event is returned along with an error if the event reporting failed.
Copy link
Collaborator

Choose a reason for hiding this comment

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

The comment does not match the code. The return is UUID xor Error. I think you meant to say if an error is returned the error will contain the UUID (the UUID is not returned directly).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

usage/usage.go Outdated
}

// ReportCreateTopologyStart reports that a topology creation has started. The UUID of the
// reported event is returned along with an error if the event reporting failed.
Copy link
Collaborator

Choose a reason for hiding this comment

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

See above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

usage/usage.go Outdated
return event.GetUuid(), nil
}

// ReportCreateTopologyEnd reports that a topology creation has ended.
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: unlike above you don't include the comment about errors in this description.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

usage/usage.go Outdated

func newEvent() *epb.KNEEvent {
return &epb.KNEEvent{
Uuid: uuid.New(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Perhaps the id should be passed in rather than creating a UUID here. ReportDeployClusterStart can then call newEvent(uuid.New()) and make it clear it is creating a new UUID rather than using an existing one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

usage/usage.go Outdated

func newEvent() *epb.KNEEvent {
return &epb.KNEEvent{
Uuid: uuid.New(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: UUID is an acronym so it really should be UUID or uuid and not Uuid.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, but this is generated proto code

@alexmasi
Copy link
Contributor Author

alexmasi commented Jul 7, 2023

/gcbrun

@alexmasi alexmasi merged commit 8ec979d into main Jul 7, 2023
6 checks passed
@alexmasi alexmasi deleted the pubsub branch July 7, 2023 17:55
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

Successfully merging this pull request may close these issues.

3 participants