Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/app/api/grpcapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ func (a *API) RegisterEvent(ctx context.Context, req *apiservice.RegisterEventRe
Id: uuid.New().String(),
Name: req.Name,
Data: req.Data,
Labels: req.Labels,
ProjectId: key.ProjectId,
})
if errors.Is(err, datastore.ErrAlreadyExists) {
Expand Down
1 change: 1 addition & 0 deletions pkg/app/api/service/apiservice/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ message GetCommandResponse {
message RegisterEventRequest {
string name = 1 [(validate.rules).string.min_len = 1];
string data = 2 [(validate.rules).string.min_len = 1];
map<string,string> labels = 3 [(validate.rules).map.keys.string.min_len = 1, (validate.rules).map.values.string.min_len = 1];
Copy link
Member

Choose a reason for hiding this comment

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

This validates just there is no empty value for a key? I just want to know this fails if no labels set. Sorry I'm lazy I didn't read the documentation for the validate.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. No labels case is fine. This checks against the empty string of the key, value.

Copy link
Member Author

Choose a reason for hiding this comment

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

In case you want to know the generated code

/ Validate checks the field values on RegisterEventRequest with the rules
// defined in the proto definition for this message. If any rules are
// violated, an error is returned.
func (m *RegisterEventRequest) Validate() error {
        if m == nil {
                return nil
        }

        if utf8.RuneCountInString(m.GetName()) < 1 {
                return RegisterEventRequestValidationError{
                        field:  "Name",
                        reason: "value length must be at least 1 runes",
                }
        }

        if utf8.RuneCountInString(m.GetData()) < 1 {
                return RegisterEventRequestValidationError{
                        field:  "Data",
                        reason: "value length must be at least 1 runes",
                }
        }

        for key, val := range m.GetLabels() {
                _ = val

                if utf8.RuneCountInString(key) < 1 {
                        return RegisterEventRequestValidationError{
                                field:  fmt.Sprintf("Labels[%v]", key),
                                reason: "value length must be at least 1 runes",
                        }
                }

                if utf8.RuneCountInString(val) < 1 {
                        return RegisterEventRequestValidationError{
                                field:  fmt.Sprintf("Labels[%v]", key),
                                reason: "value length must be at least 1 runes",
                        }
                }

        }

        return nil
}

Copy link
Member

Choose a reason for hiding this comment

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

That more makes sense! This generated code tell me how it works completely.

}

message RegisterEventResponse {
Expand Down
12 changes: 7 additions & 5 deletions pkg/app/pipectl/cmd/event/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ import (
type register struct {
root *command

name string
data string
name string
data string
labels map[string]string
}

func newRegisterCommand(root *command) *cobra.Command {
Expand All @@ -43,7 +44,7 @@ func newRegisterCommand(root *command) *cobra.Command {

cmd.Flags().StringVar(&r.name, "name", r.name, "The name of event.")
cmd.Flags().StringVar(&r.data, "data", r.data, "The string value of event data.")
// TODO: Allow specifying event labels.
cmd.Flags().StringToStringVar(&r.labels, "labels", r.labels, "The list of labels for event. Format: key=value,key2=value2")

cmd.MarkFlagRequired("name")
cmd.MarkFlagRequired("data")
Expand All @@ -59,8 +60,9 @@ func (r *register) run(ctx context.Context, t cli.Telemetry) error {
defer cli.Close()

req := &apiservice.RegisterEventRequest{
Name: r.name,
Data: r.data,
Name: r.name,
Data: r.data,
Labels: r.labels,
}

if _, err := cli.RegisterEvent(ctx, req); err != nil {
Expand Down