Skip to content

traffic watch base functionality - #213

Merged
scott-cotton merged 20 commits into
mainfrom
traffic-watch
Oct 10, 2025
Merged

scott-cotton merged 20 commits into
mainfrom
traffic-watch

Conversation

@scott-cotton

Copy link
Copy Markdown
Member

depends on https://github.com/signadot/libconnect/pull/131 and https://github.com/signadot/signadot/pull/6249

TODO probably on stacked PR(s):

  • instrumenting and undoing sandbox middleware: changes
  • missing: -o {yaml/json} support,
  • improve error messages
  • default output dir?
  • timeout options?
  • flag naming and help message improvements

But, hey, it works! tested locally in various scenarios:

  • --meta-only and not
  • restarting tw-server
  • GC'ing the connection
  • setting timeout with context
  • control-C

@daniel-de-vera

Copy link
Copy Markdown
Contributor

@scott-cotton, something that was making some noise on my mind for a while (and that I finally see it clear now) is the fact that the --meta-only mode doesn’t really tell you much about the request. So, from a user’s perspective, it feels kind of incomplete: I know we’re intercepting a request for a given routing key and host, but I have no visibility into what the request actually is (method, path, etc.).

Because of that, I don’t see much value in running with --meta-only mode as it stands. In my opinion, when running in this “lightweight” mode, user expectations would be something closer to an access log: no bodies streamed, but still enough context to view the core request/response details.

I guess it might be worth digging deeper into this aspect of the devex, since it could imply some changes in the operator.

@scott-cotton

Copy link
Copy Markdown
Member Author

@scott-cotton, something that was making some noise on my mind for a while (and that I finally see it clear now) is the fact that the --meta-only mode doesn’t really tell you much about the request. So, from a user’s perspective, it feels kind of incomplete: I know we’re intercepting a request for a given routing key and host, but I have no visibility into what the request actually is (method, path, etc.).

Because of that, I don’t see much value in running with --meta-only mode as it stands. In my opinion, when running in this “lightweight” mode, user expectations would be something closer to an access log: no bodies streamed, but still enough context to view the core request/response details.

I guess it might be worth digging deeper into this aspect of the devex, since it could imply some changes in the operator.

Indeed metadata here is metadata about the request outside of any TCP payload: it's the extra stuff we know due to the middleware/traffic-manager system. That's clearly outside the kinds of things you mention, but also necessary and critically gives a request id and time and host.

While I agree folks are likely to want more in metadata, I disagree that --meta-only is not useful. It shows when things happen to what hosts, live.

For adding non-metadata in the sense of stuff in TCP payloads, I guess it should be possible to restrict to request headers, HTTP protocol info, and possibly the same for response headers and include info without needing to stream everything. However, I am unsure of what you are implying w.r.t. MVP and our timeline: as this observation is quite late in that regard I'm unsure of what to do in terms of that and this comment.

return nil
}

func safeClose(c chan struct{}) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question, with this we ensure that pending/enqueue requests are written to the file before closing?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't in general ensure that because then It might never close, the file being a stream, and closing should always succeed.

Because of that, adding a more graceful shutdown would be complicated. In general the files will be written before ending the application. Between the low impact and the complexity of adding a stronger guarantee, this seems perhaps out of scope for MVP to me.

But I guess we could add a time limit for writing requests and responses to files and then wait for that. Just seems to be a lot of work for something that may never be a problem -- it seems ok to me to define the closing of a traffic watch as an interruption because at any rate the user cannot be aware of what was received until it is written, and so having closing distinguish between received and written requests doesn't seem to help much.

@scott-cotton

scott-cotton commented Oct 6, 2025 •

Copy link
Copy Markdown
Member Author

@scott-cotton, something that was making some noise on my mind for a while (and that I finally see it clear now) is the fact that the --meta-only mode doesn’t really tell you much about the request. So, from a user’s perspective, it feels kind of incomplete: I know we’re intercepting a request for a given routing key and host, but I have no visibility into what the request actually is (method, path, etc.).
Because of that, I don’t see much value in running with --meta-only mode as it stands. In my opinion, when running in this “lightweight” mode, user expectations would be something closer to an access log: no bodies streamed, but still enough context to view the core request/response details.
I guess it might be worth digging deeper into this aspect of the devex, since it could imply some changes in the operator.

