-
Notifications
You must be signed in to change notification settings - Fork 34
feat: adds support for API Observability #505
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
645522b
WIP: adds support for api observability
srinandan d923aaf
add api observability cmd
srinandan f0cc132
feat: adds support for api observability
srinandan ddb99d8
fix: commands
ssvaidyanathan ce0f75d
bug: multiple fixes #505
srinandan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,163 @@ | ||
| // Copyright 2024 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package observe | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "net/url" | ||
| "path" | ||
| "strconv" | ||
| "strings" | ||
|
|
||
| "internal/apiclient" | ||
| ) | ||
|
|
||
| type Action uint8 | ||
|
|
||
| const ( | ||
| ENABLE Action = iota | ||
| DISABLE | ||
| ) | ||
|
|
||
| func CreateObservationJob(observationJobId string, sources []string) (respBody []byte, err error) { | ||
| var payload string | ||
|
|
||
| u, _ := url.Parse(apiclient.GetAPIObserveURL()) | ||
| u.Path = path.Join(u.Path, "observationJobs") | ||
| q := u.Query() | ||
| q.Set("observationJobId", observationJobId) | ||
| u.RawQuery = q.Encode() | ||
|
|
||
| if len(sources) != 0 { | ||
| payload = "{ \"sources\":[\"" + strings.Join(sources, "\", \"") + "\"]}" | ||
| } | ||
| respBody, err = apiclient.HttpClient(u.String(), payload, "POST") | ||
| return respBody, err | ||
| } | ||
|
|
||
| func GetObservationJob(observationJobId string) (respBody []byte, err error) { | ||
| u, _ := url.Parse(apiclient.GetAPIObserveURL()) | ||
| u.Path = path.Join(u.Path, "observationJobs", observationJobId) | ||
| respBody, err = apiclient.HttpClient(u.String()) | ||
| return respBody, err | ||
| } | ||
|
|
||
| func DeleteObservationJob(observationJobId string) (respBody []byte, err error) { | ||
| u, _ := url.Parse(apiclient.GetAPIObserveURL()) | ||
| u.Path = path.Join(u.Path, "observationJobs", observationJobId) | ||
| respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") | ||
| return respBody, err | ||
| } | ||
|
|
||
| func ListObservationJobs(pageSize int, pageToken string) (respBody []byte, err error) { | ||
| u, _ := url.Parse(apiclient.GetAPIObserveURL()) | ||
| u.Path = path.Join(u.Path, "observationJobs") | ||
| q := u.Query() | ||
| if pageSize != -1 { | ||
| q.Set("pageSize", strconv.Itoa(pageSize)) | ||
| } | ||
| if pageToken != "" { | ||
| q.Set("pageToken", pageToken) | ||
| } | ||
| u.RawQuery = q.Encode() | ||
| respBody, err = apiclient.HttpClient(u.String()) | ||
| return respBody, err | ||
| } | ||
|
|
||
| func EnableObservationJob(observationJob string) (respBody []byte, err error) { | ||
| return controlObservation(observationJob, ENABLE) | ||
| } | ||
|
|
||
| func DisableObservationJob(observationJob string) (respBody []byte, err error) { | ||
| return controlObservation(observationJob, DISABLE) | ||
| } | ||
|
|
||
| func GetApiObservation(name string, observationJob string) (respBody []byte, err error) { | ||
| u, _ := url.Parse(apiclient.GetAPIObserveURL()) | ||
| u.Path = path.Join(u.Path, "observationJobs", observationJob, "apiObservations", name) | ||
| respBody, err = apiclient.HttpClient(u.String()) | ||
| return respBody, err | ||
| } | ||
|
|
||
| func ListApiObservations(observationJob string, pageSize int, pageToken string) (respBody []byte, err error) { | ||
| u, _ := url.Parse(apiclient.GetAPIObserveURL()) | ||
| u.Path = path.Join(u.Path, "observationJobs", observationJob, "apiObservations") | ||
| q := u.Query() | ||
| if pageSize != -1 { | ||
| q.Set("pageSize", strconv.Itoa(pageSize)) | ||
| } | ||
| if pageToken != "" { | ||
| q.Set("pageToken", pageToken) | ||
| } | ||
| u.RawQuery = q.Encode() | ||
| respBody, err = apiclient.HttpClient(u.String()) | ||
| return respBody, err | ||
| } | ||
|
|
||
| func CreateObservationSource(observationSourceId string, pscNetworkConfigs map[string]string) (respBody []byte, err error) { | ||
| u, _ := url.Parse(apiclient.GetAPIObserveURL()) | ||
| u.Path = path.Join(u.Path, "observationSources") | ||
| q := u.Query() | ||
| q.Set("observationSourceId", observationSourceId) | ||
| u.RawQuery = q.Encode() | ||
|
|
||
| networkConfig, err := json.Marshal(pscNetworkConfigs) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| payload := "{ \"gclbObservationSource\":{\"pscNetworkConfigs\":" + string(networkConfig) + "}}" | ||
| respBody, err = apiclient.HttpClient(u.String(), payload, "POST") | ||
| return respBody, err | ||
| } | ||
|
|
||
| func GetObservationSource(observationSourceId string) (respBody []byte, err error) { | ||
| u, _ := url.Parse(apiclient.GetAPIObserveURL()) | ||
| u.Path = path.Join(u.Path, "observationSources", observationSourceId) | ||
| respBody, err = apiclient.HttpClient(u.String()) | ||
| return respBody, err | ||
| } | ||
|
|
||
| func DeleteObservationSource(observationSourceId string) (respBody []byte, err error) { | ||
| u, _ := url.Parse(apiclient.GetAPIObserveURL()) | ||
| u.Path = path.Join(u.Path, "observationSources", observationSourceId) | ||
| respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") | ||
| return respBody, err | ||
| } | ||
|
|
||
| func ListObservationSources(pageSize int, pageToken string) (respBody []byte, err error) { | ||
| u, _ := url.Parse(apiclient.GetAPIObserveURL()) | ||
| u.Path = path.Join(u.Path, "observationSources") | ||
| q := u.Query() | ||
| if pageSize != -1 { | ||
| q.Set("pageSize", strconv.Itoa(pageSize)) | ||
| } | ||
| if pageToken != "" { | ||
| q.Set("pageToken", pageToken) | ||
| } | ||
| u.RawQuery = q.Encode() | ||
| respBody, err = apiclient.HttpClient(u.String()) | ||
| return respBody, err | ||
| } | ||
|
|
||
| func controlObservation(observationJob string, action Action) (respBody []byte, err error) { | ||
| u, _ := url.Parse(apiclient.GetAPIObserveURL()) | ||
| if action == ENABLE { | ||
| u.Path = path.Join(u.Path, "observationJobs", observationJob+":enable") | ||
| } else { | ||
| u.Path = path.Join(u.Path, "observationJobs", observationJob+":disable") | ||
| } | ||
| respBody, err = apiclient.HttpClient(u.String(), "", "POST") | ||
| return respBody, err | ||
| } | ||
This file contains hidden or 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,53 @@ | ||
| // Copyright 2024 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package jobs | ||
|
|
||
| import ( | ||
| "internal/apiclient" | ||
| "internal/client/observe" | ||
|
|
||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| // CrtCmd | ||
| var CrtCmd = &cobra.Command{ | ||
| Use: "create", | ||
| Short: "Create a new Observation Job", | ||
| Long: "Create a new Observation Job", | ||
| Args: func(cmd *cobra.Command, args []string) (err error) { | ||
| apiclient.SetRegion(region) | ||
| return apiclient.SetApigeeOrg(org) | ||
| }, | ||
| RunE: func(cmd *cobra.Command, args []string) (err error) { | ||
| cmd.SilenceUsage = true | ||
| _, err = observe.CreateObservationJob(observationJobId, sources) | ||
| return | ||
| }, | ||
| } | ||
|
|
||
| var ( | ||
| observationJobId string | ||
| sources []string | ||
| ) | ||
|
|
||
| func init() { | ||
| CrtCmd.Flags().StringVarP(&observationJobId, "id", "i", | ||
| "", "Observation Job") | ||
| CrtCmd.Flags().StringArrayVarP(&sources, "sources", "s", | ||
| nil, "The full path to source (repeat for multiple)") | ||
|
|
||
| _ = CrtCmd.MarkFlagRequired("id") | ||
| _ = CrtCmd.MarkFlagRequired("sources") | ||
| } |
This file contains hidden or 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 @@ | ||
| // Copyright 2024 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package jobs | ||
|
|
||
| import ( | ||
| "internal/apiclient" | ||
| "internal/client/observe" | ||
|
|
||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| // DeleteCmd to get a catalog items | ||
| var DeleteCmd = &cobra.Command{ | ||
| Use: "delete", | ||
| Short: "Delete an Observation Job", | ||
| Long: "Delete an Observation Job", | ||
| Args: func(cmd *cobra.Command, args []string) (err error) { | ||
| apiclient.SetRegion(region) | ||
| return apiclient.SetApigeeOrg(org) | ||
| }, | ||
| RunE: func(cmd *cobra.Command, args []string) (err error) { | ||
| cmd.SilenceUsage = true | ||
| _, err = observe.DeleteObservationJob(observationJobId) | ||
| return | ||
| }, | ||
| } | ||
|
|
||
| func init() { | ||
| DeleteCmd.Flags().StringVarP(&observationJobId, "id", "i", | ||
| "", "Observation Job Id") | ||
|
|
||
| _ = DeleteCmd.MarkFlagRequired("id") | ||
| } |
This file contains hidden or 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 @@ | ||
| // Copyright 2024 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package jobs | ||
|
|
||
| import ( | ||
| "internal/apiclient" | ||
| "internal/client/observe" | ||
|
|
||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| // DisableCmd to get a catalog items | ||
| var DisableCmd = &cobra.Command{ | ||
| Use: "disable", | ||
| Short: "Disable an Observation Job", | ||
| Long: "Disable an Observation Job", | ||
| Args: func(cmd *cobra.Command, args []string) (err error) { | ||
| apiclient.SetRegion(region) | ||
| return apiclient.SetApigeeOrg(org) | ||
| }, | ||
| RunE: func(cmd *cobra.Command, args []string) (err error) { | ||
| cmd.SilenceUsage = true | ||
| _, err = observe.DisableObservationJob(observationJobId) | ||
| return | ||
| }, | ||
| } | ||
|
|
||
| func init() { | ||
| DisableCmd.Flags().StringVarP(&observationJobId, "id", "i", | ||
| "", "Observation Job Id") | ||
|
|
||
| _ = DisableCmd.MarkFlagRequired("id") | ||
| } |
This file contains hidden or 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 @@ | ||
| // Copyright 2024 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package jobs | ||
|
|
||
| import ( | ||
| "internal/apiclient" | ||
| "internal/client/observe" | ||
|
|
||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| // EnableCmd to get a catalog items | ||
| var EnableCmd = &cobra.Command{ | ||
| Use: "enable", | ||
| Short: "Enable an Observation Job", | ||
| Long: "Enable an Observation Job", | ||
| Args: func(cmd *cobra.Command, args []string) (err error) { | ||
| apiclient.SetRegion(region) | ||
| return apiclient.SetApigeeOrg(org) | ||
| }, | ||
| RunE: func(cmd *cobra.Command, args []string) (err error) { | ||
| cmd.SilenceUsage = true | ||
| _, err = observe.EnableObservationJob(observationJobId) | ||
| return | ||
| }, | ||
| } | ||
|
|
||
| func init() { | ||
| EnableCmd.Flags().StringVarP(&observationJobId, "id", "i", | ||
| "", "Observation Job Id") | ||
|
|
||
| _ = EnableCmd.MarkFlagRequired("id") | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.