DatadogTarget: Customize site variable by adrien-f · Pull Request #1433 · triggermesh/triggermesh · GitHub
Skip to content
This repository was archived by the owner on Nov 5, 2024. It is now read-only.

DatadogTarget: Customize site variable#1433

Merged
odacremolbap merged 1 commit into
triggermesh:mainfrom
ManoManoTech:datadog-site
May 23, 2023
Merged

DatadogTarget: Customize site variable#1433
odacremolbap merged 1 commit into
triggermesh:mainfrom
ManoManoTech:datadog-site

Conversation

@adrien-f

Copy link
Copy Markdown
Contributor

Datadog is multi-site and each site gets its own domain so we need to be able to customize it.

See https://docs.datadoghq.com/getting_started/site/

@adrien-f

Copy link
Copy Markdown
Contributor Author

@odacremolbap odacremolbap left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nicely done, thanks so much for bringing this.

I asked for some optimizations, let's see what you think.

Comment thread pkg/apis/targets/v1alpha1/datadog_types.go Outdated
Comment thread pkg/targets/adapter/datadogtarget/config.go Outdated

type datadogAdapter struct {
apiKey string
site string

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: we could do a very slight optimization here.

Creating 2 fields at the adapter called

  • apiURL
  • apiLogsURL

At the NewTarget function we add the base to the site suffix and assign the result to those variables above.

That way we avoid an fmt.Sprintf for each processed event.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's done ✅ I was also tempted to move the newLogsAPIRequest and newAPIRequest into the struct to access it directly, let me know if that's something we'd prefer.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yep, we could optimize something there and keep at the structure the host + path for:

  • metric
  • event
  • log

instead of joining them at every call.

since that is not related to this PR, I am merging this as is.
Feel free to improve the DatadogTarget adapter with the changes that you mention in a new PR if you will 🚀

@odacremolbap

Copy link
Copy Markdown
Member

It's my first time updating a CRD so let me know if I missed anything !

Your CRD update is good.
There might be missing some generated files. The API structures must allow serializing by deep copying, and thus require DeepCopy functions, that we generate through a make target.

make codegen

Can you execute that and include the updated file in this PR?

@adrien-f

adrien-f commented May 22, 2023

Copy link
Copy Markdown
Contributor Author

It's my first time updating a CRD so let me know if I missed anything !

Your CRD update is good. There might be missing some generated files. The API structures must allow serializing by deep copying, and thus require DeepCopy functions, that we generate through a make target.

make codegen

Can you execute that and include the updated file in this PR?

When I run this command, this deletes a lot of files under pkg/client/generated but nothing is modified according to git 🤔

Thanks for the review!

@odacremolbap

Copy link
Copy Markdown
Member

This is what I get after the make codegen command.

make codegen
+ Generating deepcopy funcs for sources/v1alpha1 targets/v1alpha1 flow/v1alpha1 extensions/v1alpha1 routing/v1alpha1
+ Generating clientsets for sources/v1alpha1 targets/v1alpha1 flow/v1alpha1 extensions/v1alpha1 routing/v1alpha1
+ Generating listers for sources/v1alpha1 targets/v1alpha1 flow/v1alpha1 extensions/v1alpha1 routing/v1alpha1
+ Generating informers for sources/v1alpha1 targets/v1alpha1 flow/v1alpha1 extensions/v1alpha1 routing/v1alpha1
+ Generating injection for sources/v1alpha1 targets/v1alpha1 flow/v1alpha1 extensions/v1alpha1 routing/v1alpha1git status
On branch datadog-site
Your branch is up to date with 'manomano/datadog-site'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   pkg/apis/targets/v1alpha1/deepcopy_generated.go

no changes added to commit (use "git add" and/or "git commit -a")

and this is the file's diff

diff --git a/pkg/apis/targets/v1alpha1/deepcopy_generated.go b/pkg/apis/targets/v1alpha1/deepcopy_generated.go
index 31c50f22..b3b197a6 100644
--- a/pkg/apis/targets/v1alpha1/deepcopy_generated.go
+++ b/pkg/apis/targets/v1alpha1/deepcopy_generated.go
@@ -1301,6 +1301,11 @@ func (in *DatadogTargetList) DeepCopyObject() runtime.Object {
 func (in *DatadogTargetSpec) DeepCopyInto(out *DatadogTargetSpec) {
        *out = *in
        in.DatadogAPIKey.DeepCopyInto(&out.DatadogAPIKey)
+       if in.DatadogSite != nil {
+               in, out := &in.DatadogSite, &out.DatadogSite
+               *out = new(string)
+               **out = **in
+       }
        if in.MetricPrefix != nil {
                in, out := &in.MetricPrefix, &out.MetricPrefix
                *out = new(string)

Yes, the command is expected to re-generate the kubernetes code under pkg/client but the first step should be to generate the deep-copy.

Can you post here the output when you exec the make codegen?

See https://docs.datadoghq.com/getting_started/site/

Signed-off-by: Adrien Fillon <adrien.fillon@manomano.com>
@adrien-f

Copy link
Copy Markdown
Contributor Author

Alright for some reason, they were generated in a folder github.com/triggermesh/triggermesh, probably a GOPATH/GOMOD thing.

@odacremolbap odacremolbap left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

All good.

Thanks so much @adrien-f

@odacremolbap odacremolbap merged commit 7f065eb into triggermesh:main May 23, 2023
@adrien-f adrien-f deleted the datadog-site branch May 23, 2023 14:30
@jmcx

jmcx commented Jul 2, 2023

Copy link
Copy Markdown
Contributor

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants