-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TASK-1010] probabilistic and error samplers (#1349)
This PR adds two new Odigos actions that allow the user to sample their data.
- Loading branch information
1 parent
6f466e9
commit 2ce5948
Showing
24 changed files
with
347 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package actions | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
"github.com/odigos-io/odigos/api/actions/v1alpha1" | ||
"github.com/odigos-io/odigos/frontend/kube" | ||
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func GetErrorSampler(c *gin.Context, odigosns string, id string) { | ||
action, err := kube.DefaultClient.ActionsClient.ErrorSamplers(odigosns).Get(c, id, metav1.GetOptions{}) | ||
if err != nil { | ||
if apierrors.IsNotFound(err) { | ||
c.JSON(404, gin.H{ | ||
"error": "not found", | ||
}) | ||
return | ||
} else { | ||
c.JSON(500, gin.H{ | ||
"error": err.Error(), | ||
}) | ||
return | ||
} | ||
} | ||
c.JSON(200, action.Spec) | ||
} | ||
|
||
func CreateErrorSampler(c *gin.Context, odigosns string) { | ||
var action v1alpha1.ErrorSampler | ||
if err := c.ShouldBindJSON(&action.Spec); err != nil { | ||
c.JSON(400, gin.H{ | ||
"error": err.Error(), | ||
}) | ||
return | ||
} | ||
action.GenerateName = "es-" | ||
generatedAction, err := kube.DefaultClient.ActionsClient.ErrorSamplers(odigosns).Create(c, &action, metav1.CreateOptions{}) | ||
if err != nil { | ||
c.JSON(500, gin.H{ | ||
"error": err.Error(), | ||
}) | ||
return | ||
} | ||
c.JSON(201, gin.H{ | ||
"id": generatedAction.Name, | ||
}) | ||
} | ||
|
||
func UpdateErrorSampler(c *gin.Context, odigosns string, id string) { | ||
action, err := kube.DefaultClient.ActionsClient.ErrorSamplers(odigosns).Get(c, id, metav1.GetOptions{}) | ||
if err != nil { | ||
if apierrors.IsNotFound(err) { | ||
c.JSON(404, gin.H{ | ||
"error": "not found", | ||
}) | ||
return | ||
} else { | ||
c.JSON(500, gin.H{ | ||
"error": err.Error(), | ||
}) | ||
} | ||
return | ||
} | ||
action.Spec = v1alpha1.ErrorSamplerSpec{} | ||
if err := c.ShouldBindJSON(&action.Spec); err != nil { | ||
c.JSON(400, gin.H{ | ||
"error": err.Error(), | ||
}) | ||
return | ||
} | ||
action.Name = id | ||
|
||
_, err = kube.DefaultClient.ActionsClient.ErrorSamplers(odigosns).Update(c, action, metav1.UpdateOptions{}) | ||
if err != nil { | ||
c.JSON(500, gin.H{ | ||
"error": err.Error(), | ||
}) | ||
return | ||
} | ||
c.JSON(204, nil) | ||
} | ||
|
||
func DeleteErrorSampler(c *gin.Context, odigosns string, id string) { | ||
err := kube.DefaultClient.ActionsClient.ErrorSamplers(odigosns).Delete(c, id, metav1.DeleteOptions{}) | ||
if err != nil { | ||
if apierrors.IsNotFound(err) { | ||
c.JSON(404, gin.H{ | ||
"error": "not found", | ||
}) | ||
return | ||
} else { | ||
c.JSON(500, gin.H{ | ||
"error": err.Error(), | ||
}) | ||
return | ||
} | ||
} | ||
c.JSON(204, nil) | ||
} |
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
2 changes: 1 addition & 1 deletion
2
frontend/webapp/app/(overview)/(actions)/choose-action/page.tsx
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
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
48 changes: 48 additions & 0 deletions
48
frontend/webapp/components/overview/actions/actions.forms/samplers/error-sampler/index.tsx
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,48 @@ | ||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
import { KeyvalInput } from '@/design.system'; | ||
|
||
const FormWrapper = styled.div` | ||
width: 375px; | ||
`; | ||
|
||
interface ErrorSampler { | ||
fallback_sampling_ratio: number; | ||
} | ||
|
||
interface ErrorSamplerFormProps { | ||
data: ErrorSampler; | ||
onChange: (key: string, value: ErrorSampler | null) => void; | ||
} | ||
const ACTION_DATA_KEY = 'actionData'; | ||
export function ErrorSamplerForm({ | ||
data, | ||
onChange, | ||
}: ErrorSamplerFormProps): React.JSX.Element { | ||
function handleOnChange(fallback_sampling_ratio: number): void { | ||
onChange(ACTION_DATA_KEY, { | ||
fallback_sampling_ratio, | ||
}); | ||
} | ||
|
||
return ( | ||
<> | ||
<FormWrapper> | ||
<KeyvalInput | ||
label="Fallback Sampling Ratio" | ||
value={data?.fallback_sampling_ratio?.toString()} | ||
onChange={(value) => handleOnChange(+value)} | ||
type="number" | ||
tooltip="Specifies the ratio of non-error traces you still want to retain" | ||
min={0} | ||
max={100} | ||
error={ | ||
data?.fallback_sampling_ratio > 100 | ||
? 'Value must be less than 100' | ||
: '' | ||
} | ||
/> | ||
</FormWrapper> | ||
</> | ||
); | ||
} |
2 changes: 2 additions & 0 deletions
2
frontend/webapp/components/overview/actions/actions.forms/samplers/index.ts
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,2 @@ | ||
export * from './error-sampler'; | ||
export * from './probabilistic-sampler'; |
50 changes: 50 additions & 0 deletions
50
...webapp/components/overview/actions/actions.forms/samplers/probabilistic-sampler/index.tsx
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,50 @@ | ||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
import { KeyvalInput } from '@/design.system'; | ||
|
||
const FormWrapper = styled.div` | ||
width: 375px; | ||
`; | ||
|
||
interface ProbabilisticSampler { | ||
sampling_percentage: string; | ||
} | ||
|
||
interface ProbabilisticSamplerProps { | ||
data: ProbabilisticSampler; | ||
onChange: (key: string, value: ProbabilisticSampler | null) => void; | ||
} | ||
const ACTION_DATA_KEY = 'actionData'; | ||
export function ProbabilisticSamplerForm({ | ||
data, | ||
onChange, | ||
}: ProbabilisticSamplerProps): React.JSX.Element { | ||
console.log({ data }); | ||
|
||
function handleOnChange(sampling_percentage: string): void { | ||
onChange(ACTION_DATA_KEY, { | ||
sampling_percentage, | ||
}); | ||
} | ||
|
||
return ( | ||
<> | ||
<FormWrapper> | ||
<KeyvalInput | ||
label="Fallback Sampling Ratio" | ||
value={data?.sampling_percentage} | ||
onChange={(value) => handleOnChange(value)} | ||
type="number" | ||
tooltip="Percentage at which items are sampled; = 100 samples all items, 0 rejects all items" | ||
min={0} | ||
max={100} | ||
error={ | ||
+data?.sampling_percentage > 100 | ||
? 'Value must be less than 100' | ||
: '' | ||
} | ||
/> | ||
</FormWrapper> | ||
</> | ||
); | ||
} |
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.