-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gcp-resources): Add Error Reporting (#6326)
#### Summary Relevant API https://cloud.google.com/error-reporting/reference/rest ### Notes - To get the error event we need the error group id hence the relation - There's also `pb.ErrorGroup` (see [here](https://cloud.google.com/error-reporting/reference/rest/v1beta1/projects.groups)) but that data is available via `ErrorGroupStats.Group` so no need for an additional table (also there's no list method to get only error groups) <!--
- Loading branch information
Showing
11 changed files
with
327 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package recipes | ||
|
||
import ( | ||
errorreporting "cloud.google.com/go/errorreporting/apiv1beta1" | ||
pb "cloud.google.com/go/errorreporting/apiv1beta1/errorreportingpb" | ||
) | ||
|
||
func init() { | ||
resources := []*Resource{ | ||
{ | ||
SubService: "error_group_stats", | ||
Struct: &pb.ErrorGroupStats{}, | ||
RequestStructFields: `ProjectName: "projects/" + c.ProjectId,`, | ||
Description: "https://cloud.google.com/error-reporting/reference/rest/v1beta1/projects.groupStats/list#ErrorGroupStats", | ||
SkipMock: true, | ||
Relations: []string{"ErrorEvents()"}, | ||
}, | ||
{ | ||
SubService: "error_events", | ||
Struct: &pb.ErrorEvent{}, | ||
RequestStructFields: `ProjectName: "projects/" + c.ProjectId, GroupId: parent.Item.(*pb.ErrorGroupStats).Group.GroupId,`, | ||
Description: "https://cloud.google.com/error-reporting/reference/rest/v1beta1/ErrorEvent", | ||
ChildTable: true, | ||
SkipMock: true, | ||
}, | ||
} | ||
|
||
for _, resource := range resources { | ||
resource.Service = "clouderrorreporting" | ||
resource.ServiceAPIOverride = "errorreporting" | ||
resource.Template = "newapi_list" | ||
resource.MockTemplate = "newapi_list_grpc_mock" | ||
resource.ProtobufImport = "cloud.google.com/go/errorreporting/apiv1beta1/errorreportingpb" | ||
resource.MockImports = []string{"cloud.google.com/go/errorreporting/apiv1beta1"} | ||
resource.NewFunction = errorreporting.NewErrorStatsClient | ||
resource.RegisterServer = pb.RegisterErrorStatsServiceServer | ||
} | ||
|
||
Resources = append(Resources, resources...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
plugins/source/gcp/docs/tables/gcp_clouderrorreporting_error_events.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Table: gcp_clouderrorreporting_error_events | ||
|
||
https://cloud.google.com/error-reporting/reference/rest/v1beta1/ErrorEvent | ||
|
||
The primary key for this table is **_cq_id**. | ||
|
||
## Relations | ||
|
||
This table depends on [gcp_clouderrorreporting_error_group_stats](gcp_clouderrorreporting_error_group_stats.md). | ||
|
||
## Columns | ||
|
||
| Name | Type | | ||
| ------------- | ------------- | | ||
|_cq_source_name|String| | ||
|_cq_sync_time|Timestamp| | ||
|_cq_id (PK)|UUID| | ||
|_cq_parent_id|UUID| | ||
|project_id|String| | ||
|event_time|Timestamp| | ||
|service_context|JSON| | ||
|message|String| | ||
|context|JSON| |
29 changes: 29 additions & 0 deletions
29
plugins/source/gcp/docs/tables/gcp_clouderrorreporting_error_group_stats.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Table: gcp_clouderrorreporting_error_group_stats | ||
|
||
https://cloud.google.com/error-reporting/reference/rest/v1beta1/projects.groupStats/list#ErrorGroupStats | ||
|
||
The primary key for this table is **_cq_id**. | ||
|
||
## Relations | ||
|
||
The following tables depend on gcp_clouderrorreporting_error_group_stats: | ||
- [gcp_clouderrorreporting_error_events](gcp_clouderrorreporting_error_events.md) | ||
|
||
## Columns | ||
|
||
| Name | Type | | ||
| ------------- | ------------- | | ||
|_cq_source_name|String| | ||
|_cq_sync_time|Timestamp| | ||
|_cq_id (PK)|UUID| | ||
|_cq_parent_id|UUID| | ||
|project_id|String| | ||
|group|JSON| | ||
|count|Int| | ||
|affected_users_count|Int| | ||
|timed_counts|JSON| | ||
|first_seen_time|Timestamp| | ||
|last_seen_time|Timestamp| | ||
|affected_services|JSON| | ||
|num_affected_services|Int| | ||
|representative|JSON| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
76 changes: 76 additions & 0 deletions
76
plugins/source/gcp/resources/services/clouderrorreporting/error_events.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
105 changes: 105 additions & 0 deletions
105
plugins/source/gcp/resources/services/clouderrorreporting/error_group_stats.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
plugins/source/gcp/resources/services/clouderrorreporting/error_group_stats_mock_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package clouderrorreporting | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/cloudquery/plugin-sdk/faker" | ||
"github.com/cloudquery/plugins/source/gcp/client" | ||
"google.golang.org/grpc" | ||
|
||
pb "cloud.google.com/go/errorreporting/apiv1beta1/errorreportingpb" | ||
) | ||
|
||
func createErrorGroupStats(gsrv *grpc.Server) error { | ||
fakeServer := &fakeErrorGroupStatsServer{} | ||
pb.RegisterErrorStatsServiceServer(gsrv, fakeServer) | ||
return nil | ||
} | ||
|
||
type fakeErrorGroupStatsServer struct { | ||
pb.UnimplementedErrorStatsServiceServer | ||
} | ||
|
||
func (*fakeErrorGroupStatsServer) ListGroupStats(context.Context, *pb.ListGroupStatsRequest) (*pb.ListGroupStatsResponse, error) { | ||
resp := pb.ListGroupStatsResponse{} | ||
if err := faker.FakeObject(&resp); err != nil { | ||
return nil, fmt.Errorf("failed to fake data: %w", err) | ||
} | ||
resp.NextPageToken = "" | ||
return &resp, nil | ||
} | ||
|
||
func (*fakeErrorGroupStatsServer) ListEvents(context.Context, *pb.ListEventsRequest) (*pb.ListEventsResponse, error) { | ||
resp := pb.ListEventsResponse{} | ||
if err := faker.FakeObject(&resp); err != nil { | ||
return nil, fmt.Errorf("failed to fake data: %w", err) | ||
} | ||
resp.NextPageToken = "" | ||
return &resp, nil | ||
} | ||
|
||
func TestErrorGroupStats(t *testing.T) { | ||
client.MockTestGrpcHelper(t, ErrorGroupStats(), createErrorGroupStats, client.TestOptions{}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters