-
Notifications
You must be signed in to change notification settings - Fork 238
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cbc8723
commit 9939ade
Showing
11 changed files
with
2,833 additions
and
3 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
65 changes: 65 additions & 0 deletions
65
internal/component/compute/process/examples/go/restrict/main.go
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,65 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/extism/go-pdk" | ||
"slices" | ||
"strings" | ||
) | ||
|
||
//export process | ||
func process() int32 { | ||
in := pdk.Input() | ||
pt, err := parsePassthrough(in) | ||
if err != nil { | ||
pdk.SetError(err) | ||
return 1 | ||
} | ||
allowed := pt.Config["allowed_services"] | ||
allowedServices := strings.Split(allowed, ",") | ||
// If allowed is empty then allow all. | ||
if len(allowedServices) == 0 { | ||
pdk.Output(in) | ||
return 0 | ||
} | ||
// Could practice to pass along things unchanged unless | ||
// you explicitly don't want them to. | ||
outPT := &Passthrough{ | ||
Prommetrics: make([]*PrometheusMetric, 0), | ||
Metrics: pt.Metrics, | ||
Logs: pt.Logs, | ||
Traces: pt.Traces, | ||
} | ||
for _, metric := range pt.Prommetrics { | ||
// Check for the service label | ||
var serviceValue string | ||
for _, lbl := range metric.Labels { | ||
if lbl.Name == "service" { | ||
serviceValue = lbl.Value | ||
break | ||
} | ||
} | ||
|
||
if serviceValue == "" { | ||
continue | ||
} | ||
if slices.Contains(allowedServices, serviceValue) { | ||
outPT.Prommetrics = append(outPT.Prommetrics, metric) | ||
} | ||
} | ||
bb, err := outPT.MarshalVT() | ||
if err != nil { | ||
pdk.SetError(err) | ||
return 1 | ||
} | ||
pdk.Output(bb) | ||
return 0 | ||
} | ||
|
||
func parsePassthrough(bb []byte) (*Passthrough, error) { | ||
pt := &Passthrough{} | ||
err := pt.UnmarshalVT(bb) | ||
return pt, err | ||
} | ||
|
||
// this has to exist to compile with tinygo | ||
func main() {} |
Binary file not shown.
Oops, something went wrong.