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

Add operator interface for Probe pkg #4849

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

sukkyun2
Copy link
Contributor

@sukkyun2 sukkyun2 commented Aug 27, 2024

Proposed changes

This PR adds operator interface to probe pkg

#4836, I tried to add fuzz test for probe handler.
However, the current architecture made it impossible to mock probe operations, so I added probe operator interface.

This picture is about probe pkg.

image

References

Types of changes

What types of changes does your code introduce to Litmus? Put an x in the boxes that apply

  • New feature (non-breaking change which adds functionality)
  • Bugfix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices applies)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I have read the CONTRIBUTING doc
  • I have signed the commit for DCO to be passed.
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • I have added necessary documentation (if appropriate)

Dependency

  • Please add the links to the dependent PR need to be merged before this (if any).

Special notes for your reviewer:

I need feedback on the approach of passing probeOperator as a parameter to functions.

For example, the function GenerateExperimentManifestWithProbes in chaoscenter/graphql/server/pkg/probe/utils/utils.go directly accesses probe operation. I have added the probeOperator dependency to the handler that uses GenerateExperimentManifestWithProbes and updated the function calls to pass probeOperator as a parameter.

- Add probeOperator to probe pkg
- Add probeOperator to handler that uses probeUtils
- Add probe operator as parameter to functions that use probe operations in probeUtils

Signed-off-by: sukkyun2 <[email protected]>
- Apply goimports

Signed-off-by: sukkyun2 <[email protected]>
@sukkyun2 sukkyun2 force-pushed the refactor/add-operator-interface branch from 579cec1 to 5186dbf Compare August 28, 2024 09:32
@sukkyun2 sukkyun2 marked this pull request as ready for review August 28, 2024 09:45
@namkyu1999
Copy link
Member

can you check a build-pipeline? @sukkyun2

@@ -697,7 +697,7 @@ func ParseProbesFromManifestForRuns(wfType *dbChaosExperiment.ChaosExperimentTyp
}

// GenerateExperimentManifestWithProbes - uses GenerateProbeManifest to get and store the respective probe attribute into Raw Data template for Non Cron Workflow
func GenerateExperimentManifestWithProbes(manifest string, projectID string) (argoTypes.Workflow, error) {
func GenerateExperimentManifestWithProbes(manifest string, projectID string, probeOperator *dbSchemaProbe.Operator) (argoTypes.Workflow, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Rather than passing the operator as a parameter, better to add this to the Probe Service and then use it like so

func (p *probe) GenerateExperimentManifestWithProbes ... {
    p.probeOperator.GetProbeByName
}

Otherwise every instance of this handler would require you to declare and pass on this probeOperator like this
something := GenerateExperimentManifestWithProbes(..previous params, interface.probeOperator)

The better approach would be to use this handler via the service
something := c.probeService.GenerateExperimentManifestWithProbes(..previous params)

Its easier to test in the long run, the test cases would actually be used as checkpoints with this approach. Which also means that the respective initializers would need to change. For example for the above

type experimentRunOps struct {
	...previous values
	probeService  probeService.Service
}

func NewExperimentRunOps(...previous values, probeService probeService.Service) ExperimentRunOps {
	return &experimentRunOps{
		...previous values,
		probeService:  probeService,
	}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I’ve made the changes as suggested. Thank you for the feedback.

@@ -855,7 +855,7 @@ func GenerateExperimentManifestWithProbes(manifest string, projectID string) (ar
}

// GenerateCronExperimentManifestWithProbes - uses GenerateProbeManifest to get and store the respective probe attribute into Raw Data template
func GenerateCronExperimentManifestWithProbes(manifest string, projectID string) (argoTypes.CronWorkflow, error) {
func GenerateCronExperimentManifestWithProbes(manifest string, projectID string, probeOperator *dbSchemaProbe.Operator) (argoTypes.CronWorkflow, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Same review for this, could be added to the Service interface and used like the above

- Updated handler to call GenerateExperimentManifestWithProbes, GenerateCronExperimentManifestWithProbes via ProbeService

Signed-off-by: sukkyun2 <[email protected]>
- add mock probeService generated by mockery

Signed-off-by: sukkyun2 <[email protected]>
Signed-off-by: sukkyun2 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Review
Development

Successfully merging this pull request may close these issues.

4 participants