nats-io / nats.c

A C client for NATS
Apache License 2.0
382 stars 132 forks source link

micro commands give parser errors on names #738

Closed geiseri closed 4 months ago

geiseri commented 5 months ago

Observed behavior

I am not 100% sure if this is a nats-c bug or nats-cli bug. I have a microservice published via the nats-c api. When I run nats micro list I see the following error.

$ nats micro list
nats: error: /endpoints/0/name: does not match pattern '^[a-zA-Z0-9_-]+$',/endpoints/1/name: does not match pattern '^[a-zA-Z0-9_-]+$',/endpoints/2/name: does not match pattern '^[a-zA-Z0-9_-]+$'

If I run nats req '$SRV.INFO.candleserver' I see the following output:

~/nats$ nats req '$SRV.INFO.candleserver' ''
13:37:38 Sending request on "$SRV.INFO.candleserver"
13:37:38 Received with rtt 8.610413ms
{"description":"Candlestick Server","endpoints":[{"name":"candles.put_candles","subject":"candles.put_candles"},{"name":"candles.get_candles","subject":"candles.get_candles"},{"name":"candles.valid_timerange","subject":"candles.valid_timerange"}],"id":"UZEQXJ2PMIOH1W9WG4M9QV","name":"candleserver","type":"io.nats.micro.v1.info_response","version":"1.0.0"}

If I look at the demo service reported by nats cli I see the following:

~/nats$ nats req '$SRV.INFO.foobar' ''
13:39:30 Sending request on "$SRV.INFO.foobar"
13:39:30 Received with rtt 1.162433ms
{"name":"foobar","id":"ZjT4ZocsAU0ubxDd3HER4X","version":"1.0.0","metadata":{"_nats.client.created.library":"natscli","_nats.client.created.version":"0.1.4"},"type":"io.nats.micro.v1.info_response","description":"NATS CLI Demo Service (foobar)","endpoints":[{"name":"echo","subject":"foobar.echo","queue_group":"q","metadata":null}]}

I noticed something different in the name returned. In the case of nats-c the name is a combination of the endpoint is servicename.endpointname but the demo server uses just name. It would make sense since the . is not covered by the regexp.

Expected behavior

The service is displayed in the UI along side the service displayed with nats micro serve foobar

Server and client version

Server: v2.10.7 nats-c: 3.7.0

Host environment

No response

Steps to reproduce

Start the demo service

NATS CLI Micro Service foobar handler 993027 waiting for requests on nats://127.0.0.1:4222

Listening Subjects:

  foobar.echo: Echo Service

Requests Log:

Run nats micro list

~/nats$ nats micro list
╭────────────────────────────────────────────────────────────────────────────╮
│                             All Micro Services                             │
├────────┬─────────┬────────────────────────┬────────────────────────────────┤
│ Name   │ Version │ ID                     │ Description                    │
├────────┼─────────┼────────────────────────┼────────────────────────────────┤
│ foobar │ 1.0.0   │ ZjT4ZocsAU0ubxDd3HER4X │ NATS CLI Demo Service (foobar) │
╰────────┴─────────┴────────────────────────┴────────────────────────────────╯

Run nats-c created service

~/nats$ nats micro list
nats: error: /endpoints/0/name: does not match pattern '^[a-zA-Z0-9_-]+$',/endpoints/1/name: does not match pattern '^[a-zA-Z0-9_-]+$',/endpoints/2/name: does not match pattern '^[a-zA-Z0-9_-]+$'
ripienaar commented 5 months ago

Maybe one for the C client instead.

We can see from https://github.com/nats-io/nats-architecture-and-design/blob/main/adr/ADR-32.md#design that those are not valid names.