Indeed metadata here is metadata about the request outside of any TCP payload: it's the extra stuff we know due to the middleware/traffic-manager system. That's clearly outside the kinds of things you mention, but also necessary and critically gives a request id and time and host.

While I agree folks are likely to want more in metadata, I disagree that --meta-only is not useful. It shows when things happen to what hosts, live.

For adding non-metadata in the sense of stuff in TCP payloads, I guess it should be possible to restrict to request headers, HTTP protocol info, and possibly the same for response headers and include info without needing to stream everything. However, I am unsure of what you are implying w.r.t. MVP and our timeline: as this observation is quite late in that regard I'm unsure of what to do in terms of that and this comment.

please see 414e20c

This now depends on https://github.com/signadot/libconnect/pull/132
and https://github.com/signadot/signadot/pull/6259

- output only meta jsons
- log to stderr
- fix a close race that was losing log messages sometimes
@scott-cotton

Copy link
Copy Markdown
Member Author

I have changed the output a bit and fixed a problem that led to some missing log messages in 3f28b91

Base automatically changed from feature-mw to main October 6, 2025 11:30
@daniel-de-vera daniel-de-vera mentioned this pull request Oct 7, 2025
@gitar-bot

gitar-bot Bot commented Oct 8, 2025

Copy link
Copy Markdown

Gitar automatically fixes CI failures and addresses comments starting with Gitar.

⚙️ Options:

  • Fix CI failures*

🔄 To revert changes, post a comment:

Gitar revert to commit <desired commit SHA>

📚 Docs

* Gitar never force pushes to your branch

- --short was not printing newlines
- stderr log does non-json
Comment thread internal/command/traffic/watch.go Resolved

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is another case:

$ signadot traffic watch --sandbox location-watch --short
{"middlewareRequestID":"5fb2035c","watchOptions":"+stream/+stream","when":"2025-10-09T13:24:49.632531329Z","normHost":"location.hotrod-devmesh.svc.cluster.local:8081","routingKey":"9h8zb3gwjq3f4","destWorkload":"Deployment/hotrod-devmesh/location","requestURI":"http://location.hotrod-devmesh.svc:8081/locations","method":"GET","proto":"HTTP/1.1","userAgent":"curl/8.5.0"}
{"middlewareRequestID":"8c9efeab","watchOptions":"+stream/+stream","when":"2025-10-09T13:24:49.929906615Z","normHost":"location.hotrod-devmesh.svc.cluster.local:8081","routingKey":"9h8zb3gwjq3f4","destWorkload":"Deployment/hotrod-devmesh/location","requestURI":"http://location.hotrod-devmesh.svc:8081/locations","method":"GET","proto":"HTTP/1.1","userAgent":"curl/8.5.0"}

I'm surprised to see "watchOptions":"+stream/+stream" when I specify --short. Going back to https://github.com/signadot/libconnect/pull/132#discussion_r2406002003, what's the value of having watchOptions as part of the metadata?.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is the watchOptions of the other side of traffic watch. I guess they could be elided when --short because one would never be surprised to not get some info. OTOH, it's more uniform to just always have the same fields. Personally I prefer keeping it uniform and certainly without behavior that appears to be a bug but isn't, like not getting a request message body when one has asked for it.

I suppose we could do a sort of `report the most restrictive watch options that applied'

seems awfully cosmetic to me and sufficient to have documentation of what the fields are that the user can refer to.

Doing that most restrictive thing would also complicate the documentation...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is the watchOptions of the other side of traffic watch. I guess they could be elided when --short because one would never be surprised to not get some info. OTOH, it's more uniform to just always have the same fields. Personally I prefer keeping it uniform and certainly without behavior that appears to be a bug but isn't, like not getting a request message body when one has asked for it.

I suppose we could do a sort of `report the most restrictive watch options that applied'

seems awfully cosmetic to me and sufficient to have documentation of what the fields are that the user can refer to.

Doing that most restrictive thing would also complicate the documentation...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mm, I see, there are two watch options, once for the producer and one for the consumer, the one displayed there is the producer one. This mental model makes it easier for me to understand it. I see value now on having that field (tough maybe a rename would make it more clear). Docs will help in clarify this too.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it would be better to group requests/responses by normHost on the file system.
Using a sandbox like this one:

