Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Self-hosted usage reporting not working #310

Open
jlambynz opened this issue Dec 10, 2024 · 6 comments · May be fixed by #342
Open

Self-hosted usage reporting not working #310

jlambynz opened this issue Dec 10, 2024 · 6 comments · May be fixed by #342

Comments

@jlambynz
Copy link

jlambynz commented Dec 10, 2024

When running the gateway using supergraph, adding configuration to support usage reporting to a self hosted instance, Hive is still trying to use the cloud endpoint.

Given a config something like:

export const gatewayConfig = defineConfig({
  supergraph: {
    type: "hive",
    endpoint: "https://self-hosted.com/artifacts/..."
    key: 123
  },
  reporting: {
    type: "hive",
    token: "123",
    selfHosting: {
      applicationUrl: "https://self-hosted.com",
      graphqlEndpoint: "https://self-hosted.com/graphql",
      usageEndpoint: "https://self-hosted.com/usage",
    },
  },

The gateway doesn't use the reporting.selfHosting options and defaults to targeting https://app.graphql-hive.com/graphql:
image

From what I can tell, reporting configuration is never passed and instead a basic reporting object is constructed only consisting of type and token: https://github.com/graphql-hive/gateway/blob/main/packages/gateway/src/commands/supergraph.ts#L157-L164

I notice in the documentation it mentions not all functionality is available in the self-hosted version, including usage-estimation, but it's not clear to me if that includes usage reporting in general. Should this configuration work for the self hosting?

ardatan added a commit that referenced this issue Dec 16, 2024
@ardatan
Copy link
Member

ardatan commented Dec 16, 2024

https://github.com/graphql-hive/gateway/blob/main/packages/gateway/src/commands/supergraph.ts#L157-L164

That line works when you pass the token through CLI arguments, but it seems you pass it using the configuration file

I notice in the documentation it mentions not all functionality is available in the self-hosted version, including usage-estimation, but it's not clear to me if that includes usage reporting in general. Should this configuration work for the self hosting?

Usage reporting is included.

Could you help us reproducing the issue?
#342
I created this PR to reproduce it but it works as expected.

ardatan added a commit that referenced this issue Dec 16, 2024
@jlambynz
Copy link
Author

jlambynz commented Dec 16, 2024

@ardatan Not immediately confident I can easily create a reproduction but I'll review what you put together and see if that gleans any more information

In the interim, just to clarify as it seems I may have caused confusion, I'm not having any issues passing the token, it's about specifying a usage endpoint that isn't the default https://app.graphql-hive.com/graphql. In the config I specify selfHosting.usageEndpoint to point to our hosted instance, but the gateway continues to try send usage to https://app.graphql-hive.com/graphql.

The link to the code I was referencing was me wondering if the selfHosting section of the config should be provided there? I did a test run locally where I changed that part of the code to

if (hiveRegistryToken) {
        ctx.log.info(`Configuring Hive registry reporting`);
        registryConfig = {
          reporting: {
            type: 'hive',
            token: hiveRegistryToken,
            ...loadedConfig.reporting // <----- added this line
          },
        };
      }

With this change, it started working and sending usage reports to our hosted instance

@ardatan
Copy link
Member

ardatan commented Dec 16, 2024

That part of code handles the token given in the CLI arguments not from the config as in your example.
So you pass the token from CLI arguments, right?

@jlambynz
Copy link
Author

jlambynz commented Dec 16, 2024

@ardatan I wasn't, no. I did a quick test including the token as a CLI argument, but that doesn't seem to influence the endpoint it tries to send usage to

If it's useful, my setup is very bare bones:

Dockerfile

FROM ghcr.io/graphql-hive/gateway:1.6.6
COPY ./gateway.config.ts .
CMD ["supergraph",  "--host", "0.0.0.0"]

gateway.config.ts

import {  defineConfig } from "@graphql-hive/gateway";

export const gatewayConfig = defineConfig({
  supergraph: {
    type: "hive",
    endpoint: <CDN_URL>,
    key: <CDN_KEY>,
  },
  reporting: {
    type: "hive",
    token: "<REGITRY_TOKEN>",
    selfHosting: {
      applicationUrl: "<SELF_HOSTED_URL>",
      graphqlEndpoint: "<SELF_HOSTED_URL>/graphql",
      usageEndpoint: "<SELF_HOSTED_URL>/usage",
    },
    usage: {
      clientInfo: {
        name: "gateway",
        version: "1.0.0",
      }
    }
  },
});

Values enclosed in <> omitted

Outcome:
image

Expected:
Request to be sent to reporting.selfHosting.graphqlEndpoint, not https://app.graphql-hive.com/graphql

ardatan added a commit that referenced this issue Dec 17, 2024
@ardatan
Copy link
Member

ardatan commented Dec 17, 2024

if (hiveRegistryToken) {
        ctx.log.info(`Configuring Hive registry reporting`);
        registryConfig = {
          reporting: {
            type: 'hive',
            token: hiveRegistryToken,
            ...loadedConfig.reporting // <----- added this line
          },
        };
      }

I reproduced your issue when I passed the token as a CLI argument which that code part only runs in this case, otherwise that code never runs. I couldn't reproduce the issue when all parameters are given in the configuration file.

Maybe I am missing something but could you try with the alphas here?
#342

ardatan added a commit that referenced this issue Dec 17, 2024
@jlambynz
Copy link
Author

jlambynz commented Dec 17, 2024

@ardatan Shit, sorry, I missed a crucial piece of detail which is I'm passing HIVE_REGISTRY_TOKEN as an environment variable rather than CLI argument. Removing this makes it work since, as you mention, it skips that piece of code.

I also tested your alpha build 1.7.2-alpha-d69118ccfaf1fa7fc354aa068226490bb978018e including HIVE_REGISTRY_TOKEN and it works

ardatan added a commit that referenced this issue Dec 18, 2024
ardatan added a commit that referenced this issue Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants