Skip to content

Commit

Permalink
feat(gcp-resources): Add Error Reporting (#6326)
Browse files Browse the repository at this point in the history

#### 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
erezrokah authored and pull[bot] committed Oct 27, 2023
1 parent 5945ec6 commit 88d5dc2
Show file tree
Hide file tree
Showing 11 changed files with 327 additions and 0 deletions.
40 changes: 40 additions & 0 deletions plugins/source/gcp/codegen/recipes/clouderrorreporting.go
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...)
}
2 changes: 2 additions & 0 deletions plugins/source/gcp/docs/tables/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
- [gcp_bigquery_tables](gcp_bigquery_tables.md)
- [gcp_billing_billing_accounts](gcp_billing_billing_accounts.md)
- [gcp_billing_services](gcp_billing_services.md)
- [gcp_clouderrorreporting_error_group_stats](gcp_clouderrorreporting_error_group_stats.md)
- [gcp_clouderrorreporting_error_events](gcp_clouderrorreporting_error_events.md)
- [gcp_compute_addresses](gcp_compute_addresses.md)
- [gcp_compute_autoscalers](gcp_compute_autoscalers.md)
- [gcp_compute_backend_services](gcp_compute_backend_services.md)
Expand Down
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|
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|
1 change: 1 addition & 0 deletions plugins/source/gcp/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ require (
cloud.google.com/go/container v1.8.0
cloud.google.com/go/containeranalysis v0.6.0
cloud.google.com/go/domains v0.7.0
cloud.google.com/go/errorreporting v0.3.0
cloud.google.com/go/functions v1.9.0
cloud.google.com/go/iam v0.9.0
cloud.google.com/go/kms v1.6.0
Expand Down
2 changes: 2 additions & 0 deletions plugins/source/gcp/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7
cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk=
cloud.google.com/go/domains v0.7.0 h1:pu3JIgC1rswIqi5romW0JgNO6CTUydLYX8zyjiAvO1c=
cloud.google.com/go/domains v0.7.0/go.mod h1:PtZeqS1xjnXuRPKE/88Iru/LdfoRyEHYA9nFQf4UKpg=
cloud.google.com/go/errorreporting v0.3.0 h1:kj1XEWMu8P0qlLhm3FwcaFsUvXChV/OraZwA70trRR0=
cloud.google.com/go/errorreporting v0.3.0/go.mod h1:xsP2yaAp+OAW4OIm60An2bbLpqIhKXdWR/tawvl7QzU=
cloud.google.com/go/functions v1.9.0 h1:35tgv1fQOtvKqH/uxJMzX3w6usneJ0zXpsFr9KAVhNE=
cloud.google.com/go/functions v1.9.0/go.mod h1:Y+Dz8yGguzO3PpIjhLTbnqV1CWmgQ5UwtlpzoyquQ08=
cloud.google.com/go/iam v0.9.0 h1:bK6Or6mxhuL8lnj1i9j0yMo2wE/IeTO2cWlfUrf/TZs=
Expand Down
2 changes: 2 additions & 0 deletions plugins/source/gcp/resources/plugin/autogen_tables.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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{})
}
2 changes: 2 additions & 0 deletions website/pages/docs/plugins/sources/gcp/tables.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
- [gcp_bigquery_tables](https://github.com/cloudquery/cloudquery/blob/main/plugins/source/gcp/docs/tables/gcp_bigquery_tables.md)
- [gcp_billing_billing_accounts](https://github.com/cloudquery/cloudquery/blob/main/plugins/source/gcp/docs/tables/gcp_billing_billing_accounts.md)
- [gcp_billing_services](https://github.com/cloudquery/cloudquery/blob/main/plugins/source/gcp/docs/tables/gcp_billing_services.md)
- [gcp_clouderrorreporting_error_group_stats](https://github.com/cloudquery/cloudquery/blob/main/plugins/source/gcp/docs/tables/gcp_clouderrorreporting_error_group_stats.md)
- [gcp_clouderrorreporting_error_events](https://github.com/cloudquery/cloudquery/blob/main/plugins/source/gcp/docs/tables/gcp_clouderrorreporting_error_events.md)
- [gcp_compute_addresses](https://github.com/cloudquery/cloudquery/blob/main/plugins/source/gcp/docs/tables/gcp_compute_addresses.md)
- [gcp_compute_autoscalers](https://github.com/cloudquery/cloudquery/blob/main/plugins/source/gcp/docs/tables/gcp_compute_autoscalers.md)
- [gcp_compute_backend_services](https://github.com/cloudquery/cloudquery/blob/main/plugins/source/gcp/docs/tables/gcp_compute_backend_services.md)
Expand Down

0 comments on commit 88d5dc2

Please sign in to comment.