Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Datadog metrics #1156

Merged
merged 42 commits into from
Mar 6, 2023
Merged

Updated Datadog metrics #1156

merged 42 commits into from
Mar 6, 2023

Conversation

bcavlin
Copy link

@bcavlin bcavlin commented Nov 22, 2022

📝 Description

🎯 Relevant issues

💎 Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

📜 Example code

🚦 How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Test A
  • Test B

🏁 Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have commented my code, particularly in hard-to-understand areas

@icebob
Copy link
Member

icebob commented Dec 17, 2022

Could you link some docs from Datadog regarding the changes?

@bcavlin
Copy link
Author

bcavlin commented Dec 17, 2022

I updated comment in the code, e.g. /* More info: https://docs.datadoghq.com/api/latest/metrics/#submit-metrics */, what documents do you refer to?

.gitignore Outdated
@@ -11,3 +11,4 @@ benchmark/results
.prettierrc.js
.prettierrc
logs/
.history/
Copy link
Member

Choose a reason for hiding this comment

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

Why is it necessary?

Copy link
Author

Choose a reason for hiding this comment

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

I have history plugin so it does not hurt to include this

@@ -127,7 +127,7 @@ class MetricRegistry {
register(opts) {
if (!isPlainObject(opts)) throw new Error("Wrong argument. Must be an Object.");

if (!opts.type) throw new Error("The metric 'type' property is mandatory.");
if (opts.type === undefined) throw new Error("The metric 'type' property is mandatory.");
Copy link
Member

Choose a reason for hiding this comment

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

Why did you change it? type == null or type == "" is valid? Please revert it.

Copy link
Author

Choose a reason for hiding this comment

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

This is because !opts.type = 0 is true as metrics changed to numbers.

headers: {
"Content-Type": "application/json"
}
return fetch(`${this.opts.baseUrl}${this.opts.apiVersion}${this.opts.path}`, {
Copy link
Member

Choose a reason for hiding this comment

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

If the modified reporter only support v2, we should lock the apiVersion in the URL.

Copy link
Author

Choose a reason for hiding this comment

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

Not sure, up to you. Will lock it.

@@ -24,9 +24,29 @@ const Types = {
*/
function getByName(name) {
/* istanbul ignore next */
if (!name) return null;
if (name === undefined) return null;
Copy link
Member

Choose a reason for hiding this comment

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

Same problem, why name == null is valid?

Copy link
Author

Choose a reason for hiding this comment

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

Again, probably because of numbers? 0?


let n = Object.keys(Types).find(n => n.toLowerCase() == name.toLowerCase());
let converted = "Base";
switch (name) {
Copy link
Member

Choose a reason for hiding this comment

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

It's a common code, not just Datadog specific, don't change it, because it will affect all reporters.

@@ -176,10 +176,11 @@ describe("Test Datadog Reporter class", () => {

expect(reporter.generateDatadogSeries).toBeCalledTimes(1);
expect(fetch).toBeCalledTimes(1);
expect(fetch).toBeCalledWith("https://api.datadoghq.com/api/v1/series?api_key=12345", {
expect(fetch).toBeCalledWith("https://api.datadoghq.com/api/v1/series", {
Copy link
Member

Choose a reason for hiding this comment

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

It should be v2, right?

@@ -212,14 +213,14 @@ describe("Test Datadog Reporter class", () => {
});
reporter.init(registry);

registry.register({ name: "os.datetime.utc", type: "gauge" }).set(123456);
registry.register({ name: "test.info", type: "info" }).set("Test Value");
registry.register({ name: "os.datetime.utc", type: 3 }).set(123456);
Copy link
Member

Choose a reason for hiding this comment

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

The registry is common, don't change the type. You should make the Datadog specific conversion inside the Datadog reporter and not in the common classes.

Copy link
Author

Choose a reason for hiding this comment

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

But this is the test for datadog reporter, why is this common? They use numbers now, not names.

Copy link
Member

@icebob icebob left a comment

Choose a reason for hiding this comment

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

And please revert package-lock.json

@icebob icebob merged commit 21410be into moleculerjs:master Mar 6, 2023
@icebob
Copy link
Member

icebob commented Mar 6, 2023

Something is wrong with this PR, it shows as merged but it's not, and it shows a lot of non-relevant changes as well.

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.

9 participants