Skip to content

Conversation

@khanhtc1202
Copy link
Member

What this PR does / why we need it:

Which issue(s) this PR fixes:

Fixes #

Does this PR introduce a user-facing change?:

NONE

@pipecd-bot
Copy link
Collaborator

TODO

The following ISSUES will be created once got merged. If you want me to skip creating the issue, you can use /todo skip command.

Details

1. Implement builder to gather piped stats metrics in redis.

https://github.com/pipe-cd/pipe/blob/78d42ddc18c3135fbd299de069ee990aac18ffc4/pkg/app/ops/pipedstatsbuilder/builder.go#L30-L33

This was created by todo plugin since "TODO:" was found in 78d42dd when #2202 was merged. cc: @khanhtc1202.

Copy link
Collaborator

@pipecd-bot pipecd-bot left a comment

Choose a reason for hiding this comment

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

GO_LINTER

Some issues were detected while linting go source files in your changes.

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 32.03%. This pull request decreases coverage by -0.03%.

File Function Base Head Diff
pkg/cli/cmd.go Telemetry.CustomedMetricsHandlerFor -- 0.00% +0.00%

@pipecd-bot pipecd-bot added size/L and removed size/M labels Jul 8, 2021
@khanhtc1202 khanhtc1202 changed the title WIP Expose piped stat metrics on ops metrics endpoint Expose piped stat metrics on ops metrics endpoint Jul 8, 2021
@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 32.03%. This pull request decreases coverage by -0.03%.

File Function Base Head Diff
pkg/cli/cmd.go Telemetry.CustomedMetricsHandlerFor -- 0.00% +0.00%

@khanhtc1202 khanhtc1202 changed the title Expose piped stat metrics on ops metrics endpoint Expose piped stat metrics at ops metrics endpoint Jul 8, 2021
cmd.Flags().DurationVar(&s.gracePeriod, "grace-period", s.gracePeriod, "How long to wait for graceful shutdown.")
cmd.Flags().StringVar(&s.configFile, "config-file", s.configFile, "The path to the configuration file.")
cmd.Flags().StringVar(&s.gcloudPath, "gcloud-path", s.gcloudPath, "The path to the gcloud command executable.")
cmd.Flags().StringVar(&s.cacheAddress, "cache-address", s.cacheAddress, "The address to cache service.")
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice catch 👍
Address by b967765 🙏

w.Write([]byte("ok"))
})
admin.Handle("/metrics", t.PrometheusMetricsHandler())
admin.Handle("/metrics", t.CustomedMetricsHandlerFor(psb))
Copy link
Member Author

Choose a reason for hiding this comment

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

with this customed metrics handler, we ignore all other metrics exposed to the current ops metrics registry ( which currently is zero ). Will carefully handle those ops's metrics later 🙏

Copy link
Member

Choose a reason for hiding this comment

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

nit: I feel the name should be -> CustomMetricsHandlerFor

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 32.03%. This pull request decreases coverage by -0.03%.

File Function Base Head Diff
pkg/cli/cmd.go Telemetry.CustomedMetricsHandlerFor -- 0.00% +0.00%

}
data = append(data, value)
}
return ioutil.NopCloser(bytes.NewReader(bytes.Join(data, []byte("\n")))), nil
Copy link
Member

Choose a reason for hiding this comment

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

iouti.NopClose is deprecated. Instead using io.NopCloser is preferable.
https://golang.org/pkg/io/ioutil/#NopCloser

Copy link
Member

Choose a reason for hiding this comment

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

Well, why does it need to be an io.ReadCloser? Seems like io.Reader is enough.

Copy link
Member Author

@khanhtc1202 khanhtc1202 Jul 8, 2021

Choose a reason for hiding this comment

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

👀 Just want to carefully close the []byte stream on the hander side. Or is it unnecessary? 🤔
ref: https://github.com/pipe-cd/pipe/pull/2202/files#diff-c9b9fc9a691a60f03cc1d752ce9fac11e932d6a2867c984bd26923131704fdeaR152

Copy link
Member

Choose a reason for hiding this comment

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

First, NopCloser.Close does nothing.

And with the current implementation of PipedStatsBuilder.Build(), all byte sequences are on the heap. So no need to do close operations at all.

Copy link
Member

@nakabonne nakabonne Jul 8, 2021

Choose a reason for hiding this comment

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

If you're planning to directly read from any kinds of stream like Redis in the future, then you will have to add the close operation.

Copy link
Member Author

Choose a reason for hiding this comment

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

I see 👍 Since we will keep the GetAll interface which returns data ( not the reader or else to direct stream data ), it's safe to remove this unnecessary closer as you mentioned 🙏 Lets me address it here 🙆‍♀️

Copy link
Member Author

Choose a reason for hiding this comment

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

Addressed on d448919 🙏

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 32.03%. This pull request decreases coverage by -0.03%.

File Function Base Head Diff
pkg/cli/cmd.go Telemetry.CustomMetricsHandlerFor -- 0.00% +0.00%

}
data = append(data, value)
}
return bytes.NewReader(bytes.Join(data, []byte("\n"))), nil
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 alright to be later, adding a test for Build() makes it more clear.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, just added a simple test 6cad0a6 👀

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 32.03%. This pull request decreases coverage by -0.03%.

File Function Base Head Diff
pkg/cli/cmd.go Telemetry.CustomMetricsHandlerFor -- 0.00% +0.00%

@pipecd-bot pipecd-bot added size/XL and removed size/L labels Jul 8, 2021
@@ -0,0 +1,180 @@
# HELP go_gc_duration_seconds A summary of the pause duration of garbage collection cycles.
Copy link
Member

Choose a reason for hiding this comment

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

metricsdata -> testdata

}
data = append(data, value)
}
return bytes.NewReader(bytes.Join(data, []byte(""))), nil
Copy link
Member

Choose a reason for hiding this comment

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

Use \n as the separator is safer for all cases.

Copy link
Member

Choose a reason for hiding this comment

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

btw, an empty line between metrics is fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

got it 🙆‍♀️

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 32.07%. This pull request increases coverage by 0.01%.

File Function Base Head Diff
pkg/app/ops/pipedstatsbuilder/builder.go NewPipedStatsBuilder -- 100.00% +100.00%
pkg/app/ops/pipedstatsbuilder/builder.go PipedStatsBuilder.Build -- 61.54% +61.54%
pkg/cli/cmd.go Telemetry.CustomMetricsHandlerFor -- 0.00% +0.00%

func (m *mockBuilderBackend) GetAll() (map[string]interface{}, error) {
out := make(map[string]interface{}, len(m.srcs))
for _, file := range m.srcs {
data, err := ioutil.ReadFile(file)
Copy link
Member

Choose a reason for hiding this comment

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

ioutil package is entirely deprecated. Let's use os.ReadFile
https://golang.org/pkg/io/ioutil/#ReadFile

Copy link
Member Author

@khanhtc1202 khanhtc1202 Jul 8, 2021

Choose a reason for hiding this comment

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

Lets no ioutil, lol
028e358

Comment on lines 58 to 59
assert.NoError(t, err)
assert.NotNil(t, rc)
Copy link
Member

Choose a reason for hiding this comment

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

require package would be better because it stops test execution when it fails.

Copy link
Member Author

Choose a reason for hiding this comment

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

To be honest, do we have convention of which check should be wrapped with require and which should be with assert 👀 I saw the require is used somewhere but mixed with assert 👀

Copy link
Member Author

Choose a reason for hiding this comment

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

addressed on ac20e18

Copy link
Member

Choose a reason for hiding this comment

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

In the case of nil and error, it's more likely to panic if proceeds. So we basically use require for NoError and NotNil.

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 32.07%. This pull request increases coverage by 0.01%.

File Function Base Head Diff
pkg/app/ops/pipedstatsbuilder/builder.go NewPipedStatsBuilder -- 100.00% +100.00%
pkg/app/ops/pipedstatsbuilder/builder.go PipedStatsBuilder.Build -- 61.54% +61.54%
pkg/cli/cmd.go Telemetry.CustomMetricsHandlerFor -- 0.00% +0.00%

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 32.07%. This pull request increases coverage by 0.01%.

File Function Base Head Diff
pkg/app/ops/pipedstatsbuilder/builder.go NewPipedStatsBuilder -- 100.00% +100.00%
pkg/app/ops/pipedstatsbuilder/builder.go PipedStatsBuilder.Build -- 61.54% +61.54%
pkg/cli/cmd.go Telemetry.CustomMetricsHandlerFor -- 0.00% +0.00%

@nakabonne
Copy link
Member

Great work.
/lgtm

@pipecd-bot pipecd-bot added the lgtm label Jul 8, 2021
@pipecd-bot
Copy link
Collaborator

APPROVE

This pull request is APPROVED by nghialv.

Approvers can cancel the approval by writing /approve cancel in a comment. Any additional commits also will change this pull request to be not-approved.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants