mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-08 11:05:59 +08:00
🔥Super feat: OpenIM CTL optimization is supported (#926)
* feat: add more test code Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add more test code Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add more test code Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: init project Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: init project Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add versionchecker deploy Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: fix go work go version and build scripts Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: fix actions no pass Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add test file Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: fix chat bug Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add more test project Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add more test project Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add more test project Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: sava images file Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add test file Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add more test Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add more test Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add more test Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add more test Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add more test Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: set more help and port set Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: update slack link Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: update slack link Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add more test project Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: update openim-web Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: set more help and port set Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: update openim-web Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: update openim-web Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add docker buildx images is openim-web Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add docker buildx images is openim-web Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add more test Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: scripts fix Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: scripts fix Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: scripts fix Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: set config file path Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: set config file path Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: set config file path Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: docker compose Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: kafka environment port Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: kafka environment port Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: kafka environment port Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: kafka environment port Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * docs: fix docs link error issus:#968 Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * docs: add deployment docs Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add more helm chart Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add more helm chart Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: Optimize the functionality of iam Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: add iam super feat Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: add go format Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: add go format Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> --------- Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>
This commit is contained in:
@@ -1,133 +0,0 @@
|
||||
// Copyright © 2023 OpenIM. All rights reserved.
|
||||
//
|
||||
// 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 cmd
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/marmotedu/iam/pkg/cli/genericclioptions"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"k8s.io/kubectl/pkg/cmd/completion"
|
||||
"k8s.io/kubectl/pkg/cmd/options"
|
||||
"k8s.io/kubectl/pkg/cmd/set"
|
||||
"k8s.io/kubectl/pkg/cmd/version"
|
||||
|
||||
"github.com/OpenIMSDK/Open-IM-Server/tools/imctl/internal/util/templates"
|
||||
)
|
||||
|
||||
// NewDefaultIAMCtlCommand creates the `imctl` command with default arguments.
|
||||
func NewDefaultIMCtlCommand() *cobra.Command {
|
||||
return NewIMCtlCommand(os.Stdin, os.Stdout, os.Stderr)
|
||||
}
|
||||
|
||||
// NewIAMCtlCommand returns new initialized instance of 'imctl' root command.
|
||||
func NewIAMCtlCommand(in io.Reader, out, err io.Writer) *cobra.Command {
|
||||
// Parent command to which all subcommands are added.
|
||||
cmds := &cobra.Command{
|
||||
Use: "imctl",
|
||||
Short: "imctl controls the IM platform",
|
||||
Long: templates.LongDesc(`
|
||||
imctl controls the IM platform, is the client side tool for IM platform.
|
||||
|
||||
Find more information at:
|
||||
// TODO: add link to docs, from auto scripts and gendocs
|
||||
https://github.com/OpenIMSDK/Open-IM-Server/tree/main/docs`),
|
||||
Run: runHelp,
|
||||
// Hook before and after Run initialize and write profiles to disk,
|
||||
// respectively.
|
||||
PersistentPreRunE: func(*cobra.Command, []string) error {
|
||||
return initProfiling()
|
||||
},
|
||||
PersistentPostRunE: func(*cobra.Command, []string) error {
|
||||
return flushProfiling()
|
||||
},
|
||||
}
|
||||
|
||||
flags := cmds.PersistentFlags()
|
||||
flags.SetNormalizeFunc(cliflag.WarnWordSepNormalizeFunc) // Warn for "_" flags
|
||||
|
||||
// Normalize all flags that are coming from other packages or pre-configurations
|
||||
// a.k.a. change all "_" to "-". e.g. glog package
|
||||
flags.SetNormalizeFunc(cliflag.WordSepNormalizeFunc)
|
||||
|
||||
addProfilingFlags(flags)
|
||||
|
||||
iamConfigFlags := genericclioptions.NewConfigFlags(true).WithDeprecatedPasswordFlag().WithDeprecatedSecretFlag()
|
||||
iamConfigFlags.AddFlags(flags)
|
||||
matchVersionIAMConfigFlags := cmdutil.NewMatchVersionFlags(iamConfigFlags)
|
||||
matchVersionIAMConfigFlags.AddFlags(cmds.PersistentFlags())
|
||||
|
||||
_ = viper.BindPFlags(cmds.PersistentFlags())
|
||||
cobra.OnInitialize(func() {
|
||||
genericapiserver.LoadConfig(viper.GetString(genericclioptions.FlagIAMConfig), "iamctl")
|
||||
})
|
||||
cmds.PersistentFlags().AddGoFlagSet(flag.CommandLine)
|
||||
|
||||
f := cmdutil.NewFactory(matchVersionIAMConfigFlags)
|
||||
|
||||
// From this point and forward we get warnings on flags that contain "_" separators
|
||||
cmds.SetGlobalNormalizationFunc(cliflag.WarnWordSepNormalizeFunc)
|
||||
|
||||
ioStreams := genericclioptions.IOStreams{In: in, Out: out, ErrOut: err}
|
||||
|
||||
groups := templates.CommandGroups{
|
||||
{
|
||||
Message: "Basic Commands:",
|
||||
Commands: []*cobra.Command{
|
||||
info.NewCmdInfo(f, ioStreams),
|
||||
color.NewCmdColor(f, ioStreams),
|
||||
new.NewCmdNew(f, ioStreams),
|
||||
jwt.NewCmdJWT(f, ioStreams),
|
||||
},
|
||||
},
|
||||
{
|
||||
Message: "Identity and Access Management Commands:",
|
||||
Commands: []*cobra.Command{
|
||||
user.NewCmdUser(f, ioStreams),
|
||||
secret.NewCmdSecret(f, ioStreams),
|
||||
policy.NewCmdPolicy(f, ioStreams),
|
||||
},
|
||||
},
|
||||
{
|
||||
Message: "Troubleshooting and Debugging Commands:",
|
||||
Commands: []*cobra.Command{
|
||||
validate.NewCmdValidate(f, ioStreams),
|
||||
},
|
||||
},
|
||||
{
|
||||
Message: "Settings Commands:",
|
||||
Commands: []*cobra.Command{
|
||||
set.NewCmdSet(f, ioStreams),
|
||||
completion.NewCmdCompletion(ioStreams.Out, ""),
|
||||
},
|
||||
},
|
||||
}
|
||||
groups.Add(cmds)
|
||||
|
||||
filters := []string{"options"}
|
||||
templates.ActsAsRootCommand(cmds, filters, groups...)
|
||||
|
||||
cmds.AddCommand(version.NewCmdVersion(f, ioStreams))
|
||||
cmds.AddCommand(options.NewCmdOptions(ioStreams.Out))
|
||||
|
||||
return cmds
|
||||
}
|
||||
|
||||
func runHelp(cmd *cobra.Command, args []string) {
|
||||
_ = cmd.Help()
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
// Copyright © 2023 OpenIM. All rights reserved.
|
||||
//
|
||||
// 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 cmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime"
|
||||
"runtime/pprof"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
)
|
||||
|
||||
// profiling configuration variables
|
||||
var (
|
||||
profileName string = "none" // Name of the profile to capture.
|
||||
profileOutput string = "profile.pprof" // File to write the profile data.
|
||||
)
|
||||
|
||||
// addProfilingFlags registers profiling related flags to the given FlagSet.
|
||||
func addProfilingFlags(flags *pflag.FlagSet) {
|
||||
flags.StringVar(
|
||||
&profileName,
|
||||
"profile",
|
||||
"none",
|
||||
"Type of profile to capture. Options: none, cpu, heap, goroutine, threadcreate, block, mutex",
|
||||
)
|
||||
flags.StringVar(&profileOutput, "profile-output", "profile.pprof", "File to write the profile data")
|
||||
}
|
||||
|
||||
// initProfiling sets up profiling based on the user's choice.
|
||||
// If 'cpu' is selected, it starts the CPU profile. For block and mutex profiles,
|
||||
// sampling rates are set up.
|
||||
func initProfiling() error {
|
||||
switch profileName {
|
||||
case "none":
|
||||
return nil
|
||||
case "cpu":
|
||||
f, err := os.Create(profileOutput)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return pprof.StartCPUProfile(f)
|
||||
case "block":
|
||||
runtime.SetBlockProfileRate(1) // Sampling every block event
|
||||
return nil
|
||||
case "mutex":
|
||||
runtime.SetMutexProfileFraction(1) // Sampling every mutex event
|
||||
return nil
|
||||
default:
|
||||
if profile := pprof.Lookup(profileName); profile == nil {
|
||||
return fmt.Errorf("unknown profile type: '%s'", profileName)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// flushProfiling writes the profiling data to the specified file.
|
||||
// For heap profiles, it runs the GC before capturing the data.
|
||||
// It stops the CPU profile if it was started.
|
||||
func flushProfiling() error {
|
||||
switch profileName {
|
||||
case "none":
|
||||
return nil
|
||||
case "cpu":
|
||||
pprof.StopCPUProfile()
|
||||
return nil
|
||||
case "heap":
|
||||
runtime.GC() // Run garbage collection before writing heap profile
|
||||
fallthrough
|
||||
default:
|
||||
profile := pprof.Lookup(profileName)
|
||||
if profile == nil {
|
||||
return errors.New("invalid profile type")
|
||||
}
|
||||
f, err := os.Create(profileOutput)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return profile.WriteTo(f, 0)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user