-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add basic dns client to kapinger (#859)
# Description Simple nslookup on burst ## Related Issue ## Checklist - [ ] I have read the [contributing documentation](https://retina.sh/docs/contributing). - [ ] I signed and signed-off the commits (`git commit -S -s ...`). See [this documentation](https://docs.github.com/en/authentication/managing-commit-signature-verification/about-commit-signature-verification) on signing commits. - [ ] I have correctly attributed the author(s) of the code. - [ ] I have tested the changes locally. - [ ] I have followed the project's style guidelines. - [ ] I have updated the documentation, if necessary. - [ ] I have added tests, if applicable. ## Screenshots (if applicable) or Testing Completed Please add any relevant screenshots or GIFs to showcase the changes made. ## Additional Notes Add any additional notes or context about the pull request here. --- Please refer to the [CONTRIBUTING.md](../CONTRIBUTING.md) file for more information on how to contribute to this project.
- Loading branch information
Showing
13 changed files
with
204 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Dockerfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,30 @@ | ||
FROM mcr.microsoft.com/oss/go/microsoft/golang:1.22 AS builder | ||
FROM --platform=linux/amd64 mcr.microsoft.com/oss/go/microsoft/golang:1.22 AS builder | ||
|
||
WORKDIR /build | ||
ADD . . | ||
RUN go mod download | ||
|
||
# Build for Linux | ||
RUN CGO_ENABLED=0 GOOS=linux go build -o kapinger . | ||
|
||
FROM scratch | ||
WORKDIR /build | ||
# Build for Windows | ||
RUN CGO_ENABLED=0 GOOS=windows go build -o kapinger.exe . | ||
|
||
# Build for ARM64 Linux | ||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o kapinger-arm64 . | ||
|
||
FROM --platform=linux/amd64 scratch AS linux-amd64 | ||
WORKDIR /app | ||
COPY --from=builder /build/kapinger . | ||
CMD ["./kapinger"] | ||
|
||
FROM --platform=windows/amd64 mcr.microsoft.com/windows/servercore:ltsc2022 AS windows-amd64 | ||
WORKDIR /app | ||
COPY --from=builder /build/kapinger.exe . | ||
ENTRYPOINT [ "cmd.exe" ] | ||
CMD [ "/c", "kapinger.exe" ] | ||
|
||
FROM --platform=linux/arm64 scratch AS linux-arm64 | ||
WORKDIR /app | ||
COPY --from=builder /build/kapinger-arm64 . | ||
CMD ["./kapinger-arm64"] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package clients | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
type Client interface { | ||
MakeRequests(ctx context.Context) error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package clients | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"net" | ||
"time" | ||
) | ||
|
||
type KapingerDNSClient struct { | ||
volume int | ||
interval time.Duration | ||
} | ||
|
||
func NewKapingerDNSClient(volume int, interval time.Duration) *KapingerDNSClient { | ||
return &KapingerDNSClient{ | ||
interval: time.Duration(interval), | ||
volume: volume, | ||
} | ||
} | ||
|
||
func (k *KapingerDNSClient) MakeRequests(ctx context.Context) error { | ||
ticker := time.NewTicker(k.interval) | ||
for { | ||
select { | ||
case <-ctx.Done(): | ||
log.Printf("DNS client context done") | ||
return nil | ||
case <-ticker.C: | ||
go func() { | ||
for i := 0; i < k.volume; i++ { | ||
domain := "retina.sh" | ||
|
||
ips, err := net.LookupIP(domain) | ||
if err != nil { | ||
fmt.Printf("dns client: could not get IPs: %v\n", err) | ||
return | ||
} | ||
log.Printf("dns client: resolved %s to %s\n", domain, ips) | ||
} | ||
}() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.