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

support multiple yaml config files #218

Merged
merged 15 commits into from
Oct 9, 2022
Merged

support multiple yaml config files #218

merged 15 commits into from
Oct 9, 2022

Conversation

samanhappy
Copy link
Collaborator

@samanhappy samanhappy commented Sep 29, 2022

This PR is trying to resolve #201 by merging multiple yaml files.

The merge work is completed by https://github.com/mikefarah/yq using merge operator * and append arrays flag +, more details can refer https://mikefarah.gitbook.io/yq/operators/multiply-merge.

@codecov-commenter
Copy link

codecov-commenter commented Sep 29, 2022

Codecov Report

Base: 99.64% // Head: 99.64% // Increases project coverage by +0.00% 🎉

Coverage data is based on head (61840ee) compared to base (668a312).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #218   +/-   ##
=======================================
  Coverage   99.64%   99.64%           
=======================================
  Files          71       72    +1     
  Lines        5061     5083   +22     
=======================================
+ Hits         5043     5065   +22     
  Misses         12       12           
  Partials        6        6           
Impacted Files Coverage Δ
conf/conf.go 96.72% <100.00%> (+0.04%) ⬆️
conf/merge.go 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@haoel
Copy link
Contributor

haoel commented Sep 29, 2022

I am not sure this merge function would work well.

because the array is nested in the notify section. and for settings, we should merge the settings instead of overwriting the whole settings

I think we can do this better.

how about just using the yq? here is an example use it as a library: https://github.com/kamolhasan/yq-for-strings

@samanhappy
Copy link
Collaborator Author

The settings are merged already, the example maybe a little misleading, so I modified it and will add more tests later.

The merge code is simple now, I will research the yq to see if there is a better solution.

@haoel
Copy link
Contributor

haoel commented Sep 30, 2022

At least, I think we must pass the following mandatory test cases:

1. Section Merge Case

into

http:
  - name: "test 1"
    url: "http://localhost:8080"
    method: "GET"
tcp:
  - name: "test 2"
    host: "localhost:8080"

from

notify:
  slack:
    - name: "slack"
      webhook: "https://hooks.slack.com/services/xxxxxx"

result

http:
  - name: "test 1"
    url: "http://localhost:8080"
    method: "GET"
tcp:
  - name: "test 2"
    host: "localhost:8080"
notify:
  slack:
    - name: "slack"
      webhook: "https://hooks.slack.com/services/xxxxxx"

2. Same Probe Merge Case

into

http:
    - name: "test 1"
        url: "http://localhost:8080"
        method: "GET"

from

http:
    - name: "test 2"
        url: "http://localhost:8181"
        method: "GET"

result

http:
  - name: "test 1"
    url: "http://localhost:8080"
    method: "GET"
  - name: "test 2"
    url: "http://localhost:8181"
    method: "GET"

3. Notify Merge Case

into

notify:
  slack:
    - name: slack
      webhook: "https://hooks.slack.com/services/xxxxxx"

from

notify:
  discord:
    - name: discord
      webhook: "https://discord.com/api/webhooks/xxxxxx"

result

notify:
  slack:
    - name: slack
      webhook: "https://hooks.slack.com/services/xxxxxx"
  discord:
    - name: discord
      webhook: "https://discord.com/api/webhooks/xxxxxx"

4. Notify Array Merge Case

into

notify:
  slack:
    - name: slack1
      webhook: "https://hooks.slack.com/services/xxxxxx"

from

notify:
  slack:
    - name: slack2
      webhook: "https://hooks.slack.com/services/xxxxxx"

result

notify:
  slack:
    - name: slack1
      webhook: "https://hooks.slack.com/services/xxxxxx"
    - name: slack2
      webhook: "https://hooks.slack.com/services/xxxxxx"

5. Settings Merge Case

into

settings:
  name: easeprobe
  sla:
    schedule: "daily"
    time: "00:00"
  notify:
    retry:
      times: 5
      interval: 10

from

settings:
  name: easeprobe_from
  probe:
    timeout: 10s
    interval: 30s
   sla:
    schedule: "weekly"

result

settings:
  name: easeprobe_from
  probe:
    timeout: 10s
    interval: 30s
  notify:
    retry:
      times: 5
      interval: 10
  sla:
    schedule: "weekly"

conf/merge_test.go Outdated Show resolved Hide resolved
conf/merge_test.go Outdated Show resolved Hide resolved
conf/merge_test.go Outdated Show resolved Hide resolved
conf/merge_test.go Outdated Show resolved Hide resolved
conf/merge.go Outdated Show resolved Hide resolved
conf/merge.go Outdated Show resolved Hide resolved
conf/merge.go Outdated Show resolved Hide resolved
conf/merge_test.go Outdated Show resolved Hide resolved
conf/merge.go Outdated Show resolved Hide resolved
conf/merge.go Outdated Show resolved Hide resolved
conf/merge.go Outdated Show resolved Hide resolved
conf/merge.go Outdated Show resolved Hide resolved
conf/merge.go Outdated Show resolved Hide resolved
conf/merge.go Outdated Show resolved Hide resolved
@samanhappy samanhappy marked this pull request as ready for review October 2, 2022 11:35
conf/conf.go Outdated Show resolved Hide resolved
conf/conf_test.go Outdated Show resolved Hide resolved
conf/conf_test.go Outdated Show resolved Hide resolved
conf/merge.go Outdated Show resolved Hide resolved
conf/merge.go Outdated Show resolved Hide resolved
Copy link
Contributor

@haoel haoel left a comment

Choose a reason for hiding this comment

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

LGTM

@haoel haoel merged commit a261de3 into megaease:main Oct 9, 2022
@samanhappy samanhappy deleted the config branch December 5, 2022 06:18
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.

If there are many sites, can I include conf files like nginx?
3 participants