Grafeas golang filter string and DeleteOccurrence() issue

82 views
Skip to first unread message

Yuzhou Liu

unread,
Mar 24, 2021, 4:44:43 PM3/24/21
to Grafeas Users
I'm running into 2 separate issues using the Grafeas golang proto/v1beta1 API.

What I'm trying to do
  • Call ListOccurrencesRequest() with a Filter to get a list of occurrences for deletion
  • Call DeleteOccurrence() on each occurrence from above list to delete it
Issue #1
I'm trying to set
filterStr := fmt.Sprintf(`kind=%q`, grafeas_common_proto.NoteKind_BUILD.String())
ListOccurrencesRequest{
    Parent: "projects/broker_builds", 
    Filter:  filterStr,
    PageSize: 100,
}

I copied the golang GCP Reference for filter string

But I get this error:
    filterStr       {"filterStr": "kind=\"BUILD\""}
    failed to iterate over occurrences      {"error": "rpc error: code = Internal desc = error while parsing filter expression: 4 errors occurred:\n\t* error parsing filter\n\t* Syntax error: token recognition error at: '=\"' (1:4)\n\t* Syntax error: token recognition error at: '\"' (1:11)\n\t* Syntax error: extraneous input 'BUILD' expecting <EOF> (1:6)\n\n"}


Issue #2
When trying to delete an occurrence, I can see that the occurrence is deleted using

But the err in the following code is always set by Grafeas:
    for _, o := range occToDelete {
        log.Info("occToDelete", zap.String("occurrence", o))
        _, err := r.grafeasCommon.DeleteOccurrence(ctx, &grafeas_proto.DeleteOccurrenceRequest{
            Name: o,
        })
        if err != nil {
            log.Error("failed to delete occurrence", zap.String("occurrence", o), zap.NamedError("error", err))
        }
}

And here's the error:
    failed to delete occurrence     {"occurrence": "projects/broker_builds/occurrences/f61a4c57-a3d3-44a9-86ee-5d58cb6c6052", "error": "rpc error: code = Internal desc = grpc: error while marshaling: proto: Marshal called with nil"}


Would anyone be able to point me in the right direction?

Thanks.

Yuzhou Liu

unread,
Mar 24, 2021, 5:15:02 PM3/24/21
to Grafeas Users

Yuzhou Liu

unread,
Mar 25, 2021, 4:38:27 PM3/25/21
to Grafeas Users

Solution for Issue #1

I'm using grafeas-elasticsearch as the storage backend. It uses a different filter string format than the examples I had looked at in my original post.

For example, instead of '=' -> '==', 'AND' -> '&&', etc.

More examples can be seen here: https://github.com/rode/grafeas-elasticsearch/blob/main/test/v1beta1/occurrence_test.go#L226


Solution for Issue #2

Known issue with grafeas

https://github.com/grafeas/grafeas/pull/456

https://github.com/grafeas/grafeas/pull/468

Unfortunately the latest tagged release of grafeas v0.1.6 does not include these fixes yet. So will need to pick them up on the next release.

ovi...@ghinet.ch

unread,
Mar 25, 2021, 8:20:24 PM3/25/21
to Grafeas Users

yes, I hope we get a new release soon also.

otherwise I have been cherrypick for the last 6 months or so...

or 
go get github.com/grafeas/grafeas@5b072a9930ea or some other commit known to work for me.


Regards,
Ovidiu
Reply all
Reply to author
Forward
0 new messages