Null response when making GET request to list services associated with a gateway

Hello!! I was wondering if I could get some support with the service List Services for Gateway. As, I have been working on implementing the corresponding test in the consuldotnet repository to make this service available.

This is the approach taken to test the service:

[Fact]
public async Task Catalog_GatewayServices()
{
    using (IConsulClient client = new ConsulClient(c =>
    {
        c.Token = TestHelper.MasterToken;
        c.Address = TestHelper.HttpUri;
    }))
    {
        var terminatingGatewayName = "terminating-gateway";
        var ingressGatewayName = "ingress-gateway";

        // Register terminating gateway service
        var terminatingGatewayEntry = new CatalogRegistration
        {
            Node = "gateway-service",
            Address = "192.168.1.100",
            Service = new AgentService
            {
                ID = "terminating-gateway",
                Service = terminatingGatewayName,
                Port = 8080,
                Kind = ServiceKind.TerminatingGateway,
            }
        };
        await client.Catalog.Register(terminatingGatewayEntry);

        // Register ingress gateway service
        var ingressGatewayEntry = new CatalogRegistration
        {
            Node = "gateway-service",
            Address = "192.168.1.100",
            Service = new AgentService
            {
                ID = "ingress-gateway",
                Service = ingressGatewayName,
                Port = 8081,
                Kind = ServiceKind.IngressGateway,
            }
        };
        await client.Catalog.Register(ingressGatewayEntry);

        // Retrieve gateway services associated with the "gateway-service" node
        var gatewayServices = await client.Catalog.GatewayService("gateway-service", QueryOptions.Default, CancellationToken.None);

        // Assert that the response is not null
        Assert.NotNull(gatewayServices);

        
    }
}

Once I run the local server in Consul/ui I can see that the Node for gateway-service is registered as well as the two associated services → terminating-gateway and ingress-gateway (see image below)

The error I’m getting is a null response when trying to make requests to the API endpoint (GET /v1/catalog/gateway-services/:gateway). I have tried making curl requests directly, but still I only get []

Here is the error log

2024-05-14T12:41:21.615+0200 [WARN]  agent.server.catalog: no terminating-gateway or ingress-gateway associated with this gateway: gateway=gateway-service

I would really appreciate it if someone can take a look into the code test mentioned above to see any potential reasons on why am I getting a null response from the gateway service. Here is the complete code.

Hi @JocelynVelarde, the docs for this parameter are incorrect. This API requires that you specify the logical name of the gateway service. In your environment this would be ingress-gateway or terminating-gateway.

Give that a try and you should see some services returned in the API response.

So @blake this is actually very interesting, the tests are passing now, and I am not getting a null error when asserting on ingress-gateway, terminating-gateway or gateway-service.

Correctas! - Con error:     0, Superado:   210, Omitido:    18, Total:   228, Duración: 4 m 10 s - Consul.Test.dll (net461)

The only thing that I don’t get completely is why when I make curl requests to the endpoint, I just get this:

C:\Users\jvela>curl http://127.0.0.1:8500/v1/catalog/gateway-services/ingress-gateway
[]
C:\Users\jvela>curl http://127.0.0.1:8500/v1/catalog/gateway-services/terminating-gateway
[]
C:\Users\jvela>curl http://127.0.0.1:8500/v1/catalog/gateway-services/gateway-service
[]

@JocelynVelarde,

This API requires that you first associate services to an ingress or terminating gateway using the ingress or terminating gateway configuration entries.

The API should return the associated services once you create the config entry that associates a service to the gateway.

For example,

$ consul config read -kind ingress-gateway -name my-ingress-gateway
{
    "Kind": "ingress-gateway",
    "Name": "my-ingress-gateway",
    "TLS": {
        "Enabled": false
    },
    "Listeners": [
        {
            "Port": 8080,
            "Protocol": "tcp",
            "Services": [
                {
                    "Name": "uuid-api",
                    "Hosts": null
                }
            ]
        }
    ],
    "CreateIndex": 14578102,
    "ModifyIndex": 14578102
}

$ curl --insecure --header "X-Consul-Token:$CONSUL_HTTP_TOKEN" \
  "$CONSUL_HTTP_ADDR/v1/catalog/gateway-services/my-ingress-gateway?pretty"
[
    {
        "Gateway": {
            "Name": "my-ingress-gateway"
        },
        "Service": {
            "Name": "uuid-api"
        },
        "GatewayKind": "ingress-gateway",
        "Port": 8080,
        "Protocol": "tcp",
        "CreateIndex": 14578102,
        "ModifyIndex": 14578102
    }
]

This topic was automatically closed 62 days after the last reply. New replies are no longer allowed.