Skip to content

Commit

Permalink
feat: schema field level usage analytics (#174)
Browse files Browse the repository at this point in the history
Co-authored-by: Jens Neuse <jens.neuse@gmx.de>
Co-authored-by: Aenimus <daviditstutt@gmail.com>
Co-authored-by: Nithin Kumar B <nithinkumar5353@gmail.com>
Co-authored-by: fiam <alberto@garciahierro.com>
  • Loading branch information
5 people authored Oct 25, 2023
1 parent ca4f67d commit 4f257a7
Show file tree
Hide file tree
Showing 156 changed files with 9,114 additions and 771 deletions.
2 changes: 2 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ protocol:
- "proto/**/*"
controlplane:
- "controlplane/**/*"
graphqlmetrics:
- "graphqlmetrics/**/*"
2 changes: 0 additions & 2 deletions .github/workflows/cli-ci.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: Cli CI
on:
pull_request:
branches:
- main
paths:
- "cli/**/*"
- "connect/**/*"
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/composition-ci.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: Composition CI
on:
pull_request:
branches:
- main
paths:
- "composition/**/*"
- composition-go/**/*"
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/controlplane-ci.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: Controlplane CI
on:
pull_request:
branches:
- main
paths:
- "controlplane/**/*"
- "connect/**/*"
Expand Down
69 changes: 69 additions & 0 deletions .github/workflows/graphqlmetrics-ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: GraphQLMetrics CI
on:
pull_request:
paths:
- "graphqlmetrics/**/*"
- ".github/workflows/graphqlmetrics-ci.yaml"

concurrency:
group: ${{github.workflow}}-${{github.head_ref}}
cancel-in-progress: true

env:
CI: true
INT_TESTS: true

jobs:
build_test:
runs-on: ubuntu-latest
services:
clickhouse:
# Docker Hub image
image: clickhouse/clickhouse-server:23
ports:
- "8123:8123"
- "9000:9000"
env:
CLICKHOUSE_DB: cosmo
CLICKHOUSE_USER: default
CLICKHOUSE_PASSWORD: changeme
CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT: 1
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
# The go install / version instructions are inside the Makefile, so we need to cache the Makefile.
key: ${{ runner.os }}-go-${{ hashFiles('graphqlmetrics/go.sum') }}-makefile-${{ hashFiles('Makefile') }}
restore-keys: |
${{ runner.os }}-go-
- uses: ./.github/actions/go
with:
cache-dependency-path: graphqlmetrics/go.sum

- name: Install tools
run: make setup-build-tools

- name: Generate code
run: rm -rf graphqlmetrics/gen && buf generate --path proto/wg/cosmo/graphqlmetrics --path proto/wg/cosmo/common --template buf.graphqlmetrics.go.gen.yaml

- name: Check if git is not dirty after generating files
run: git diff --no-ext-diff --exit-code

- name: Install dependencies
working-directory: ./graphqlmetrics
run: go mod download

- name: Test
working-directory: ./graphqlmetrics
run: make test

- name: Build
working-directory: ./graphqlmetrics
run: make build
2 changes: 0 additions & 2 deletions .github/workflows/images-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ on:
- 'scripts/**'

pull_request:
branches:
- main
paths-ignore:
- 'docs/*/**'
- 'helm/**'
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/router-ci.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: Router CI
on:
pull_request:
branches:
- main
paths:
- "router/**/*"
- "router-tests/**/*"
Expand Down Expand Up @@ -30,7 +28,7 @@ jobs:
~/.cache/go-build
~/go/pkg/mod
# The go install / version instructions are inside the Makefile, so we need to cache the Makefile.
key: ${{ runner.os }}-go-${{ hashFiles('Makefile') }}
key: ${{ runner.os }}-go-${{ hashFiles('router/go.sum') }}-makefile-${{ hashFiles('Makefile') }}
restore-keys: |
${{ runner.os }}-go-
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/shared-ci.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: Shared CI
on:
pull_request:
branches:
- main
paths:
- ".github/workflows/shared-ci.yaml"
- "composition/**/*"
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/studio-ci.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: Studio CI
on:
pull_request:
branches:
- main
paths:
- "studio/**/*"
- "connect/**/*"
Expand Down
10 changes: 10 additions & 0 deletions .run/graphqlmetrics.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="graphqlmetrics" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="cosmo" />
<working_directory value="$PROJECT_DIR$/graphqlmetrics" />
<kind value="FILE" />
<directory value="$PROJECT_DIR$" />
<filePath value="$PROJECT_DIR$/graphqlmetrics/cmd/main.go" />
<method v="2" />
</configuration>
</component>
2 changes: 1 addition & 1 deletion .run/router.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
<filePath value="$PROJECT_DIR$/router/cmd/router/main.go" />
<method v="2" />
</configuration>
</component>
</component>
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ all: dev-setup

setup-build-tools:
go install github.com/bufbuild/buf/cmd/buf@latest
go install github.com/bufbuild/connect-go/cmd/protoc-gen-connect-go@latest
go install honnef.co/go/tools/cmd/staticcheck@latest
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install connectrpc.com/connect/cmd/protoc-gen-connect-go@latest

setup-dev-tools: setup-build-tools
go install github.com/amacneil/dbmate/v2@v2.6.0
Expand Down Expand Up @@ -63,7 +64,8 @@ generate:
make generate-go

generate-go:
rm -rf router/gen && buf generate --path proto/wg/cosmo/node --path proto/wg/cosmo/common --template buf.go.gen.yaml
rm -rf router/gen && buf generate --path proto/wg/cosmo/node --path proto/wg/cosmo/common --path proto/wg/cosmo/graphqlmetrics --template buf.router.go.gen.yaml
rm -rf graphqlmetrics/gen && buf generate --path proto/wg/cosmo/graphqlmetrics --path proto/wg/cosmo/common --template buf.graphqlmetrics.go.gen.yaml

start-cp:
pnpm -r run --filter './controlplane' dev
Expand Down Expand Up @@ -109,5 +111,6 @@ docker-build-minikube: docker-build-local
minikube image load ghcr.io/wundergraph/cosmo/controlplane:latest & \
minikube image load ghcr.io/wundergraph/cosmo/otelcollector:latest & \
minikube image load ghcr.io/wundergraph/cosmo/router:latest & \
minikube image load ghcr.io/wundergraph/cosmo/graphqlmetrics:latest & \
minikube image load ghcr.io/wundergraph/cosmo/keycloak:latest
minikube cache reload
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,20 @@
<br/>

WunderGraph Cosmo is the On-Premise Platform for building, maintaining, and collaborating on GraphQL Federation. A drop-in replacement for Apollo GraphOS.
The repository consists of the following components:
The repository consists of the following core components:

Core:

- [CLI](./cli): The cosmo CLI tool `wgc`. Used to manage the cosmo platform e.g. pushing schema, check schemas, creating new projects, managing users, etc. It interacts with the control plane.
- [Control Plane](./controlplane): The control plane is the central component of the cosmo platform. It consists of a platform API and a node API. The platform API is used by the cosmo `CLI` tool and the `Studio` to manage the platform.
- [Router](./router): The router is the component that understands the GraphQL Federation protocol. It is responsible for routing requests to the correct service and for aggregating the responses. It is in connection with the control plane to register itself for advanced fleet management.
- [Studio](./studio): The studio is the web interface for the cosmo platform. It is used to manage the platform and to collaborate on GraphQL Federation. It is in connection with the control plane through the Platform API to manage the platform.

Collectors:

- [OpenTelemetry Collector](./otelcollector): The OpenTelemetry Collector is used to collect and export metrics and traces from the platform. It is configured to collect metrics and traces from the `router` and instrumented `subgraphs`.
- [GraphQLMetrics Collector](./graphqlmetrics): The GraphQLMetrics collector is used to collect and export metrics from the platform that doesn't fit into the OpenTelemetry model. Primarily, it is used to collect operation usage metrics from the `router` to allow advanced breaking changes analysis of client applications.

## Migrate from Apollo GraphOS / Apollo Federation

We've made it super easy for you to migrate from Apollo by using our fully automatic [Migration Assistant](https://cosmo-cp.wundergraph.com/v1/auth/login).
Expand Down Expand Up @@ -57,7 +64,7 @@ export ROUTER_TOKEN=...
make dc-federation-demo
```

3. Navigate to the [Studio explorer](http://localhost:3000/wundergraph/graph/production/explorer) and query the router. Login with the default credentials:
3. Navigate to the [Studio Playground](http://localhost:3000/wundergraph/graph/production/playground) and query the router. Login with the default credentials:

```
Username: foo@wundergraph.com
Expand Down
17 changes: 17 additions & 0 deletions buf.graphqlmetrics.go.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: v1
managed:
enabled: true
go_package_prefix:
default: github.com/wundergraph/cosmo/graphqlmetrics/gen/proto
# Remove `except` field if googleapis is not used
except:
- buf.build/googleapis/googleapis
plugins:
- plugin: connect-go
out: graphqlmetrics/gen/proto
opt:
- paths=source_relative
- plugin: go
out: graphqlmetrics/gen/proto
opt:
- paths=source_relative
File renamed without changes.
1 change: 0 additions & 1 deletion cli/src/commands/subgraph/commands/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export default (opts: BaseCommandOptions) => {
'--subscription-protocol <protocol>',
'The protocol to use when subscribing to the subgraph. The supported protocols are ws, sse, and sse-post.',
);

schemaPush.action(async (name, options) => {
const resp = await opts.client.platform.createFederatedSubgraph(
{
Expand Down
2 changes: 1 addition & 1 deletion connect/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@
"name": "WunderGraph Maintainers",
"email": "info@wundergraph.com"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { createQueryService } from "@connectrpc/connect-query";
import { MethodIdempotency, MethodKind } from "@bufbuild/protobuf";
import { CheckFederatedGraphRequest, CheckFederatedGraphResponse, CheckSubgraphSchemaRequest, CheckSubgraphSchemaResponse, CreateAPIKeyRequest, CreateAPIKeyResponse, CreateFederatedGraphRequest, CreateFederatedGraphResponse, CreateFederatedGraphTokenRequest, CreateFederatedGraphTokenResponse, CreateFederatedSubgraphRequest, CreateFederatedSubgraphResponse, CreateIntegrationRequest, CreateIntegrationResponse, CreateOrganizationWebhookConfigRequest, CreateOrganizationWebhookConfigResponse, DeleteAPIKeyRequest, DeleteAPIKeyResponse, DeleteFederatedGraphRequest, DeleteFederatedGraphResponse, DeleteFederatedSubgraphRequest, DeleteFederatedSubgraphResponse, DeleteIntegrationRequest, DeleteIntegrationResponse, DeleteOrganizationRequest, DeleteOrganizationResponse, DeleteOrganizationWebhookConfigRequest, DeleteOrganizationWebhookConfigResponse, DeleteRouterTokenRequest, DeleteRouterTokenResponse, FixSubgraphSchemaRequest, FixSubgraphSchemaResponse, ForceCheckSuccessRequest, ForceCheckSuccessResponse, GetAnalyticsViewRequest, GetAnalyticsViewResponse, GetAPIKeysRequest, GetAPIKeysResponse, GetCheckDetailsRequest, GetCheckDetailsResponse, GetChecksByFederatedGraphNameRequest, GetChecksByFederatedGraphNameResponse, GetDashboardAnalyticsViewRequest, GetDashboardAnalyticsViewResponse, GetFederatedGraphByNameRequest, GetFederatedGraphByNameResponse, GetFederatedGraphChangelogRequest, GetFederatedGraphChangelogResponse, GetFederatedGraphSDLByNameRequest, GetFederatedGraphSDLByNameResponse, GetFederatedGraphsRequest, GetFederatedGraphsResponse, GetFederatedSubgraphSDLByNameRequest, GetFederatedSubgraphSDLByNameResponse, GetGraphMetricsRequest, GetGraphMetricsResponse, GetMetricsErrorRateRequest, GetMetricsErrorRateResponse, GetOrganizationIntegrationsRequest, GetOrganizationIntegrationsResponse, GetOrganizationMembersRequest, GetOrganizationMembersResponse, GetOrganizationWebhookConfigsRequest, GetOrganizationWebhookConfigsResponse, GetOrganizationWebhookMetaRequest, GetOrganizationWebhookMetaResponse, GetRouterTokensRequest, GetRouterTokensResponse, GetSubgraphByNameRequest, GetSubgraphByNameResponse, GetSubgraphsRequest, GetSubgraphsResponse, GetTraceRequest, GetTraceResponse, InviteUserRequest, InviteUserResponse, IsGitHubAppInstalledRequest, IsGitHubAppInstalledResponse, LeaveOrganizationRequest, LeaveOrganizationResponse, MigrateFromApolloRequest, MigrateFromApolloResponse, PublishFederatedSubgraphRequest, PublishFederatedSubgraphResponse, RemoveInvitationRequest, RemoveInvitationResponse, UpdateFederatedGraphRequest, UpdateFederatedGraphResponse, UpdateIntegrationConfigRequest, UpdateIntegrationConfigResponse, UpdateOrganizationDetailsRequest, UpdateOrganizationDetailsResponse, UpdateOrganizationWebhookConfigRequest, UpdateOrganizationWebhookConfigResponse, UpdateOrgMemberRoleRequest, UpdateOrgMemberRoleResponse, UpdateSubgraphRequest, UpdateSubgraphResponse, WhoAmIRequest, WhoAmIResponse } from "./platform_pb.js";
import { CheckFederatedGraphRequest, CheckFederatedGraphResponse, CheckSubgraphSchemaRequest, CheckSubgraphSchemaResponse, CreateAPIKeyRequest, CreateAPIKeyResponse, CreateFederatedGraphRequest, CreateFederatedGraphResponse, CreateFederatedGraphTokenRequest, CreateFederatedGraphTokenResponse, CreateFederatedSubgraphRequest, CreateFederatedSubgraphResponse, CreateIntegrationRequest, CreateIntegrationResponse, CreateOrganizationWebhookConfigRequest, CreateOrganizationWebhookConfigResponse, DeleteAPIKeyRequest, DeleteAPIKeyResponse, DeleteFederatedGraphRequest, DeleteFederatedGraphResponse, DeleteFederatedSubgraphRequest, DeleteFederatedSubgraphResponse, DeleteIntegrationRequest, DeleteIntegrationResponse, DeleteOrganizationRequest, DeleteOrganizationResponse, DeleteOrganizationWebhookConfigRequest, DeleteOrganizationWebhookConfigResponse, DeleteRouterTokenRequest, DeleteRouterTokenResponse, FixSubgraphSchemaRequest, FixSubgraphSchemaResponse, ForceCheckSuccessRequest, ForceCheckSuccessResponse, GetAnalyticsViewRequest, GetAnalyticsViewResponse, GetAPIKeysRequest, GetAPIKeysResponse, GetCheckDetailsRequest, GetCheckDetailsResponse, GetChecksByFederatedGraphNameRequest, GetChecksByFederatedGraphNameResponse, GetDashboardAnalyticsViewRequest, GetDashboardAnalyticsViewResponse, GetFederatedGraphByNameRequest, GetFederatedGraphByNameResponse, GetFederatedGraphChangelogRequest, GetFederatedGraphChangelogResponse, GetFederatedGraphSDLByNameRequest, GetFederatedGraphSDLByNameResponse, GetFederatedGraphsRequest, GetFederatedGraphsResponse, GetFederatedSubgraphSDLByNameRequest, GetFederatedSubgraphSDLByNameResponse, GetFieldUsageRequest, GetFieldUsageResponse, GetGraphMetricsRequest, GetGraphMetricsResponse, GetMetricsErrorRateRequest, GetMetricsErrorRateResponse, GetOrganizationIntegrationsRequest, GetOrganizationIntegrationsResponse, GetOrganizationMembersRequest, GetOrganizationMembersResponse, GetOrganizationWebhookConfigsRequest, GetOrganizationWebhookConfigsResponse, GetOrganizationWebhookMetaRequest, GetOrganizationWebhookMetaResponse, GetRouterTokensRequest, GetRouterTokensResponse, GetSubgraphByNameRequest, GetSubgraphByNameResponse, GetSubgraphsRequest, GetSubgraphsResponse, GetTraceRequest, GetTraceResponse, InviteUserRequest, InviteUserResponse, IsGitHubAppInstalledRequest, IsGitHubAppInstalledResponse, LeaveOrganizationRequest, LeaveOrganizationResponse, MigrateFromApolloRequest, MigrateFromApolloResponse, PublishFederatedSubgraphRequest, PublishFederatedSubgraphResponse, RemoveInvitationRequest, RemoveInvitationResponse, UpdateFederatedGraphRequest, UpdateFederatedGraphResponse, UpdateIntegrationConfigRequest, UpdateIntegrationConfigResponse, UpdateOrganizationDetailsRequest, UpdateOrganizationDetailsResponse, UpdateOrganizationWebhookConfigRequest, UpdateOrganizationWebhookConfigResponse, UpdateOrgMemberRoleRequest, UpdateOrgMemberRoleResponse, UpdateSubgraphRequest, UpdateSubgraphResponse, WhoAmIRequest, WhoAmIResponse } from "./platform_pb.js";
import { GetConfigRequest, GetConfigResponse } from "../../node/v1/node_pb.js";

export const typeName = "wg.cosmo.platform.v1.PlatformService";
Expand Down Expand Up @@ -972,3 +972,21 @@ export const getMetricsErrorRate = createQueryService({
typeName: "wg.cosmo.platform.v1.PlatformService",
},
}).getMetricsErrorRate;

/**
* @generated from rpc wg.cosmo.platform.v1.PlatformService.GetFieldUsage
*/
export const getFieldUsage = createQueryService({
service: {
methods: {
getFieldUsage: {
name: "GetFieldUsage",
kind: MethodKind.Unary,
I: GetFieldUsageRequest,
O: GetFieldUsageResponse,
idempotency: MethodIdempotency.NoSideEffects,
},
},
typeName: "wg.cosmo.platform.v1.PlatformService",
},
}).getFieldUsage;
Loading

0 comments on commit 4f257a7

Please sign in to comment.