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

making pubsub idempotent and other fixes #91

Merged
merged 3 commits into from
Jan 18, 2023
Merged

Conversation

jhsinger-klotho
Copy link
Contributor

• Does any part of it require special attention?
• Does it relate to or fix any issue? closes https://github.com/klothoplatform/klotho-pro/issues/26

Pubsub was not idempotent or able to find any modules not in the base path of klotho config. We also did not have the names lined up between what our infra launched and what code expected.

Needed to add proxy files at the end so the plugin doesnt reprocess them and see more subscribers/publishers than intended.

Need to make sure we arent overwriting our core resources.

Standard checks

  • Unit tests: Any special considerations?
  • Docs: Do we need to update any docs, internal or public?
  • Backwards compatibility: Will this break existing apps? If so, what would be the extra work required to keep them working? Well it wouldnt have worked now, so no because the naming of infra will be different

Copy link
Contributor

@gordon-klotho gordon-klotho left a comment

Choose a reason for hiding this comment

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

Good find on the problem. Solution looks mostly good, just a few polish comments.

@@ -620,7 +620,7 @@ export class CloudCCLib {
publishers: string[],
subscribers: string[]
): aws.sns.Topic {
let topic = `${this.name}_${path.replace(/[^0-9a-zA-Z_-]/g, '-')}_${varName}_${event}`
let topic = `${this.name}_${varName}_${event}`
Copy link
Contributor

Choose a reason for hiding this comment

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

Why remove the path? Is varName not the emitter's variable name anymore (ie, is it the ID)? Didn't this need to match with something in the runtime as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so the path isnt in the runtime and i believe that varName is actually the ID and not truly the varName. Let me double check because if it is the varname we could have conflicts. I can also rename the variable to pubsubID so it makes more sense

pkg/lang/javascript/plugin_pubsub.go Show resolved Hide resolved
pkg/lang/javascript/plugin_pubsub.go Show resolved Hide resolved
@@ -360,7 +375,14 @@ func (p *Pubsub) generateEmitterDefinitions() (err error) {
}

func findTopics(f *core.SourceFile, spec VarSpec, query string, methodName string) (topics []string) {
varName := findVarName(f, spec)
relPath, _ := filepath.Rel(filepath.Dir(f.Path()), spec.DefinedIn)
Copy link
Contributor

Choose a reason for hiding this comment

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

Error should be checked, even if it's to panic.

VarName: spec.VarName,
}

varName := findVarName(f, newSpec)
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like a shortcoming of findVarName that should be fixed inside, not outside.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will move this logic in there and panic on the relPAth error. Otherwise we need a major refactor of finding every method that uses findVarName

Copy link
Contributor

Choose a reason for hiding this comment

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

Realistically, relPath only errors when one of the paths is absolute, which we should never have. The panic is like an assert that makes sure that's true.

Copy link

Choose a reason for hiding this comment

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

It's been a while, so I forget exactly what all the inputs to findVarMean — but doesn't moving relPath, err := filepath.Rel(filepath.Dir(f.Path()), spec.DefinedIn) into it make it more language-specific? There are languages where relative imports aren't a thing.

Copy link
Contributor

Choose a reason for hiding this comment

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

It is indeed language specific, but the var finder is in the javascript package so I'd expect it to be.

Copy link

Choose a reason for hiding this comment

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

🤦‍♂️ So it is. For some reason I thought it was in a language-agnostic package (and I didn't even think to double check that assumption in the path). Sorry — carry on! :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah i just realized, wouldnt this cause issues for golang?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh wait this is js specific

@github-actions
Copy link

Package Line Rate Health
github.com/klothoplatform/klotho/pkg/analytics 2%
github.com/klothoplatform/klotho/pkg/annotation 23%
github.com/klothoplatform/klotho/pkg/core 20%
github.com/klothoplatform/klotho/pkg/env_var 82%
github.com/klothoplatform/klotho/pkg/exec_unit 45%
github.com/klothoplatform/klotho/pkg/infra/kubernetes 58%
github.com/klothoplatform/klotho/pkg/infra/kubernetes/helm 52%
github.com/klothoplatform/klotho/pkg/input 63%
github.com/klothoplatform/klotho/pkg/lang 37%
github.com/klothoplatform/klotho/pkg/lang/dockerfile 0%
github.com/klothoplatform/klotho/pkg/lang/golang 9%
github.com/klothoplatform/klotho/pkg/lang/javascript 47%
github.com/klothoplatform/klotho/pkg/lang/python 60%
github.com/klothoplatform/klotho/pkg/lang/yaml 0%
github.com/klothoplatform/klotho/pkg/logging 7%
github.com/klothoplatform/klotho/pkg/multierr 95%
github.com/klothoplatform/klotho/pkg/provider/aws 60%
github.com/klothoplatform/klotho/pkg/runtime 75%
github.com/klothoplatform/klotho/pkg/static_unit 32%
github.com/klothoplatform/klotho/pkg/validation 73%
Summary 42% (3593 / 8607)

@jhsinger-klotho jhsinger-klotho merged commit 4f7f9d1 into main Jan 18, 2023
@jhsinger-klotho jhsinger-klotho deleted the pubsub_fixes branch January 18, 2023 16:48
@ghost
Copy link

ghost commented Jan 18, 2023

Are there tests (unit or integration) that we can add to prove the problem is fixed?

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