Search code examples
gografeas

Grafeas golang filter string and DeleteOccurrence() API errors


I'm running into 2 separate issues using the Grafeas golang 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 the Filter field using this GCP reference grafeas golang code as a guide.

filterStr := fmt.Sprintf(`kind=%q`, grafeas_common_proto.NoteKind_BUILD.String())
listReq := &grafeas_proto.ListOccurrencesRequest{
    Parent:   BuildProject,
    Filter:   filterStr,
    PageSize: 100,
}

listOccResp, err := r.grafeasCommon.ListOccurrences(ctx, listReq)
for {
        if err != nil {
            log.Error("failed to iterate over occurrences", zap.NamedError("error", err))
            return nil, err
        }
        ...

But it looks like my filterStr is invalid, here's the 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"}

It looks like the \ escape character is causing trouble but I've tried it without it and get another flavor of same type of error.

Issue #2

When I call DeleteOccurrence(), I can see that the occurrence is in fact deleted from Grafeas by checking:

curl http://localhost:8080/v1beta1/projects/broker_builds/occurrences

But DeleteOccurrence() always sets the err

Code:

    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))
        }
    }

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"}

I don't understand what the error is referring to.

This question was cross-posted on Grafeas message board.

Appreciate any help. Thanks.


Solution

  • 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.

    Thanks to @Ovidiu Ghinet, that was a good tip