GithubHelp home page GithubHelp logo

Comments (7)

mxinden avatar mxinden commented on May 23, 2024

I tried using () as the label set for a family, like Family<(), Histogram, ...>.

What is your reasoning for not using a plain Histogram?

from client_rust.

Victor-N-Suadicani avatar Victor-N-Suadicani commented on May 23, 2024

I've built a small wrapping library around client_rust for internal use at my job, to streamline and standardize our usage. Basically I'm not using a plain Histogram as this is using some generic code which allows you to use any label type you want. I figured that in the case you didn't want any labels, you could just use () - but that turned out not to work 😅

from client_rust.

mxinden avatar mxinden commented on May 23, 2024

One solution could be to only add a , here in case the previous label has a length larger than 0.

if let Some(labels) = &self.labels {
if opened_curly_brackets {
self.writer.write_all(b",")?;
} else {
opened_curly_brackets = true;
self.writer.write_all(b"{")?;
}
labels.encode(self.writer)?;
}

from client_rust.

Victor-N-Suadicani avatar Victor-N-Suadicani commented on May 23, 2024

Tangentially related, but I noticed that &str also implements encode - does that assume that you must have the &str be equal to "label_name=\"label_value\"? I'm assuming that if you just set it equal to "foobar" then prometheus will complain that the label has no value (must labels have values?).

But yea that might be one solution I suppose. Alternatively, maybe it should be the responsibility of the Encode implementation to insert the comma?

from client_rust.

mxinden avatar mxinden commented on May 23, 2024

Tangentially related, but I noticed that &str also implements encode - does that assume that you must have the &str be equal to "label_name=\"label_value\"? I'm assuming that if you just set it equal to "foobar" then prometheus will complain that the label has no value (must labels have values?).

That assumption is correct.

But yea that might be one solution I suppose. Alternatively, maybe it should be the responsibility of the Encode implementation to insert the comma?

That would as well be a viable solution.

from client_rust.

Victor-N-Suadicani avatar Victor-N-Suadicani commented on May 23, 2024

I honestly find it a bit surprising that &str implements Encode in that case. I guess it's the same with f32 and the other primitives that implement Encode. encode should at least return Err when it doesn't match the expected format, I would say.

I feel like (&str, &str) should implement Encode but not &str. Currently the tuple impl requires the items to also implement Encode - maybe it should just implement Encode for (K, V) where K: Display, V: Display?

from client_rust.

mxinden avatar mxinden commented on May 23, 2024

I agree. Today I am using Encode to encode the following:

  • Label pair
  • Label key
  • Label value
  • Metric value

Each of these use-cases should probably use their own EncodeXXX trait instead of a single shared one.

from client_rust.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.