$ signadot sandbox apply -f - <<EOF
name: hotrod-watch
spec:
  cluster: test
  virtual:
  - name: location-watch
    workload:
      kind: Deployment
      namespace: hotrod-devmesh
      name: location
  - name: route-watch
    workload:
      kind: Deployment
      namespace: hotrod-devmesh
      name: route
  middleware:
    - name: trafficwatch-client
      match:
        - workload: "*"
EOF

When running a traffic watch, I get:

$ find /tmp/tw1
/tmp/tw1
/tmp/tw1/meta.jsons
/tmp/tw1/2c5a1679
/tmp/tw1/2c5a1679/meta.json
/tmp/tw1/2c5a1679/response
/tmp/tw1/2c5a1679/request
/tmp/tw1/2d4fa9c8
/tmp/tw1/2d4fa9c8/meta.json
/tmp/tw1/2d4fa9c8/response
/tmp/tw1/2d4fa9c8/request
/tmp/tw1/6de09246
/tmp/tw1/6de09246/meta.json
/tmp/tw1/6de09246/response
/tmp/tw1/6de09246/request
/tmp/tw1/30c0d6c5
/tmp/tw1/30c0d6c5/meta.json
/tmp/tw1/30c0d6c5/response
/tmp/tw1/30c0d6c5/request
/tmp/tw1/5fc8412b
/tmp/tw1/5fc8412b/meta.json
/tmp/tw1/5fc8412b/response
/tmp/tw1/5fc8412b/request
/tmp/tw1/4322a8cb
/tmp/tw1/4322a8cb/meta.json
/tmp/tw1/4322a8cb/response
/tmp/tw1/4322a8cb/request
...

Producing something like below may be clearer (and it shouldn't affect any programmatic consumption of the output):

$ find /tmp/tw1
/tmp/tw1
/tmp/tw1/meta.jsons
/tmp/tw1/location.hotrod-devmesh.svc.cluster.local:8081
/tmp/tw1/location.hotrod-devmesh.svc.cluster.local:8081/68b10e07
/tmp/tw1/location.hotrod-devmesh.svc.cluster.local:8081/68b10e07/meta.json
/tmp/tw1/location.hotrod-devmesh.svc.cluster.local:8081/68b10e07/response
/tmp/tw1/location.hotrod-devmesh.svc.cluster.local:8081/68b10e07/request
/tmp/tw1/route.hotrod-devmesh.svc.cluster.local:8083
/tmp/tw1/route.hotrod-devmesh.svc.cluster.local:8083/2c5a1679
/tmp/tw1/route.hotrod-devmesh.svc.cluster.local:8083/2c5a1679/meta.json
/tmp/tw1/route.hotrod-devmesh.svc.cluster.local:8083/2c5a1679/response
/tmp/tw1/route.hotrod-devmesh.svc.cluster.local:8083/2c5a1679/request
...

WDYT?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it looks nicer but has some drawbacks too:

  • less flat: harder to grep and the like
  • norm host may change, either the resolved one due to a change in services or our def of it

I was thinking of an all-in-1 yaml format and the possibility of tooling on top of some structure, like building an html to make things more visually appealing.

Not sure that those future hypotheticals would benefit.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes... I'm not sure.
I agree having some tooling on top of the flat struct would help (and in a way I like the flat struct), but for the average case, maybe it's better to have the 2-level struct.
@foxish, do you have any opinion on this? (I would say I'm 60% in favor of the 2-level struct).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expect most users will consume it interactively, so, as long as there's some option that doesn't write any files, I'm ok with anything. For the output format, I do agree the 2 levels of grouping does make it easier to parse - but I don't feel strongly here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expect most users will consume it interactively, as long as there's some option that doesn't write any files

Well.. I'm not sure I agree with this, otherwise it's just like looking at an access log (which is a good thing to have, but nobody will use signadot just for that). IMO, the main use case is the one that write files, and the one that will be used the most (files could be body-less or the full req/resp).

Comment thread internal/config/trafficwatch.go Resolved
Comment thread internal/config/trafficwatch.go Resolved
Comment thread internal/trafficwatch/get.go Resolved

@daniel-de-vera daniel-de-vera left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@scott-cotton
scott-cotton merged commit b9c650f into main Oct 10, 2025
@scott-cotton
scott-cotton deleted the traffic-watch branch October 10, 2025 00:55
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 this pull request may close these issues.

4 participants