Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

chore: Simplify RequestState/PositionalRequestArgs o11y code#63040

Merged
varungandhi-src merged 2 commits into
mainfrom
vg/o11y
Jun 4, 2024
Merged

chore: Simplify RequestState/PositionalRequestArgs o11y code#63040
varungandhi-src merged 2 commits into
mainfrom
vg/o11y

Conversation

@varungandhi-src

@varungandhi-src varungandhi-src commented Jun 3, 2024

Copy link
Copy Markdown
Contributor

Moving the common observability attributes code into helper methods makes
reading the observation related code less painful.

TODO:

  • Add a function to de-duplicate the attributes, because the current implementation
    will end up creating a slice on seeing duplicate keys for the fields common between
    RequestState and PositionalRequestArgs.

@Strum355, do you know why we keep multiple values for the same key instead
of having overwriting semantics? You added this behavior here:
https://github.com/sourcegraph/sourcegraph/pull/29652

Test plan

Covered by existing tests

Changelog

@varungandhi-src varungandhi-src requested a review from Strum355 June 3, 2024 12:59
@cla-bot cla-bot Bot added the cla-signed label Jun 3, 2024
@github-actions github-actions Bot added team/graph Graph Team (previously Code Intel/Language Tools/Language Platform) team/product-platform labels Jun 3, 2024

@kritzcreek kritzcreek 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 in general (thanks for doing this, I assume I "nerdsniped" you with my comment during our call)

Just have one question regarding the ordered-map dependency.

package observation

import (
orderedmap "github.com/wk8/go-ordered-map/v2"

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.

Are we already depending on this somewhere else? I was surprised to see that a library for a datastructure also includes yaml and json parsers https://github.com/wk8/go-ordered-map/blob/85ca4a2b29d3241fa4513f82be3d38fe2392a791/go.mod#L5-L11

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's for implementing deserialization from JSON and YAML, since the stdlib implementation for JSON parsing is slower. https://sourcegraph.com/github.com/wk8/go-ordered-map/-/blob/json.go?L109:9-109:19

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Are we already depending on this somewhere else?

Yes, but not in many places

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.

Well if we're already pulling it in I guess that's fine. I understand what it's used for, it just screams bad library at me. Probably just my intuitions being wrong in the context of Go again.

@varungandhi-src varungandhi-src Jun 4, 2024

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's similar in Rust, many libraries depend on serde via a crate feature. https://github.com/rust-random/rand/blob/master/Cargo.toml#L33

Go doesn't have support for feature flagging in the same way.

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.

Right, if it was feature flagged or in a "ordered-map-serialisation" library I wouldn't have flinched at all.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It can't be in a separate library because you can't add methods to a type in a separate library (somewhat similar to the orphan rule), and the composable way for a type to be (de)serializable is by adding methods with specific signatures.

@varungandhi-src

Copy link
Copy Markdown
Contributor Author

LGTM in general (thanks for doing this, I assume I "nerdsniped" you with my comment during our call)

No, I was working on this locally before our call.

@varungandhi-src varungandhi-src merged commit 3adcd25 into main Jun 4, 2024
@varungandhi-src varungandhi-src deleted the vg/o11y branch June 4, 2024 10:08
@Strum355

Strum355 commented Jun 4, 2024

Copy link
Copy Markdown
Contributor

@Strum355, do you know why we keep multiple values for the same key instead of having overwriting semantics? You added this behavior here: github.com/sourcegraph/sourcegraph/pull/29652

The idea was for use in per-loop-iteration data point collection. Im not particularly happy with the implementation, Im also not sure if its actively being used anywhere. Bit of a hack that I wouldn't be against removing

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla-signed team/graph Graph Team (previously Code Intel/Language Tools/Language Platform) team/product-platform

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants