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

windowsservicereceiver wireframe #35362

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

shalper2
Copy link
Contributor

Description: wireframe and early pass at api for a windowsservices receiver as requested in issue 31377

Link to tracking Issue: 31377

Testing: none yet

Documentation: documentation around receiver scope in README.md

@shalper2 shalper2 force-pushed the 31377-windowsservicereceiver-wireframe branch from bcf5660 to 6055531 Compare September 26, 2024 19:15
Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Oct 11, 2024
@pjanotti
Copy link
Contributor

I'll be reviewing this PR.

@github-actions github-actions bot removed the Stale label Oct 24, 2024
@shalper2 shalper2 force-pushed the 31377-windowsservicereceiver-wireframe branch 2 times, most recently from 5b0fb01 to c179923 Compare October 29, 2024 02:42
Copy link
Contributor

@pjanotti pjanotti left a comment

Choose a reason for hiding this comment

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

Some initial feedback for the wireframe

receiver/windowsservicereceiver/go.mod Outdated Show resolved Hide resolved
Comment on lines 12 to 17
scraperhelper.ControllerConfig `mapstructure:",squash"`
Services []string `mapstructure:"services"` // user provided list of services to monitor with receiver
MonitorAll bool `mapstructure:"monitor_all"` // monitor all services on host machine. supercedes services
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Assuming the default values for Services and MonitorAll it is not clear what would be the result: all services or none? It seems none giving that the boolean is false and the list of services is empty. Let me look at the rest of the code before making a suggestion here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at the previous art from telegraf: it seems reasonable to have a include and a exclude list of services. If the include is empty it assumes all services minus the exclude list.

receiver/windowsservicereceiver/windowsservice.go Outdated Show resolved Hide resolved
receiver/windowsservicereceiver/windowsservice.go Outdated Show resolved Hide resolved
@shalper2 shalper2 force-pushed the 31377-windowsservicereceiver-wireframe branch from c179923 to 731526c Compare November 7, 2024 14:23
@shalper2 shalper2 force-pushed the 31377-windowsservicereceiver-wireframe branch 3 times, most recently from 6358dd5 to 0566f19 Compare November 13, 2024 17:33
receiver/windowsservicereceiver/factory.go Outdated Show resolved Hide resolved
receiver/windowsservicereceiver/factory.go Outdated Show resolved Hide resolved
receiver/windowsservicereceiver/scraper.go Show resolved Hide resolved
receiver/windowsservicereceiver/winapi.go Outdated Show resolved Hide resolved
receiver/windowsservicereceiver/winapi.go Outdated Show resolved Hide resolved
}

func (m *Manager) Disconnect() error {
return windows.CloseServiceHandle(m.Handle)
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if the Handle has the default value? Does it return an error?

Copy link
Contributor Author

@shalper2 shalper2 Nov 19, 2024

Choose a reason for hiding this comment

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

It absolutely can return an error. obviously should be handled by the caller

}

func GetService(sname string) (*ServiceStatus, error) {
m, err := SCConnect()
Copy link
Contributor

Choose a reason for hiding this comment

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

We should connect at Start instead of on every call to GetService.


func GetService(sname string) (*ServiceStatus, error) {
m, err := SCConnect()
defer m.Disconnect()
Copy link
Contributor

Choose a reason for hiding this comment

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

Typically you should add this defer only if connect succeeded.

func (s *ServiceStatus) getStatus() error {
st, err := s.service.Query()
if err != nil {
return err
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not a problem with the current code since the handle to the service is opened every time a GetService call is made. However, it is good to pay attention here that the value of s.ServiceStatus in case of error will be the default value for the type (0 in this case).

Copy link
Contributor

Choose a reason for hiding this comment

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

Similar in the call to Config below.

description: Gauge value containing service status as an integer value.
extended_documentation: >
Gauge values map to service status as follows:
1 - Stopped,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
1 - Stopped,
0 - Failed to retrieve service status,
1 - Stopped,

@shalper2 shalper2 force-pushed the 31377-windowsservicereceiver-wireframe branch 3 times, most recently from a9bf88e to 7bc070a Compare December 3, 2024 15:02
@shalper2 shalper2 force-pushed the 31377-windowsservicereceiver-wireframe branch from 7bc070a to 7a65265 Compare December 10, 2024 16:12
@shalper2 shalper2 force-pushed the 31377-windowsservicereceiver-wireframe branch from 7a65265 to 26077db Compare December 16, 2024 17:04
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.

2 participants